Skip to content
GetProfitable
Search

Walk-forward analysis

Lesson 20 · about 11 min

A single in-sample/out-of-sample split gives you one out-of-sample test. Walk-forward analysis gives you many, by sliding the split through time: optimise on a window, test on the period just after it, move both forward, repeat. The result is a chain of out-of-sample segments that, joined together, form an equity curve made entirely of trades the parameters had never seen. It is the closest a backtest can get to simulating the experience of re-tuning a strategy periodically and trading it forward.

The procedure

  1. Choose an in-sample window length (say, 3 years) and an out-of-sample step (say, 1 year).
  2. Optimise the parameters on years 1 to 3. Record the chosen set.
  3. Run those parameters, frozen, on year 4. Record the trades.
  4. Slide: optimise on years 2 to 4, run frozen on year 5.
  5. Continue to the end of the data.
  6. Concatenate the out-of-sample segments. That is the walk-forward equity curve.
Window In-sample (optimise) Out-of-sample (frozen) Params chosen OOS avg R
1 2014 to 2016 2017 LB 20, stop 2.5 +0.18
2 2015 to 2017 2018 LB 25, stop 2.5 +0.09
3 2016 to 2018 2019 LB 25, stop 2.0 +0.21
4 2017 to 2019 2020 LB 20, stop 3.0 +0.31
5 2018 to 2020 2021 LB 20, stop 2.5 +0.14
6 2019 to 2021 2022 LB 25, stop 2.5 −0.04
7 2020 to 2022 2023 LB 30, stop 2.5 +0.12

Two things to read from this table. First, the out-of-sample results are positive in six of seven windows, with one flat year. Second, the chosen parameters wander within a narrow band (lookback 20 to 30, stop 2.0 to 3.0). Both are signs of a robust strategy. If the chosen parameters had jumped around (lookback 10, then 60, then 15), the optimiser would be chasing noise from window to window.

Anchored versus rolling

  • Rolling: the in-sample window is a fixed length and slides forward, dropping old data. Adapts to regime change; less data per optimisation.
  • Anchored: the in-sample window always starts at the beginning and grows. More data per optimisation; slower to adapt, and early data may no longer be relevant.

Rolling is the more common choice for retail strategies. Use anchored when data is scarce and the market's character is believed stable.

Walk-forward efficiency

Walk-forward efficiency compares the out-of-sample performance with the in-sample performance it was optimised against:

WFE = (average out-of-sample result) ÷ (average in-sample result)

In-sample avg R (across windows) Out-of-sample avg R WFE
+0.29 +0.14 48%

A WFE around 50% or better is usually taken as acceptable. It means half the in-sample edge survived contact with unseen data, which is about what you should expect once the tuning optimism is removed. A WFE near zero means the in-sample edge was fitted. A WFE well above 100% is not good news; it means the out-of-sample periods happened to be easier, and the in-sample estimate is not a useful guide to anything.

Key idea: Walk-forward analysis turns one out-of-sample test into many and produces an equity curve built only from unseen data. Read three things: whether the OOS segments are consistently positive, whether the chosen parameters are stable, and whether about half the in-sample edge survives.

Choosing window sizes

The in-sample window must contain enough trades to optimise on, using the trades-per-degree-of-freedom rule from the previous lesson. The out-of-sample step should be long enough to contain a meaningful number of trades but short enough that you get several windows.

Strategy frequency Trades per year Reasonable IS window Reasonable OOS step
Swing (weekly bars) 15 6 years 2 years
Swing (daily bars) 60 3 years 1 year
Intraday (15-min) 400 1 year 3 months
Intraday (1-min) 3,000 6 months 1 month

With 13 years of daily data and a 3-year window, you get about 10 out-of-sample years. With 5 years, you get 2, which is too few to say much.

What walk-forward does not fix

Walk-forward tests whether a parameter-tuning process is robust. It does not test whether the strategy structure (the rules themselves) was chosen with hindsight. If you designed the entry rule after looking at all 13 years of charts, no amount of walk-forward on the parameters removes that. It also does not remove the multiple-testing problem from the next lesson: if you ran walk-forward on twenty different strategy ideas and kept the one that passed, you have selected again.

Reading the walk-forward equity curve

Plot the concatenated OOS trades as an equity curve and treat it as the backtest. Compute expectancy, profit factor, drawdown and the sample-size checks on this curve, not on the full-period in-sample one. The in-sample numbers are tuning artefacts; the walk-forward numbers are the estimate.

Try it: Run a walk-forward with at least five windows on a strategy you have already tested with a single split. Tabulate the chosen parameters per window and the OOS average R. Compute WFE. If the parameters wander by more than a factor of two between windows, the strategy is tuning to noise regardless of what the OOS numbers say.

Recap

  • Walk-forward slides the IS/OOS split through time; the OOS segments joined together are the honest equity curve.
  • Read consistency of OOS results, stability of chosen parameters, and walk-forward efficiency.
  • WFE around 50% is normal; near zero means overfit; far above 100% means the OOS periods were unusually easy.
  • Window sizes come from trades per degree of freedom; aim for at least five OOS windows.
  • Walk-forward tests parameter robustness, not rule-design hindsight or strategy-selection bias.

See it drawn

Original diagrams for the ideas on this page. Illustrative, not real market data.

An equity curve and its drawdownAn account balance rising over a year, falling from a peak to a trough, then climbing back to the old peak.ACCOUNT EQUITY$20k$12k$8k024681012TIME (MONTHS)PEAK $16,000TROUGH $12,000DRAWDOWN−25%RECOVERY
Equity curve and drawdown. An account balance plotted month by month. The fall from the $16,000 peak to the $12,000 trough is a 25% drawdown, and the shaded area lasts until the balance climbs back to the old peak.
The spread of outcomes behind an expectancyA histogram of forty trades: a tall block of small losses on the left, a low spread of larger wins on the right, and a line marking the average outcome.NUMBER OF TRADES051024 LOSSES, AVG −$20016 WINS, AVG +$600EXPECTANCY +$120−$400−$200$0+$200+$400+$600+$800PROFIT OR LOSS PER TRADEexpectancy = (40% × $600) − (60% × $200) = +$120 per trade
Expectancy: the average trade. Forty trades sorted by outcome: 24 small losses and 16 larger wins. Weighting each side by how often it happens gives the average result per trade, marked here by the dashed line at +$120.