quantlab.model.walk_forward_training#

Walk-forward training: one walk-forward cross-validation of a model or an ensemble.

train_walk_forward runs a train_cv call for anything satisfying the public protocol WalkForwardTrainable; BaseModel and BaseEnsemble are its two adapters, and their train_cv delegates here. It owns the procedure, so the two cannot drift apart:

  1. check the unit’s hyperparameters, before any directory exists;

  2. lay out the folds over the unit’s bars with quantlab.model.split.walk_forward_folds and its purge length;

  3. create the trial directory {class}_trial_{timestamp}/ under the unit’s model_save_dir and train fold i, in order, into fold_{i}/ (the unit applies the fold’s dates, trains and restores its own dates);

  4. average every train_* / val_* / test_* metric of the folds’ trained runs (cv_mean_metrics), write the means to a {class}_cv_summary tracking run in the trial’s group and record the walk-forward trained run (quantlab.runs.trained_run) with the unit’s provenance.

The module imports no quantlab layer above quantlab.utils except the trained-run module.

Examples#

>>> run = train_walk_forward(model.collect(), train_periods=20)
>>> run.kind, len(run.folds)
('walk_forward', 4)

Classes

WalkForwardTrainable

What train_walk_forward needs from the unit it trains; all public.

Functions

cv_mean_metrics

Average every train_* / val_* / test_* metric over folds.

fold_config

Return config with fold's training window before the purge and its test window.

train_walk_forward

Run a walk-forward cross-validation of unit and return the walk-forward run.