quantlab.model.view.PredictorView#
- class quantlab.model.view.PredictorView(predictor)[source]#
Bases:
ComponentRoot class of the views of
config.predictor.Every protocol member is the wrapped predictor’s, through the view:
labelsthe wrapped predictor’s
train_boundsthe wrapped predictor’s
test_boundsthe wrapped predictor’s
fitted_train_boundsthe wrapped predictor’s
label_delaysthe wrapped predictor’s
label_scalesthe wrapped predictor’s
predict_windowthe wrapped predictor’s, then
_view_predictionscollect,loadcalled on the wrapped predictor; return the view
trainthe wrapped predictor’s checkpoint
check_checkpointthe wrapped predictor’s
configconfig_clsfilled from the view’s attributes of the same namesfrom_configthe config’s fields, components rebuilt, passed to the constructor
A subclass declares
config_cls(a subclass ofPredictorViewConfig), keeps each config field as an attribute of the same name, takes the fields as constructor arguments, and overrides_view_predictionsto change the predictions; a view that predicts differently (a wider request, a record) overridespredict_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
modela 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
pathwith 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_clsfilled 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_dirpassed 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
pathinto 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