5.2 Optimisation and overfitting
The strategy testers can optimise: try thousands of combinations of settings and find the one that gave the best result. It sounds smart. It is also the most common way to fool yourself.
Overfitting
Overfitting means that the robot is fitted to the noise in historical data – not to a pattern that repeats. The more settings you optimise, and the more combinations you try, the greater the danger.
Marcos López de Prado shows in Advances in Financial Machine Learning that when you test enough variants, some of them will always look good – purely by chance.
How to protect yourself
1. Split the data. Optimise on the first 70% of the period (in-sample), and test on the last 30% that the robot has never “seen” (out-of-sample). If the result there is much worse, the robot is probably overfitted.
2. Walk-forward. Robert Pardo describes in The Evaluation and Optimization of Trading Strategies a method where you repeat this several times forward in time:
3. Few settings. A robot with three settings is far more robust than one with fifteen.
4. Look for plateaus. A good setting sits in the middle of an area where many values give good results. If only an MA of 17 works, while 16 and 18 lose, 17 is probably chance.
5. Test several markets. A robust idea often works – at least reasonably – on several similar markets.
Kevin Davey’s rule of thumb
Kevin Davey, who has placed among the best in the World Cup Championship of Futures Trading, writes in Building Winning Algorithmic Trading Systems that he expects live results to be significantly worse than the test. He also lets new strategies run for a period on paper or demo – incubation – before using real money.
Try it yourself
Optimise one setting on 2018–2022, and test the best value on 2023–2025. Did the result hold?
Key takeaways
- Overfitting is when the robot is fitted to noise in historical data.
- Split the data, use walk-forward and keep the number of settings low.
- Good settings sit on plateaus – not on isolated peaks.
65% of retail investor accounts lose money when trading CFDs with this provider.