Skip to content

Commit

Permalink
Merge pull request #149 from nwillemse/tearsheet-statistics
Browse files Browse the repository at this point in the history
Clean up grid lines on Equity, Drawdown and Yearly Return charts
  • Loading branch information
mhallsmoore committed Oct 26, 2016
2 parents e5af59a + eb8ed41 commit 95cbe6d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion qstrader/statistics/tearsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ def format_two_dec(x, pos):
y_axis_formatter = FuncFormatter(format_two_dec)
ax.yaxis.set_major_formatter(FuncFormatter(y_axis_formatter))
ax.xaxis.set_tick_params(reset=True)
ax.yaxis.grid(linestyle=':')
ax.xaxis.set_major_locator(mdates.YearLocator(1))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
ax.xaxis.grid(linestyle=':')

if self.benchmark is not None:
benchmark = stats['cum_returns_b']
Expand Down Expand Up @@ -179,6 +181,11 @@ def format_perc(x, pos):

y_axis_formatter = FuncFormatter(format_perc)
ax.yaxis.set_major_formatter(FuncFormatter(y_axis_formatter))
ax.yaxis.grid(linestyle=':')
ax.xaxis.set_tick_params(reset=True)
ax.xaxis.set_major_locator(mdates.YearLocator(1))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
ax.xaxis.grid(linestyle=':')

underwater = -100 * drawdown
underwater.plot(ax=ax, lw=2, kind='area', color='red', alpha=0.3, **kwargs)
Expand Down Expand Up @@ -237,13 +244,15 @@ def format_perc(x, pos):

y_axis_formatter = FuncFormatter(format_perc)
ax.yaxis.set_major_formatter(FuncFormatter(y_axis_formatter))
ax.yaxis.grid(linestyle=':')

yly_ret = perf.aggregate_returns(returns, 'yearly') * 100.0
yly_ret.plot(ax=ax, kind="bar")
ax.set_title('Yearly Returns (%)', fontweight='bold')
ax.set_ylabel('')
ax.set_xlabel('')
ax.set_xticklabels(ax.get_xticklabels(), rotation=45)
ax.xaxis.grid(False)

return ax

Expand Down Expand Up @@ -357,7 +366,8 @@ def format_perc(x, pos):
avg_loss_pct = '{:.2%}'.format(np.mean(pos[pos["trade_pct"] <= 0]["trade_pct"]))
max_win_pct = '{:.2%}'.format(np.max(pos["trade_pct"]))
max_loss_pct = '{:.2%}'.format(np.min(pos["trade_pct"]))
max_loss_dt = '' # pos[pos["trade_pct"] == np.min(pos["trade_pct"])].entry_date.values[0]
# TODO: Position class needs entry date
max_loss_dt = 'TBD' # pos[pos["trade_pct"] == np.min(pos["trade_pct"])].entry_date.values[0]
avg_dit = '0.0' # = '{:.2f}'.format(np.mean(pos.time_in_pos))

ax.text(0.5, 8.9, 'Trade Winning %', fontsize=8)
Expand Down

0 comments on commit 95cbe6d

Please sign in to comment.