quantlab.model.walk_forward_training.train_walk_forward#
- quantlab.model.walk_forward_training.train_walk_forward(unit, train_periods, expanding=False, test_periods=None)[source]#
Run a walk-forward cross-validation of
unitand return the walk-forward run.See the module docstring for the procedure; the parameters are those of
walk_forward_folds.- Parameters:
- unitWalkForwardTrainable
The collected model or ensemble.
- train_periodsint
Number of bars in the first fold’s training window, and in every fold’s when sliding.
- expandingbool, default False
Train every fold from the first fold’s start.
- test_periodsint, optional
Number of bars in each fold’s test window, and the step between folds. Defaults to
train_periods // 5.
- Returns:
- TrainedRun
The
"walk_forward"run: itsfoldsandcv_mean.
- Raises:
- ValueError
If a hyperparameter is invalid,
walk_forward_foldsrefuses the settings (checked first), or the unit has no bar in its date range; nothing is created on disk then.
Examples
>>> run = train_walk_forward(model.collect(), train_periods=20, test_periods=10) >>> len(run.folds), sorted(run.cv_mean)[:1] (2, ['cv_mean_test_ic'])