MCPcopy Index your code
hub / github.com/kernc/backtesting.py / _plot_pl_section

Function _plot_pl_section

backtesting/_plotting.py:428–453  ·  view source on GitHub ↗

Profit/Loss markers section

()

Source from the content-addressed store, hash-verified

426 return fig
427
428 def _plot_pl_section():
429 """Profit/Loss markers section"""
430 fig = new_indicator_figure(y_axis_label="Profit / Loss", height=80)
431 fig.add_layout(Span(location=0, dimension='width', line_color='#666666',
432 line_dash='dashed', level='underlay', line_width=1))
433 trade_source.add(trades['ReturnPct'], 'returns')
434 size = trades['Size'].abs()
435 size = np.interp(size, (size.min(), size.max()), (8, 20))
436 trade_source.add(size, 'marker_size')
437 if 'count' in trades:
438 trade_source.add(trades['count'], 'count')
439 trade_source.add(trades[['EntryBar', 'ExitBar']].values.tolist(), 'lines')
440 fig.multi_line(xs='lines',
441 ys=transform('returns', CustomJSTransform(v_func='return [...xs].map(i => [0, i]);')),
442 source=trade_source, color='#999', line_width=1)
443 trade_source.add(np.take(['inverted_triangle', 'triangle'], trades['Size'] > 0), 'triangles')
444 r1 = fig.scatter(
445 'index', 'returns', source=trade_source, fill_color=cmap,
446 marker='triangles', line_color='black', size='marker_size')
447 tooltips = [("Size", "@size{0,0}")]
448 if 'count' in trades:
449 tooltips.append(("Count", "@count{0,0}"))
450 set_tooltips(fig, tooltips + [("P/L", "@returns{+0.[000]%}")],
451 vline=False, renderers=[r1])
452 fig.yaxis.formatter = NumeralTickFormatter(format="0.[00]%")
453 return fig
454
455 def _plot_volume_section():
456 """Volume section"""

Callers 1

plotFunction · 0.85

Calls 2

new_indicator_figureFunction · 0.85
set_tooltipsFunction · 0.85

Tested by

no test coverage detected