quantlab.backtest.base.Predictor#

class quantlab.backtest.base.Predictor(*args, **kwargs)[source]#

Bases: Protocol

What the backtester needs from a model: the whole contract between the two.

BacktestConfig.model is any object with these members; BaseModel has 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 whose model lacks 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, after load, as the checkpoint records them.

fitted_train_boundstuple

The (start, end) training window actually fitted, after the purge; known after train or load. The in-sample split starts from it.

label_delaystuple[int, …]

Each label’s delay in bars, in the order of labels; each must equal the engine’s fill_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 start to end, one variable per label on (timestamp, symbol); the predictor requests its own features, warm-up included.

collect(), train()

Train-mode preparation; train returns the checkpoint it wrote.

load(path), check_checkpoint(path)

Load-mode preparation; check_checkpoint validates 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