Walk-forward testing designs a strategy on one window of past data, tests it on the period right after, then rolls both windows forward and repeats. It produces a chain of out-of-sample results that mimics how the strategy would have been used.
How it works
- Choose a training window and a test window, for example 5 years and 1 year.
- Fit the model on the training window.
- Record its results on the following test window, using no information from it.
- Move both windows forward by the test length and repeat until the data runs out.
The combined test results form a single out-of-sample record.
An illustrative example
| Step | Trained on | Tested on |
|---|---|---|
| 1 | Years 1 to 5 | Year 6 |
| 2 | Years 2 to 6 | Year 7 |
| 3 | Years 3 to 7 | Year 8 |
| 4 | Years 4 to 8 | Year 9 |
| 5 | Years 5 to 9 | Year 10 |
This is a rolling window. An anchored (expanding) version keeps year 1 as the start of every training window, so the training set grows. Ten years of data give five separate test years here. The setup is illustrative.
Why it helps
A single split into in-sample and out-of-sample data gives one test. Walk-forward testing gives several, shows whether performance is stable across periods and mimics periodic re-fitting. See out-of-sample testing.
Pitfalls
- Choosing the windows after seeing results. Trying many window lengths and keeping the best brings back overfitting.
- Leakage. Returns that overlap the boundary between training and test windows let the test see the training period. A gap between them reduces this.
- Short test windows. One year of monthly data is only 12 observations, which is a weak test.
- Costs. Re-fitting too often adds turnover. See portfolio turnover.
Frequently asked questions
What is walk-forward testing?
It is a testing method that repeatedly trains a model on a window of past data and tests it on the period immediately after, rolling forward through time.
What is the difference between a rolling and an anchored walk-forward test?
A rolling test keeps the training window the same length and slides it forward. An anchored test keeps the same start date, so the training window keeps growing.
How is walk-forward testing different from a simple out-of-sample test?
A simple test uses one split. Walk-forward testing uses many splits in sequence, which shows whether performance holds up across different periods.
Does walk-forward testing prevent overfitting?
It reduces it, but a researcher who adjusts the setup after seeing the results can still overfit to the walk-forward record.