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, with run.json last.

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 DataRecorder recorded it: entries by component path (the stitched pass of a run_cv run).

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, returns and, with a benchmark, benchmark_value and benchmark_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 holding variable on (timestamp, symbol) covering every bar of the window; written as holdings.zarr beside the weights when the engine supplies them.

foldssequence of FoldArtifacts, optional

A run_cv run’s folds.

Returns:
Path

final.

Raises:
RuntimeError

If final already 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'