Walk-Forward Validation and Preventing Overfitting
Walk forward validation retrains a model on a rolling or expanding window and tests it on the next period, just as it would be used live. Learn setup and choices.
Walk forward validation tests a model the way it would actually be used. You train it on data up to a point, use it to predict the next period, record the results, then move forward: retrain with the newer data and predict the following period. Stitching together all those out of sample predictions gives a realistic picture of how the model would have performed if you had run it through history, retraining on schedule. It is the standard method for validating trading models, and Walk-Forward Analysis covers the same idea for rule based strategy parameters.
How it works#
| Step | Train window | Predict |
|---|---|---|
| 1 | Jan 2016 to Dec 2019 | Jan to Mar 2020 |
| 2 | Apr 2016 to Mar 2020 | Apr to Jun 2020 |
| 3 | Jul 2016 to Jun 2020 | Jul to Sep 2020 |
| ... | Keep rolling | ... |
The predictions from every step form one continuous out of sample record.
Rolling versus expanding windows#
| Rolling window | Expanding window | |
|---|---|---|
| Training data | Fixed length, oldest data dropped | All data up to the cutoff |
| Adapts to change | Faster | Slower |
| Stability | Less stable, less data | More stable, more data |
| Suits | Markets with shifting behaviour | Stable relationships, scarce data |
Testing both, and window lengths, is common, but remember each variation is another trial. See Rolling and Expanding Windows.
Key choices#
| Choice | Considerations |
|---|---|
| Training length | Enough data to learn, short enough to stay relevant |
| Retraining frequency | Daily, monthly or quarterly; more frequent costs more computing |
| Test period length | Should match how long you would use a model before retraining |
| Gap between train and test | Purge overlapping labels. See Model Evaluation and Cross-Validation |
| Hyperparameter tuning | Done inside each training window only, never using test data |
Reading the results#
- Look at performance over time, not just the total. Steady modest results beat one great year.
- Compare with a simple baseline, such as a linear model or a buy and hold benchmark.
- Check turnover and costs from the stitched predictions. See Signal Turnover, Breadth and Neutralization.
- Examine the worst periods and understand them.
- Count trials across configurations. See P-Hacking and Multiple Testing.
Common mistakes#
- Tuning on the test windows and then reporting them as out of sample.
- Using a scaler or feature selection fitted on all data before splitting. See Data Leakage.
- Retraining more often in validation than you could in practice.
- Ignoring data availability delays, such as fundamentals published weeks after quarter end. See Point-in-Time and Survivorship-Free Data.
- Treating walk forward as proof: it reduces but does not remove overfitting risk.
Beyond scheduled retraining#
Some models update continuously as new data arrives, rather than in scheduled retrains. See Online Learning.
Frequently asked questions#
What is walk forward validation?#
A method where a model repeatedly learns from past data and is tested on the following period, rolling forward through history to simulate real use.
How often should I retrain a trading model?#
It depends on how quickly its edge decays; walk forward tests with different retraining frequencies help find a sensible schedule.
What is the difference between walk forward validation and walk forward analysis?#
They share the same idea. Walk forward validation usually refers to machine learning models; walk forward analysis often refers to optimising rule based strategy parameters.
Next, learn about models that update continuously in Online Learning.
3 quick questions on this lesson. Get them all right to finish it.
Turn on JavaScript to take the quiz.
Mentioned in
- Machine Learning in TradingMachine Learning
- Random Forests and Gradient BoostingMachine Learning
- Neural Networks and Deep LearningMachine Learning
- Reinforcement LearningMachine Learning
- Data LeakageResearch and Backtesting
- Quant Trader and Quant ResearcherThe Trading Industry