From c370f42497ad03eb77c56cea31eccc770ffee992 Mon Sep 17 00:00:00 2001 From: Juliette James Date: Thu, 29 Feb 2024 10:04:20 +0000 Subject: [PATCH] Qs625 update qst (#391) * extended plot results to include savefig method * Added doc string to tearsheet.py plot_results * Updated QSTrader to version 0.2.6 --- CHANGELOG.md | 6 ++++++ pyproject.toml | 4 ++-- qstrader/statistics/tearsheet.py | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a38b0d..8fc3f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.2.6 + +* Removed get_portfolio_total_non_cash_equity and get_account_total_non_cash_equity from broker/broker.py abstract base class. These methods are not implemented. +* Added save option to TearsheetStatistics class in statistics/tearsheet.py. The tearsheet output can now be saved to a given filename by passing the optional filename parameter as a string when calling the plot_results function. + + # 0.2.5 * Moved build-backend system to Hatchling from setuptools diff --git a/pyproject.toml b/pyproject.toml index 3469198..a735cba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,9 +4,9 @@ build-backend = "hatchling.build" [project] name = "qstrader" -version = "0.2.5" +version = "0.2.6" dependencies = [ - "click>=8.0", + "click>=8.1", "matplotlib>=3.8", "numpy>=1.26", "pandas>=2.2", diff --git a/qstrader/statistics/tearsheet.py b/qstrader/statistics/tearsheet.py index 9fced87..6e9a66a 100644 --- a/qstrader/statistics/tearsheet.py +++ b/qstrader/statistics/tearsheet.py @@ -264,9 +264,12 @@ def format_perc(x, pos): def plot_results(self, filename=None): """ Plot the Tearsheet + + Parameters + ========== + filename : `str` + Option to save the tearsheet output when a filename is specified. """ - if settings.PRINT_EVENTS: - print('Plotting the tearsheet...') rc = { 'lines.linewidth': 1.0, 'axes.facecolor': '0.995', @@ -313,5 +316,14 @@ def plot_results(self, filename=None): # self._plot_txt_trade(stats, ax=ax_txt_trade) # self._plot_txt_time(stats, ax=ax_txt_time) + # Save the figure + if filename: + if settings.PRINT_EVENTS: + print(f"Saving tearsheet to {filename}") + fig = plt.gcf() + fig.savefig(filename) + # Plot the figure + if settings.PRINT_EVENTS: + print('Plotting the tearsheet...') plt.show()