The intuition: why you need data the strategy has never seen
Imagine a student who is given last year's exam paper, memorises every answer, and then scores full marks on that same paper. Does the score show understanding? No. It shows memory. The real test is a new paper with different questions.
A backtest has the same weakness. If you design rules while looking at a stretch of history, you will almost always find settings that fit that history well. Some of the fit reflects a genuine pattern. Some reflects coincidence, which will not repeat. The backtest alone cannot tell you which is which.
The fix is to separate the data into two roles:
- In-sample (IS): the data you use to explore, build and tune the strategy.
- Out-of-sample (OOS): data you set aside and do not use for any design decision. It acts as the new exam paper.
This lesson covers how to make the split, how the holdout gets contaminated, and how forward testing extends the idea. For the broader problem this guards against, see our lesson on overfitting in trading strategies.
The mechanics of a split
Step 1: Split by time, not at random
In many fields, such as image recognition, data points are independent, so you can shuffle them and assign a random 70% to training. Market data is different. Returns are ordered in time, volatility clusters, and regimes persist. A random split lets the model train on days surrounding each test day, which leaks information about the same market conditions into the test.
For time-series work, use a chronological split: the earlier part is in-sample and the later part is out-of-sample. This also mirrors real use, because you will always trade a strategy on data that comes after the data you built it on.
Step 2: Choose the proportions
There is no universal ratio. Common starting points are somewhere between 60/40 and 80/20 in favour of in-sample. Think about the trade-off:
- Too little in-sample: the strategy is tuned on too few observations and the parameters are noisy.
- Too little out-of-sample: the test has too few trades or too few market conditions to say anything reliable.
The number of trades or independent observations matters more than the calendar length. A test period with only a handful of trades is nearly uninformative, whatever the dates.
Step 3: Freeze the rules, then test once
Before touching the out-of-sample period, write down the complete rule set: entry, exit, position sizing, costs assumed, and the metrics you will judge success by. Then run the test. The result, good or bad, is the answer.
Step 4: Consider a validation set
Many researchers use three parts rather than two:
- Training (in-sample): build and fit.
- Validation: compare candidate versions and choose between them.
- Test (holdout): touched once, at the very end.
The middle layer absorbs the repeated peeking that happens during development, so the final holdout stays clean.
Worked example
Suppose you have 20 years of daily data for a broad equity index, from the start of year 1 to the end of year 20. All figures here are hypothetical.
You decide on a chronological split:
| Segment | Period | Role |
|---|---|---|
| Training | Years 1–12 | Build and tune a trend rule |
| Validation | Years 13–16 | Choose between candidate versions |
| Holdout | Years 17–20 | Final one-time test |
You test a simple rule: hold the index when its price is above its moving average, otherwise hold cash. You try moving average lengths from 50 to 250 days in steps of 10, which is 21 variants.
In the training period, the best variant, say 130 days, shows an illustrative annualised return of 9% with a maximum drawdown of 18%. Buy-and-hold over the same years shows 7% with a 35% drawdown. That looks promising, but you picked the best of 21, so some of the edge is selection.
On the validation years, the 130-day version shows 6% and a 15% drawdown, while buy-and-hold shows 6% and a 22% drawdown. The return advantage has vanished, though the drawdown benefit has partly survived. This is useful information: the return gain looked like noise, and the risk reduction may be the more durable feature.
You freeze the rule and run the holdout once. Suppose it shows 5% against 8% for buy-and-hold, with drawdowns of 12% and 20%. The honest reading: the rule gave up some return for lower drawdowns, which is a different claim from the one the training period suggested. You report that, not the training numbers.
Notice what the split did. Without it, you would have believed in a 2-point annual advantage. With it, you learned the real trade-off.
The peeking problem
The holdout is only valid while it is truly unseen. Consider this common loop:
- Run the test on the holdout. It disappoints.
- Adjust the moving average length or add a filter.
- Run the holdout again. It improves.
- Repeat until it looks good.
After a few cycles, your decisions have been shaped by the holdout results. The holdout has become in-sample data under a different name, and its numbers no longer estimate future performance. Each retry also adds to the multiple-testing problem described in our lesson on data snooping and multiple testing.
Practical habits that help:
- Keep a log of every time the holdout is run, and treat more than one run as a warning sign.
- Have the holdout data stored separately so it is not casually loaded during exploration.
- Decide in advance what result would make you abandon the idea, so that a poor result is not simply an invitation to tweak.
- If you do peek and revise, accept that the old holdout is spent. You need fresh data, whether newly arrived data or a different market, to test again.
Beyond a single split
A single split gives a single verdict, and it depends heavily on which years landed in the holdout. Two refinements are worth knowing:
- Walk-forward testing: repeatedly train on a rolling window, test on the next window, and stitch the test windows together. It gives many out-of-sample segments rather than one. See walk-forward analysis.
- Different markets as holdouts: tune on one market and test on others that were never used in design. If the idea is genuine, it often shows up, perhaps more weakly, elsewhere.
Forward (paper) testing
Even a well-run holdout is historical data that already existed when you began. Forward testing goes further: you run the finalised rules in real time on new data, either with simulated trades (paper trading) or with very small real positions.
Its value is that it cannot be contaminated by hindsight, because the data did not exist when the rules were written. It also reveals practical issues a backtest hides, such as delayed data, order execution differences, and costs that were underestimated. Its limit is speed: a strategy that trades a few times a year needs a long forward period before the results mean much. Treat forward testing as a final gate, not a quick confirmation.
Common mistakes
- Random shuffling of time-series data, which leaks information across the split.
- Tuning on the full dataset first, then "splitting" afterwards. The test data already influenced the design.
- A holdout that is too short, with too few trades to separate skill from luck.
- Judging by a different standard out-of-sample, for example switching metrics until one looks good.
- Treating a good holdout as proof. It raises confidence but does not guarantee future results, since markets change.
- Ignoring costs in the holdout, which can turn a modest edge negative.
- Ignoring the data-quality issues that affect both samples equally, such as survivorship bias. See data quality for backtests.
Try this
Take any simple rule you can describe in one sentence, such as "hold an asset when it is above its 100-day average, otherwise hold cash." Using any freely available price history of at least ten years:
- Split it chronologically, roughly 70% in-sample and 30% out-of-sample, and write down the dates before looking at any results.
- Test three or four different average lengths in-sample only, and pick one.
- Write down, in advance, what out-of-sample result would make you reject the rule.
- Run the out-of-sample test once and record the result.
- Compare the two periods. How large is the gap, and what might explain it?
The goal is not to find a winning rule. It is to feel how much a result can change once the data is unseen.