quantlab.backtest.live#

Predict a backtest run’s strategy one bar past its end: the daily live prediction.

A backtest run directory is a strategy’s recipe: its config.json rebuilds the price dataset, the model and the portfolio rule, and its trained unit is the checkpoint. predict_live_bar brings every store that recipe reads up to the last closed bar t and appends the model’s prediction of t to a LivePredictionStore, from which an executor decides t with the run’s rule.

The bar. t is the last bar of the run’s price dataset, whose vendor store a vendor update (scripts/sharadar/update.py) has just extended.

The inputs. The stores the prediction and the decision read are the ones the components under the run’s backtester’s price_dataset, model and constructor declare (Component.store_uses, gathered by walk_store_uses), leaving out the model’s labels (a prediction reads none):

  • every dataset store they read ("reads", gathered by input_stores) must already hold t: they are the vendor’s stores, which this job does not update. A store a dataset is only built from ("source") is not checked. A store named in may_lag may end earlier (a rate published the next business day, read lagged); its last bar is recorded. A store named in mirrors is a copy of some of the price dataset’s variables (the example’s prices.zarr): it gains the price dataset’s bars after its last, or, when the price dataset has gained a symbol, is rewritten from it over its own range, so its new symbol has its history;

  • every store a component owns, written by date range, with a recorded range ("owns", gathered by ranged_stores: a factor’s store, a factor risk model’s regression and estimate stores) is extended to t with its handle’s extend, in one loop, deepest in the tree first (so a risk model’s exposures before its regression store, and that before its estimate store). Only a store’s owner extends it (ADR 0029); a ranged store only read (a factor view, a factor pinned to some of its variables), with no owner in the run, is an outside input and must already hold t.

A store already reaching t is left alone, so a run interrupted after some stores were extended is finished by the next one. Each store is then checked to hold t.

The prediction. The run’s model (config.model, the membership-masked predictor of an index strategy) loads the run’s checkpoint and predicts predict_window(t, t) inside a DataRecorder keyed by the backtester’s component paths; the row and its record (run, checkpoint, data fingerprint, the stores extended, the lagging stores’ last bars) are appended to the store.

Refusals. LivePredictionRefused is raised, and nothing is appended to the live store, when t is already predicted (or the store ends after it), when a leaf dataset lacks t, when the store belongs to another run or checkpoint, or when the run has no model. The stores are not touched by a refusal raised before the extension; a store still lacking t after it is refused after the extension (the stores keep what was appended).

Exactness. An extended store equals a store built over the whole range at t whenever the value at t depends only on the warmup_bars bars before it, which is the contract of every ranged store’s extend; a row is then the row predict_window(t, t) gives on rebuilt stores, bit for bit. A vendor restatement of a stored bar reaches no extended store.

Classes

LivePrediction

What predict_live_bar appended.

Functions

input_stores

Return the stores a run's prediction and decision read, each with who reads it.

last_bar

Return the last bar of dataset's calendar, or None for an empty store.

mirror_new_bars

Bring a store copying some of source's variables up to end.

predict_live_bar

Extend a run's stores to the price dataset's last bar t and append t's prediction.

ranged_stores

Return a run's ranged stores with a recorded range, the owned and the only read.