Plots¶
Visualization functions for backtest results. Requires matplotlib:
All functions return a matplotlib.figure.Figure. Call fig.savefig("plot.png") to save.
plot_equity¶
Equity curve with optional drawdown shading.
| Parameter | Type | Default | Description |
|---|---|---|---|
results |
BacktestResults |
required | Results with equity curve |
show_drawdown |
bool |
True |
Shade drawdown regions |
figsize |
Tuple[int, int] |
(12, 6) |
Figure size |
plot_drawdown¶
Drawdown as negative percentage filled area.
| Parameter | Type | Default | Description |
|---|---|---|---|
results |
BacktestResults |
required | Results with equity curve |
figsize |
Tuple[int, int] |
(12, 4) |
Figure size |
plot_trades¶
Entry/exit markers, optionally on a price chart.
| Parameter | Type | Default | Description |
|---|---|---|---|
results |
BacktestResults |
required | Results with trades |
prices |
Optional[List[Tuple]] |
None |
(timestamp, price) tuples for price line |
figsize |
Tuple[int, int] |
(14, 6) |
Figure size |
Markers: ^ = long entry, v = short entry, x = exit. Green = profit, red = loss.
plot_monthly_heatmap¶
Monthly PnL as a Year x Month heatmap.
| Parameter | Type | Default | Description |
|---|---|---|---|
results |
BacktestResults |
required | Results with monthly data |
figsize |
Tuple[int, int] |
(10, 5) |
Figure size |
Green cells = profit, red cells = loss. Values annotated inside cells.
plot_exit_breakdown¶
Exit reason breakdown as bar or pie chart.
| Parameter | Type | Default | Description |
|---|---|---|---|
results |
BacktestResults |
required | Results with exit breakdown |
kind |
str |
"bar" |
"bar" or "pie" |
figsize |
Tuple[int, int] |
(8, 5) |
Figure size |
plot_multi_equity¶
Per-symbol equity curves with optional combined portfolio overlay.
| Parameter | Type | Default | Description |
|---|---|---|---|
results |
MultiAssetResults |
required | Multi-asset results |
show_combined |
bool |
True |
Show combined equity line |
figsize |
Tuple[int, int] |
(14, 7) |
Figure size |
plot_sweep_heatmap¶
2D parameter sweep as a heatmap.
fig = plot_sweep_heatmap(
sweep_results,
x_param="take_profit_pct",
y_param="stop_loss_pct",
metric="net_pnl",
figsize=(10, 7),
)
| Parameter | Type | Default | Description |
|---|---|---|---|
results |
SweepResults |
required | Sweep results |
x_param |
str |
required | Parameter for x-axis |
y_param |
str |
required | Parameter for y-axis |
metric |
str |
"net_pnl" |
Metric to display |
figsize |
Tuple[int, int] |
(10, 7) |
Figure size |