quantlab.model.predefined.recorded.RecordedPredictor#

class quantlab.model.predefined.recorded.RecordedPredictor(predictor, run_dir, history=False)[source]#

Bases: PredictorView

A Predictor that serves a recorded backtest run’s predictions.

predict_window(start, end) returns the recorded run’s prediction panel over the days start to end (no warm-up bar: the record holds the bars the rule read). It serves only what the checkpoint last passed to load predicted in that run: for a run_cv record, the fold whose trained unit holds that checkpoint, inside the fold’s traded window; for a run record, the run’s own checkpoint inside the run’s window. With history=True the window may also start earlier: the bars before the checkpoint’s window are the record’s stitched panel, what the checkpoint live at each of those bars predicted there (a run_cv record’s earlier folds), and the record’s first bar is the first one served; the window still may not end after the checkpoint’s window, so no prediction is served before it was made. The recorded label names and scales must be the wrapped predictor’s. Every other protocol member forwards to the wrapped predictor (PredictorView); train is refused.

Parameters:
predictorPredictor

The predictor that made the recorded predictions, e.g. the MembershipMaskedPredictor the recorded run was configured with.

run_dirstr or os.PathLike

The recorded backtest run’s directory.

historybool, default False

Whether a window may start before the loaded checkpoint’s window, served from the record’s earlier bars.

Examples

With whole a run_cv result over every fold and backtester the same backtester with a later start_date:

>>> backtester.config = dataclasses.replace(
...     backtester.config, model=RecordedPredictor(model, whole.run_dir)
... )
>>> replay = backtester.run_cv()  # no fold is predicted again

With history=True the bars before a fold come from the earlier folds:

>>> recorded = RecordedPredictor(model, whole.run_dir, history=True)
>>> fold_2 = recorded.load(checkpoints[2]).predict_window(first_bar, fold_2_end)
>>> bool(fold_2.equals(whole_predictions.sel(timestamp=slice(first_bar, fold_2_end))))
True
config_cls#

The config dataclass the wrapper is serialised and rebuilt with.

alias of RecordedPredictorConfig

load(path)[source]#

Load path into the wrapped predictor and serve what it predicted; returns the wrapper.

predict_window(start, end)[source]#

The recorded predictions over the days start to end.

Raises:
ValueError

If no checkpoint is loaded, the record holds no prediction of it, or the window reaches outside what it predicted there (with history, only past its end).

Examples

>>> recorded.load(fold_checkpoint).predict_window("2024-02-13", "2024-02-19").sizes["timestamp"]
5
train()[source]#

Refused: a recorded predictor predicts nothing new.

Raises:
ValueError

Always.