What a backtest is
A backtest applies a set of rules to past market data and records what would have happened. It is a simulation. No order was sent and nobody had to sit through the losses, so the result is hypothetical.
A backtest can show that a rule set was not obviously broken, find mistakes in the rules and give a rough idea of how a method behaves. It cannot show what the method will do next, and it does not prove the method works.
What the CFTC says about hypothetical results
In the United States, a commodity pool operator or commodity trading advisor that presents simulated or hypothetical results must attach a warning (CFTC Rule 4.41(b), see Sources). In plain words, the required statement says:
- These results are simulated and have inherent limitations.
- Unlike an actual record, they do not represent actual trading.
- Because the trades were never executed, the results may have under- or over-compensated for market factors such as a lack of liquidity.
- Simulated programs are designed with the benefit of hindsight.
- No claim is made that any account will or is likely to achieve profits or losses similar to those shown.
The rule says the statement must sit in immediate proximity to written hypothetical results. If you see backtest figures without anything like it, treat them with extra caution. This page is general education, not a presentation of any results.
Costs and slippage
A backtest that ignores costs is flattering. Real trading has commissions, exchange and other fees, the spread and slippage. A backtest that fills every order at the exact price it hoped for assumes away the hardest part. The more often a method trades, the more this matters. See Scalping futures.
A fair test charges a realistic cost on every trade, and then tests again with costs worse than expected to see how fragile the result is.
Biases that flatter a backtest
- Look-ahead bias. The test uses information that was not available at the time of the decision, such as a value that is only known once a period ends. It is easy to do by accident, and it makes results look much better than anything tradeable.
- Survivorship bias. The data holds only things that survived. A test on today's list of winners leaves out the ones that failed, and so overstates results. It matters most with stocks and funds, and less with a single futures contract, but the idea carries over to any selection made with hindsight.
- Unrealistic fills. Assuming you always got the price you wanted, with no regard for size or liquidity.
- Data problems. Missing or wrong data, and futures contracts stitched together in ways that create prices nobody could have traded.
Overfitting and too many tries
Overfitting means fitting rules so closely to past data that they capture its chance quirks, not anything lasting. The fit looks great and then fails on new data.
It usually comes from too many tries. Test enough variations of enough rules on the same data and some will look excellent by luck alone. Here is a made-up illustration: if you toss a fair coin ten times, ten heads in a row is very unlikely. Do that with a thousand coins and you will probably find at least one that managed it. Picking that coin tells you nothing about its next ten tosses.
Signs of overfitting:
- Many settings, each tuned to a precise value.
- Results that fall apart when a setting is changed a little.
- A rule with no sensible reason behind it, only a good past.
- A long history of trying and discarding versions that you have not counted.
Keep a count of how many things you tried. The more you tried, the more skeptical you should be of the best one.
In-sample, out-of-sample and walk-forward
- In-sample data is what you used to build and tune the rules.
- Out-of-sample data is data held back and never used to build them. You test on it once, after the rules are fixed. If you change the rules after seeing it, it is no longer out of sample.
- Walk-forward testing repeats this in steps. Fit the rules on one stretch of data, test them on the stretch just after, then move both forward and repeat. It looks at how the method does on data it has not seen, over several periods, instead of once.
- Held-back data, kept untouched until the end, is the most honest check you have. Decide how much to hold back before looking at any results.
Monte Carlo
A Monte Carlo test reshuffles or resamples the trades from a backtest many times to see how different the results could have looked with the same trades in a different order. It helps judge how large a drawdown might be and how much of a result was luck in ordering. It cannot fix a flawed backtest: it reuses the same trades, so any bias in them carries over.
Why live results differ
- Costs and fills are worse than assumed.
- The market changed. See Trend following versus mean reversion.
- The rules were fitted to chance quirks of the data.
- Real traders miss trades, hesitate and change the rules. See Mechanical versus discretionary trading.
- Data, platform or connection problems.
A common outcome is that live results come in below the backtest. Plan for that.
Risk note
A strong backtest is not evidence of future profit. The CFTC's required statement says hypothetical results are designed with the benefit of hindsight and that no one can say any account will achieve similar results. Futures trading carries a substantial risk of loss, and the CFTC's standard risk statement says you may lose more than you deposit. Treat any backtest as a reason to ask questions, not as a promise.