quantlab.model.predefined.recorded.RecordedPredictor#
- class quantlab.model.predefined.recorded.RecordedPredictor(predictor, run_dir, history=False)[source]#
Bases:
PredictorViewA
Predictorthat serves a recorded backtest run’s predictions.predict_window(start, end)returns the recorded run’s prediction panel over the daysstarttoend(no warm-up bar: the record holds the bars the rule read). It serves only what the checkpoint last passed toloadpredicted in that run: for arun_cvrecord, the fold whose trained unit holds that checkpoint, inside the fold’s traded window; for arunrecord, the run’s own checkpoint inside the run’s window. Withhistory=Truethe 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 (arun_cvrecord’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);trainis refused.- Parameters:
- predictorPredictor
The predictor that made the recorded predictions, e.g. the
MembershipMaskedPredictorthe 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
wholearun_cvresult over every fold andbacktesterthe same backtester with a laterstart_date:>>> backtester.config = dataclasses.replace( ... backtester.config, model=RecordedPredictor(model, whole.run_dir) ... ) >>> replay = backtester.run_cv() # no fold is predicted again
With
history=Truethe 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
pathinto the wrapped predictor and serve what it predicted; returns the wrapper.
- predict_window(start, end)[source]#
The recorded predictions over the days
starttoend.- 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