quantlab.backtest.base.Predictor#
- class quantlab.backtest.base.Predictor(*args, **kwargs)[source]#
Bases:
ProtocolWhat the backtester needs from a model: the whole contract between the two.
BacktestConfig.modelis any object with these members;BaseModelhas them without inheriting this class, and so can an ensemble that composes several models. The backtester reads no model config and calls no other model method, so a predictor built from models with different configs is backtested unchanged. A config whosemodellacks a member is refused at construction.- Attributes:
- labelslist
The label objects, whose
lookahead_bars()extends the effective training window of the in-sample split and whose variable names are the prediction variables.- train_bounds, test_boundstuple
The
(start, end)training and test windows: as configured, or, afterload, as the checkpoint records them.- fitted_train_boundstuple
The
(start, end)training window actually fitted, after the purge; known aftertrainorload. The in-sample split starts from it.- label_delaystuple[int, …]
Each label’s
delayin bars, in the order oflabels; each must equal the engine’sfill_delay_bars.- label_scalesdict[str, str]
Each label name’s prediction scale:
"raw"when the prediction is in the label’s own units,"standardized"when it only ranks the cross-section (a model fitted on a transformed target, a label an ensemble averages). A rule that needs return units checks it.
Methods
predict_window(start, end)
The predictions for every bar from
starttoend, one variable per label on(timestamp, symbol); the predictor requests its own features, warm-up included.collect(), train()
Train-mode preparation;
trainreturns the checkpoint it wrote.load(path), check_checkpoint(path)
Load-mode preparation;
check_checkpointvalidates a checkpoint without loading it and runs first.get_config(), from_config(config, run_dir=None)
A JSON-ready dict naming the class in
"name", and the class method that rebuilds the predictor from it.Examples
>>> from typing import get_protocol_members >>> sorted(get_protocol_members(Predictor))[:4] ['check_checkpoint', 'collect', 'fitted_train_bounds', 'from_config'] >>> from quantlab.model.base import BaseModel >>> all(hasattr(BaseModel, name) for name in get_protocol_members(Predictor)) True