Skip to content

Commit

Permalink
Qs625 update qst (#391)
Browse files Browse the repository at this point in the history
* extended plot results to include savefig method

* Added doc string to tearsheet.py plot_results

* Updated QSTrader to version 0.2.6
  • Loading branch information
juliettejames committed Feb 29, 2024
1 parent be5109c commit c370f42
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 14 additions & 2 deletions qstrader/statistics/tearsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()

0 comments on commit c370f42

Please sign in to comment.