quantlab.runs.backtest_run.write_backtest_run#
- quantlab.runs.backtest_run.write_backtest_run(final, kind, *, backtester, market, annualization, data_fingerprint, benchmark_source, trained_run, weights, equity, settlements, metrics, write_report, predictions=None, factor_attribution=None, holdings=None, folds=())[source]#
Write a backtest run directory at
final, staged, withrun.jsonlast.- Parameters:
- finalPath or str
The run directory to create; it must not exist.
- kind{“run”, “run_cv”, “run_weights”}
Which entry point ran.
- backtesterBaseBacktester
The backtester, whose
get_config()is the recipe; every in-memory dataset in its component tree writes its copy under the run directory.- marketMarket
The backtester class’s price columns.
- annualizationAnnualization
The backtester class’s annualization.
- data_fingerprintMapping
What the run read, as its
DataRecorderrecorded it: entries by component path (the stitched pass of arun_cvrun).- benchmark_sourcestr or None
Where the benchmark was read from, as the report names it; None without a benchmark.
- trained_runPath, str or None
The trained unit the backtest used; None for
run_weights.- weights, equityxarray.Dataset
The simulated target weights and the equity curve (
value,returnsand, with a benchmark,benchmark_valueandbenchmark_returns).- settlementslist
The settlements of the simulation.
- metricsdict
The run’s metrics.
- write_reportcallable
Writes the HTML report at the path it is given.
- predictionsPredictionPanel, optional
The predictions the rule read, for a run with a model.
- factor_attributionxarray.Dataset, optional
The per-bar factor attribution, for a run with a risk model (
quantlab.risk.attribution.factor_attribution).- holdingsxarray.Dataset, optional
The simulated holdings, a
holdingvariable on(timestamp, symbol)covering every bar of the window; written asholdings.zarrbeside the weights when the engine supplies them.- foldssequence of FoldArtifacts, optional
A
run_cvrun’s folds.
- Returns:
- Path
final.
- Raises:
- RuntimeError
If
finalalready exists.
Examples
>>> write_backtest_run(runs / "MyBacktester_1", "run", backtester=backtester, ... market=Market("open", "close"), ... annualization=Annualization(252, 390), data_fingerprint={}, ... benchmark_source=None, ... trained_run=checkpoint_unit, weights=weights, equity=equity, ... settlements=[], metrics=metrics, write_report=report) >>> BacktestRun.open(runs / "MyBacktester_1").kind 'run'