@@ -147,7 +147,7 @@ def plot(*, results: pd.Series,
147
147
df : pd .DataFrame ,
148
148
indicators : List [_Indicator ],
149
149
filename = '' , plot_width = None ,
150
- plot_equity = True , plot_pl = True ,
150
+ plot_equity = True , plot_return = False , plot_pl = True ,
151
151
plot_volume = True , plot_drawdown = False ,
152
152
smooth_equity = False , relative_equity = True ,
153
153
superimpose = True , resample = True ,
@@ -172,6 +172,7 @@ def plot(*, results: pd.Series,
172
172
173
173
plot_volume = plot_volume and not df .Volume .isnull ().all ()
174
174
plot_equity = plot_equity and not trades .empty
175
+ plot_return = plot_return and not trades .empty
175
176
plot_pl = plot_pl and not trades .empty
176
177
is_datetime_index = df .index .is_all_dates
177
178
@@ -274,7 +275,7 @@ def set_tooltips(fig, tooltips=(), vline=True, renderers=()):
274
275
renderers = renderers , formatters = formatters ,
275
276
tooltips = tooltips , mode = 'vline' if vline else 'mouse' ))
276
277
277
- def _plot_equity_section ():
278
+ def _plot_equity_section (is_return = False ):
278
279
"""Equity section"""
279
280
# Max DD Dur. line
280
281
equity = equity_data ['Equity' ].copy ()
@@ -307,10 +308,14 @@ def _plot_equity_section():
307
308
308
309
if relative_equity :
309
310
equity /= equity .iloc [0 ]
311
+ if is_return :
312
+ equity -= equity .iloc [0 ]
310
313
311
- source .add (equity , 'equity' )
314
+ yaxis_label = 'Return' if is_return else 'Equity'
315
+ source_key = 'eq_return' if is_return else 'equity'
316
+ source .add (equity , source_key )
312
317
fig = new_indicator_figure (
313
- y_axis_label = "Equity" ,
318
+ y_axis_label = yaxis_label ,
314
319
** ({} if plot_drawdown else dict (plot_height = 110 )))
315
320
316
321
# High-watermark drawdown dents
@@ -322,16 +327,16 @@ def _plot_equity_section():
322
327
fill_color = '#ffffea' , line_color = '#ffcb66' )
323
328
324
329
# Equity line
325
- r = fig .line ('index' , 'equity' , source = source , line_width = 1.5 , line_alpha = 1 )
330
+ r = fig .line ('index' , source_key , source = source , line_width = 1.5 , line_alpha = 1 )
326
331
if relative_equity :
327
- tooltip_format = '@equity{ +0,0.[000]%}'
332
+ tooltip_format = f'@ { source_key } {{ +0,0.[000]%} }'
328
333
tick_format = '0,0.[00]%'
329
334
legend_format = '{:,.0f}%'
330
335
else :
331
- tooltip_format = '@equity{ $ 0,0}'
336
+ tooltip_format = f'@ { source_key } {{ $ 0,0} }'
332
337
tick_format = '$ 0.0 a'
333
338
legend_format = '${:,.0f}'
334
- set_tooltips (fig , [('Equity' , tooltip_format )], renderers = [r ])
339
+ set_tooltips (fig , [(yaxis_label , tooltip_format )], renderers = [r ])
335
340
fig .yaxis .formatter = NumeralTickFormatter (format = tick_format )
336
341
337
342
# Peaks
@@ -569,6 +574,9 @@ def __eq__(self, other):
569
574
if plot_equity :
570
575
_plot_equity_section ()
571
576
577
+ if plot_return :
578
+ _plot_equity_section (is_return = True )
579
+
572
580
if plot_drawdown :
573
581
figs_above_ohlc .append (_plot_drawdown_section ())
574
582
0 commit comments