Walk forward testing, explained with a real test
Walk forward testing means: pick a strategy's settings using only past data (say 3 years), test those settings on the next year it has never seen, then move the window forward a year and repeat. Joining the test years gives an honest record. In our 12-year test on SPY, the best moving-average settings made 12.3% a year on the data they were picked from but only 6.0% a year on the following unseen years - against 12.5% for simply holding.
Step by step
- Split the data. Choose an in-sample window (here 3 years) for picking settings and an out-of-sample window (here the next 1 year) for testing.
- Optimise in-sample only. Try your settings grid on the in-sample years and keep the best by one fixed measure, chosen before you look.
- Test on the next window. Run those exact settings on the out-of-sample year. Do not change anything after seeing it.
- Roll forward. Move both windows forward by one test period and repeat until the data runs out.
- Judge the joined test years. Only the joined out-of-sample results count. Compare them with the in-sample results and with buy-and-hold after costs.
Our walk forward on SPY (daily prices, 2011-2025): moving-average crossover, 3-year optimise, 1-year test, 0.05% cost per switch
| Test year | Best settings (fast/slow days) | In-sample, % a year | Next year (unseen), % | Buy and hold, % |
|---|---|---|---|---|
| 2014 | 45/150 | 14.6 | 11.3 | 11.3 |
| 2015 | 20/175 | 17.1 | -9.0 | -0.8 |
| 2016 | 50/125 | 13.3 | -0.3 | 9.6 |
| 2017 | 25/225 | 5.6 | 19.4 | 19.4 |
| 2018 | 25/225 | 8.1 | 5.2 | -6.3 |
| 2019 | 25/225 | 11.2 | 15.1 | 28.8 |
| 2020 | 25/200 | 13.4 | -3.6 | 16.2 |
| 2021 | 30/50 | 11.2 | 18.8 | 27.0 |
| 2022 | 5/175 | 20.1 | -20.9 | -19.5 |
| 2023 | 5/200 | 8.1 | 9.9 | 24.3 |
| 2024 | 50/250 | 13.2 | 23.3 | 23.3 |
| 2025 | 50/250 | 12.1 | 2.6 | 16.4 |
What our test shows
The settings that looked best kept changing (from 45/150 to 5/200 to 50/250), and their in-sample return of about 12.3% a year roughly halved on unseen data. The strategy beat buy-and-hold in only 1 of 12 test years (2018). That gap between in-sample and out-of-sample is the overfitting a normal backtest hides. Prices are Yahoo daily closes without dividends, for both the strategy and buy-and-hold.
The rolling windows, drawn
| Round | Pick settings on | Test on (unseen) |
|---|---|---|
| 1 | 2011-2013 | 2014 |
| 2 | 2012-2014 | 2015 |
| 3 | 2013-2015 | 2016 |
| ... | ... | ... |
| 12 | 2022-2024 | 2025 |
Each test year is used once and never for picking. Limits of our example: one market, one simple strategy family and one window length; a different strategy or market can behave differently, which is why you run the test on your own system.
A 10-minute spreadsheet version
- Put dates and closing prices in two columns.
- Add columns for the strategy's daily result with each setting you want to try.
- For each year, find the setting with the best total over the previous three years (a MAX over a filtered range).
- Copy only that setting's result for the year into a 'walk forward' column.
- Compare the walk forward column with the in-sample bests and with buy-and-hold.
Common mistakes
- Peeking: changing the grid after seeing test years makes them in-sample.
- Too short test windows with too few trades - see how many trades a backtest needs.
- Leaving out costs and slippage.
- Calling it 'passed' because the walk forward made money, without comparing to simply holding.
Questions
- What is the difference between walk forward testing and backtesting?
- A plain backtest picks settings and measures them on the same data. Walk forward picks settings on past data and measures them only on later data they never saw.
- What is a good walk forward efficiency?
- Out-of-sample return divided by in-sample return; our SPY test was about 0.49 (6.0 / 12.3). Many practitioners look for well above 0.5, but there is no official bar.
- How long should the in-sample and out-of-sample windows be?
- Long enough for many trades in each. A common start is 3-4 years in, 1 year out on daily data; check the trade count in each window.
- Is walk forward testing the same as forward testing?
- No. Forward testing usually means paper trading live. Walk forward is done on historical data.
Sources
- Wikipedia: Walk forward optimization (Pardo, 1992)
- AmiBroker guide: Walk-forward testing
- Bailey, Borwein, Lopez de Prado, Zhu: The Probability of Backtest Overfitting
Check your backtest for luck
Upload your trade list to Truth Test and see whether the result could be luck - free.