quantlab.runs.backtest_run#
Backtest runs: the directory a backtest writes, and how it is read back and rebuilt.
A backtester writes one run directory per run(), run_cv() or
run_weights() through write_backtest_run, a run of the run layer
(quantlab.runs.directory): staged, complete or absent, with run.json
written last. Its kinds are "run", "run_cv", "run_weights" and
"fold", one fold of a run_cv run, written as a child run.
config.jsonholds the rebuild recipe only: the backtester’sget_config(), where every in-memory dataset found anywhere in the component tree is recorded reading its copy underinputs/, named by its component path and written once however many fields hold it.run.jsonholds the header, the window (the first and last bar of the equity curve),market(the backtester class’s price columns),annualization(its trading days per year and session minutes per day), the config fields that hold components (components, so a field is rebuilt by its declaration without importing the backtester class), the data fingerprint (what the run’sDataRecorderrecorded: every dataset or factor store it read, by component path; arun_cvrun’s is its stitched pass, each fold child run what its fold’s prediction read),code(the backtester tree’s code record,quantlab.runs.record),trained_run(the trained unit the backtest used: the one trained in train mode, the checkpoint’s in load mode, the walk-forward unit forrun_cv; none forrun_weights) and the folds.The weights, the equity curve, the holdings (when the engine supplies them), the metrics, the settlements, the report, the prediction panel (a run with a model), the per-bar factor attribution (a run with a risk model) and each fold’s metrics are files of the directory, named by this module only. A fold is the run’s stitched account over its test segment (ADR 0033): its weights, equity, holdings and settlements are read from the run, cut to the fold’s window.
BacktestRun.open (or quantlab.runs.directory.open_run) reads a run:
typed properties, readers that return loaded objects, trained_run(),
folds and the rebuilds rebuild_backtester(**overrides) and
rebuild(field). No path is exposed but the run directory itself.
Opening and reading a run imports no model, factor, label or backtest module; rebuilding imports what the recorded classes need.
Examples#
>>> run = BacktestRun.open(result.run_dir)
>>> run.kind, run.rebalance_periods, run.market.fill_price_column
('run', 5, 'open')
>>> again = run.rebuild_backtester().run() # reproduces the run
Classes
How a backtester annualized its statistics: trading days and session length. |
|
One backtest run directory, as its |
|
What a |
|
The price columns a backtester fills orders at and values holdings with. |
Functions
Write a backtest run directory at |