quantlab.model.view.PredictorView#

class quantlab.model.view.PredictorView(predictor)[source]#

Bases: Component

Root class of the views of config.predictor.

Every protocol member is the wrapped predictor’s, through the view:

labels

the wrapped predictor’s

train_bounds

the wrapped predictor’s

test_bounds

the wrapped predictor’s

fitted_train_bounds

the wrapped predictor’s

label_delays

the wrapped predictor’s

label_scales

the wrapped predictor’s

predict_window

the wrapped predictor’s, then _view_predictions

collect, load

called on the wrapped predictor; return the view

train

the wrapped predictor’s checkpoint

check_checkpoint

the wrapped predictor’s

config

config_cls filled from the view’s attributes of the same names

from_config

the config’s fields, components rebuilt, passed to the constructor

A subclass declares config_cls (a subclass of PredictorViewConfig), keeps each config field as an attribute of the same name, takes the fields as constructor arguments, and overrides _view_predictions to change the predictions; a view that predicts differently (a wider request, a record) overrides predict_window, and one that changes a label’s scale or the checkpoint handling overrides that member.

Parameters:
predictorPredictor

The wrapped predictor.

Attributes:
predictorPredictor

The wrapped predictor.

Examples

With model a loaded predictor:

>>> class Doubled(PredictorView):
...     def _view_predictions(self, predictions):
...         return predictions * 2
>>> view = Doubled(model)
>>> view.train_bounds == model.train_bounds, view.label_scales == model.label_scales
(True, True)
>>> window = ("2024-01-01", "2024-01-12")
>>> bool(view.predict_window(*window).equals(model.predict_window(*window) * 2))
True
>>> view.load("ckpt.joblib") is view
True
check_checkpoint(path)[source]#

Validate path with the wrapped predictor, without loading it.

Examples

>>> view.check_checkpoint("ckpt.joblib")  # raises if it does not fit
collect()[source]#

Collect the wrapped predictor’s training data; returns the view.

Examples

>>> view.collect() is view
True
property config#

config_cls filled from the view’s attributes; get_config() serialises it.

Examples

>>> view.config.predictor is model
True
config_cls#

The config class the view is serialised and rebuilt with.

alias of PredictorViewConfig

property fitted_train_bounds#

The wrapped predictor’s fitted (start, end) training window.

Examples

>>> view.fitted_train_bounds == model.fitted_train_bounds
True
classmethod from_config(config, run_dir=None)[source]#

Rebuild the view and the predictor it wraps from get_config().

The component fields are rebuilt by the component rule, with run_dir passed down, and every field is passed to the constructor by name.

Examples

>>> from quantlab.model.predefined.smoothed import SmoothedPredictor
>>> smoothed = SmoothedPredictor(None, halflife_bars=2.5)
>>> rebuilt = SmoothedPredictor.from_config(smoothed.get_config())
>>> rebuilt.halflife_bars, rebuilt.warmup_bars, rebuilt.predictor
(2.5, 25, None)
property label_delays#

The wrapped predictor’s label delays; a view moves no bar.

Examples

>>> view.label_delays == model.label_delays
True
property label_scales#

The wrapped predictor’s label scales.

Examples

>>> view.label_scales == model.label_scales
True
property labels#

The wrapped predictor’s labels.

Examples

>>> view.labels is model.labels
True
load(path)[source]#

Load path into the wrapped predictor; returns the view.

Examples

>>> view.load("ckpt.joblib") is view
True
predict_window(start, end)[source]#

The wrapped predictor’s predictions over the window, through _view_predictions.

Examples

>>> bool(view.predict_window(*window).equals(model.predict_window(*window) * 2))
True
property test_bounds#

The wrapped predictor’s (start, end) test window.

Examples

>>> view.test_bounds == model.test_bounds
True
train()[source]#

Train the wrapped predictor; returns its checkpoint.

Examples

>>> view.train() == model.train()
True
property train_bounds#

The wrapped predictor’s (start, end) training window.

Examples

>>> view.train_bounds == model.train_bounds
True