Walk-Forward Optimization

Why Walk-Forward?

Optimization tries many parameter sets and keeps the one with the best score in the chosen period. That score is measured on the same data that was used to pick the parameters (in-sample). Part of it is luck: the best parameters also fit the noise of this particular history. This is called overfitting, and the more parameter sets you try, the more optimistic the best score gets.

In real trading you never get that result. You pick parameters with the data you have today and trade them on data that does not exist yet. Walk-forward optimization repeats this situation many times in the past: optimize on a training window, trade the next test window with the parameters found, move both windows forward and repeat. Every trade in the test windows is made with parameters chosen without seeing that data (out-of-sample).

What walk-forward tells you

  • A realistic estimate of what the strategy could earn if you re-optimized it regularly. It tests the whole process: the strategy, the optimization method, the scorer and the window lengths, not one parameter set.
  • How much of the optimization result is overfitting: compare the walk-forward result with a normal optimization on the same period. The bigger the gap, the more the optimization fits noise.
  • Whether the best parameters are stable: if they jump from one end of the range to the other between windows, the optimum is mostly noise.

How Alis Splits the Time

Walk-forward windows: each test window follows its training window; the test windows joined together make the walk-forward result 1 Training (36 months) Test 2 Training Test 3 Training Test 4 Training Test โ€ฆ One backtest of all test windows 2016 2017 2018 2019 2020 2021 2022 2023
  • Test windows follow one another from the start time to the end time. The last one is cut at the end time.
  • Every test window has a training window just before it. The first training window starts before the start time, so market data must reach that far back.
  • For every window, Alis optimizes the strategy on the training window exactly as on the Optimization screen (the same result verifier, parameters selection, scorer and maximum number of permutations) and takes the parameters with the highest score. With the genetic algorithm or random selection, the best parameters of the previous window are also tried as a starting point.
  • Then Alis backtests all test windows together, as one continuous backtest. At the start of each test window the strategy switches to the parameters of that window and keeps its open positions: nothing is sold just because a window ends.

Running a Walk-Forward

Step 1: Open the Walk-Forward Screen

Point at Research โ–พ in the top bar and choose Walk-forward. Market data must be loaded.

Research menu with the Walk-forward option

Step 2: Set It Up

  • Strategy to test.
  • Start time: the first day of the first test window (yyyymmdd). End time: the last day of the last test window.
  • Training window (months): how many months before each test window the strategy is optimized on. Default: 36.
  • Test window (months): how long one set of parameters is traded before the strategy is optimized again. Default: 12.
  • The line under these fields shows how many test windows you get and where the first training window starts. If it is red, change the dates or the window lengths, for example when there is not enough data before the first training window.
  • Commission rate and Initial capital, as for a backtest.
  • Result verifier, Parameters selection and Result scorer: the same as for optimization. Choose the scorer you would use to pick parameters for real trading.
  • Max permutations applies to every training window, so the whole run takes about test windows ร— permutations backtests.
Walk-forward settings: strategy, dates and window lengths, with the number of test windows

Step 3: Start

Click Start. Under the settings you can see which window is being optimized and how many backtests it took (Window 3 / 8 ยท iterations 120), and then the progress of the final backtest. The Windows tab lists every window as soon as its optimization ends.

Stop ends the optimization of the current window. Alis leaves that window out and backtests the windows that were optimized in full. Like other jobs, a walk-forward runs in Alis, not in the browser: you can close the tab and come back to the results later.

Step 4: Read the Results

The Equity tab shows the equity and statistics of the test windows only. This is the out-of-sample result, with the same statistics as a backtest. The Trades and Orders tabs list every trade and order of the test windows.

Walk-forward equity and statistics of the test windows

The Windows tab has one row per window:

  • Training and Test: the dates of the window.
  • Training score: the score of the best parameters in the training window.
  • Test return: the return of the account in the test window, when it was traded with those parameters.
  • Transactions: buys and sells in the test window.
  • Params: click View to see the parameters chosen for the window.
Walk-forward windows with training scores, test returns and parameters

How to Read the Results: an Example

The screenshots above show the BuyATH example strategy, which has one parameter (sessions, from 5 to 250). It was optimized for the Sharpe ratio with full permutation, on 36-month training windows, with 12-month test windows from January 2019 to November 2026.

2019-01-02 โ€“ 2026-11-09 Sharpe ratio Final NAV Parameters
Optimization of the whole period (in-sample)1.521.71 millionsessions = 69
Walk-forward (out-of-sample)1.301.07 millionfrom 15 to 42, a new value every year

The optimization of the whole period looks better, but it knew the future: sessions = 69 is the best value only in hindsight, and no training window ever chose it. The walk-forward result is what the process of optimizing every year and trading the next year would really have given. Here it is lower, but still good, which suggests that the strategy's result is not only the effect of fitting. The parameters were also fairly stable: 33, 42, 35, 38, 34, 15, 41 and 42, with one outlier.

Rules of thumb

  • Compare the walk-forward with an optimization of the same period. If the out-of-sample result is much worse (for example, less than half of the return, or a Sharpe ratio close to zero), the optimization mostly fits noise. Try fewer parameters, a robust result verifier or a different strategy.
  • Look at the test windows one by one. A result made by a single lucky window is weak; many losing test windows after high training scores are a warning.
  • Check the Transactions column. With only a few trades in a window, its return is mostly luck.
  • Check that the parameters are stable from window to window.
  • As an extra check, backtest the strategy with the chosen parameters and use Compare to random.

Choosing the Window Lengths

  • Training window: long enough to hold many trades and different market phases (rises and falls). Too long, and the strategy adapts slowly to changes.
  • Test window: shorter than the training window, usually a third to a fifth of it. It is also how often you plan to re-optimize the strategy in real trading.
  • Number of windows: aim for at least five test windows. With two or three, the result depends too much on single periods.
  • Do not tune the walk-forward itself. If you run it many times with different window lengths, scorers and strategies and keep the best, the walk-forward result becomes in-sample too. Decide the settings first, or keep the most recent part of the data for one final check.

From Walk-Forward to Real Trading

If you trust the walk-forward result, trade the way it was simulated: run a normal optimization on the most recent training window (for example, the last 36 months up to the latest session), with the same scorer and settings, and use its best parameters for the length of one test window (for example, 12 months). Then optimize again.

Click View next to the best result and then Copy to get the parameters as Java code for the strategy's source code. The parameters of every walk-forward window can be copied the same way, from the Windows tab.

× Enlarged documentation screenshot