quantlab.backtest.base#

Backtester base class and the result types every backtest run produces.

This module sits at the end of the pipeline: a trained return model and a price dataset go in, and a run directory holding target weights, an equity curve, metrics and an HTML report comes out. BaseBacktester owns the three public entry points, run() (backtest one model), run_cv() (replay every fold of a cross-validation run as one continuous curve) and run_weights() (backtest a precomputed target-weight panel, no model), and every step between them that does not depend on the simulation engine, plus report_figure(), the report chart of a result held in memory. Engine layers such as VectorBtBacktester implement the simulation hooks, and concrete classes add a MarketSpec and a signal generator.

A few terms are used throughout. A panel is an xarray.Dataset indexed by timestamp and symbol, and a bar is one timestamp of it. Target weights are the fraction of portfolio value each symbol should hold after a rebalance. The warm-up is the stretch of bars before the backtest window that factors need to fill their rolling windows. In-sample bars are bars the model was trained on (including the bars its labels looked ahead into), and out-of-sample bars are bars it never saw; results are reported for both separately. A fold is one train/test split of a walk-forward cross-validation run (train_cv), and the stitched curve simulates the test segments of all folds back to back. A fingerprint is a hash of the data a run read, stored so that a later rebuild of the run can tell whether the data has changed. The backtester does not decide what is fingerprinted: it opens a quantlab.runs.record.DataRecorder around each run, each run_cv fold and the stitched pass, and every dataset or factor store read inside it is recorded under its component path.

Classes

BacktestResult

Return value of BaseBacktester.run() and BaseBacktester.run_weights().

BaseBacktester

Abstract base of every backtester: the public entry points and shared steps.

CVBacktestResult

Return value of BaseBacktester.run_cv().

MarketSpec

Backtest conventions of one market: price columns and annualization.

Predictor

What the backtester needs from a model: the whole contract between the two.

SimulationResult

Output of one engine simulation in engine-independent form.

Functions

attribution_score_label

Return the label a backtest's attribution ranks its universe by.

benchmark_display_name

Return a benchmark's readable name: its ticker as of as_of when dataset names a lookup.

label_specs

Return the LabelSpec of every prediction variable of predictor.