Skip to main content
The plotting module processes raw backtest data into frozen dataclasses that matplotlib, plotly, or any charting library can consume directly. No external dependencies required.

Bollinger Bands

Rolling mean with standard deviation envelopes

Distributions

Return and PnL histograms with full statistics

Heatmaps

Monthly returns and correlation matrices

Underwater

Per-point drawdown depth for area charts

Trade Scatter

Buy/sell markers with PnL attribution

PlotBundle

One-call extraction of all plot data

Quick Start

One-Call Extraction

from_backtest

Extract all plot data from a BacktestResult in a single call.
Returns a PlotBundle containing all extracted data.

Individual Functions

bollinger_bands

Returns BandData with timestamps, middle, upper, lower, bandwidth.

underwater_curve

Returns UnderwaterData with per-point drawdown_pct and peak tracking.

histogram

Returns HistogramData with bin_edges, bin_centers, counts, frequencies, plus mean, median, std, skew, kurtosis.

return_distribution

Extracts period returns from equity curve, returns HistogramData.

pnl_distribution

FIFO-matches trades into round-trips, returns HistogramData of PnL values.

monthly_returns_heatmap

Returns HeatmapData with years as rows and months (Jan-Dec) as columns.

correlation_heatmap

Returns HeatmapData with Pearson correlation coefficients.

rolling_stats

Returns RollingStatData with sharpe and sortino as CurveData.

normalized_equity

Returns NormalizedEquityData with equity normalized to 1.0 and cumulative PnL.

trade_scatter

Returns TradeScatterData with all points, buys, and sells as TradeScatterPoint tuples.

calibration_plot

Returns CalibrationPlotData with bin_centers, actual_freq, perfect_line, ece, and brier_score. Uses Rust calibration_curve() when available, falls back to pure Python.

Output Types

All types are frozen dataclasses with tuple fields (immutable).