BacktestingOOS
Backtesting is applying a strategy's rules to historical data to see how it would have performed — useful, but easy to fool yourself with if the test is not honest.
Before risking money on a strategy, you can ask how it would have done in the past. That is backtesting: apply precise rules to historical prices and record every trade the rules would have taken. A good backtest can reject bad ideas cheaply. A careless one does the opposite — it produces beautiful equity curves for strategies that fail the moment they meet live markets. This entry explains how to run an honest backtest and the biases that most often break them.
- Reading time
- 6 min
- Also called
- Backtest, Historical testing, Strategy backtest
- Updated
Backtesting in plain words
Write your strategy as exact rules: when to enter, where the stop and target go, how much to risk.1 Then go through past price data, bar by bar, and record what those rules would have done — every entry, exit, cost and result.2
The output is a list of hypothetical trades and the statistics they produce: win rate, average win and loss, Expectancy, Drawdown. Those numbers are only as trustworthy as the honesty of the test.
How to run an honest backtest, step by step
Write unambiguous rules
Every decision must be defined in advance. If two people could read a rule differently, the test cannot be trusted.
Get clean data
Use data adjusted for splits and dividends, include delisted assets where relevant, and know which session times it covers. See Survivorship Bias.
Split the data
Design and tune the strategy on one period (in-sample) and keep a later period untouched for a single final test (out-of-sample).
Model real costs
Include commissions, spreads, Slippage and financing. Short-term strategies often live or die on costs.
Avoid look-ahead
Only use information available at the moment of each decision. See Look-Ahead Bias.
Judge with enough trades
Dozens of trades say little; hundreds give more confidence. Then forward-test on new data before trading real size. See Forward Testing.
Worked examples
Example 1 — Costs change the verdict
CostsA day-trading strategy shows 400 trades over two years with an average gain of $0.04 a share on 500 shares, before costs. Spread, slippage and fees add up to $0.05 a share per round trip.
| Gross per trade | 500 × $0.04 = +$20 |
| Costs per trade | 500 × $0.05 = −$25 |
| Net over 400 trades | 400 × −$5 = −$2,000 |
A strategy that looked profitable is a loser once realistic costs are included.
Example 2 — In-sample vs. out-of-sample
OverfitA trader tunes a moving-average system on 2017–2022, trying 200 combinations. The best shows +38% a year. On 2023–2025, never used in tuning, the same settings return +3% a year.
| In-sample (tuned) | +38% a year |
| Out-of-sample (untouched) | +3% a year |
| Reading | Most of the in-sample result was fitting noise |
Picking the best of 200 variations almost guarantees a great in-sample number. Only the untouched data gives an honest estimate. See Overfitting and Data Snooping.
Example 3 — Look-ahead bias
Look-aheadA backtest buys at a day’s close whenever that day’s close is above its 20-day high. It shows a 75% win rate.
| Problem | The signal needs the close; the trade uses the same close |
| Realistic version | Trade at the next day’s open |
| Win rate after fixing | Much lower |
Using information that would not have been available at decision time is one of the most common backtesting errors.
In-sample, out-of-sample and walk-forward
Ways to test a strategy
| Aspect | What it shows | Main weakness |
|---|---|---|
| Backtest (in-sample) | Whether the idea worked on past data | Easily overfitted |
| Out-of-sample test | Performance on data not used for tuning | Only one sample; use it once |
| Walk-forward analysis | Repeated out-of-sample results over time | More work; still historical |
| Forward / paper testing | Behaviour in live market conditions | Slow; no real fills or emotions |
| Small live trading | Real fills, costs and psychology | Costs real money |
What backtesting is good for
Rejecting bad ideas cheaply
Most ideas fail a careful backtest; finding that out costs nothing.
Setting expectations
Win rate, average R and drawdowns tell you what to expect live. See Win Rate.
Sizing
Historical losing streaks and drawdowns guide sensible risk per trade. See Position Sizing.
Building confidence in rules
Knowing a rule’s history makes it easier to follow during a bad run.
Advantages and disadvantages
Advantages
- Tests ideas without risking money.
- Produces objective statistics instead of impressions.
- Forces precise, written rules.
Disadvantages
- Past performance may not repeat; markets change.
- Easy to overfit by testing many variations.
- Costs, slippage and liquidity are often underestimated.
- Cannot capture the psychology of trading real money.
Going deeper
Read as far as you need. Each level builds on the one before it.
Manual backtesting
Beginner
You can backtest by scrolling through charts bar by bar and recording what your rules would have done. It is slow, but it builds pattern recognition — as long as you do not peek at the bars to the right.
The biases that break backtests
Intermediate
Overfitting (tuning to noise), look-ahead bias (using future data), survivorship bias (testing only assets that still exist) and data snooping (trying so many ideas that some work by luck) each make results look better than reality. Most failed backtests suffer from at least one.
Robustness checks
Advanced
Robust strategies keep working when parameters change slightly, on related markets and in different periods. Reshuffling the order of trades many times (Monte Carlo analysis) shows how deep drawdowns could have been with different luck. See Walk-Forward Analysis.
Common mistakes
Optimising until it looks perfect
The best of many variations is usually the luckiest, not the best.
Ignoring costs
Spreads, fees and slippage can erase a small edge entirely.
Testing on too few trades
Twenty trades cannot distinguish skill from luck. See Sample Size and Statistical Significance.
Reusing the out-of-sample data
Once you adjust the strategy after seeing the out-of-sample result, it is no longer out-of-sample.
Check your understanding
Test yourself before moving on. Each answer comes with an explanation.
Key points to remember
- Backtesting applies exact rules to historical data to estimate performance.
- Split data: tune in-sample, test once out-of-sample.
- Include realistic costs and slippage, and avoid look-ahead.
- Beware overfitting, survivorship bias and data snooping.
- Forward-test and start small before trusting a backtest with real money.
Frequently asked questions
How many trades does a backtest need?
Why does my strategy work in the backtest but not live?
Is paper trading the same as backtesting?
Further learning
- Win Rate
One of the key statistics a backtest produces.
- Drawdown
Why live drawdowns are usually deeper than backtested ones.
- Slippage
A cost backtests often underestimate.
- Trading Journal
Where live results are compared with the backtest.
Sources
This article is written in our own words. The sources below support the specific facts, rules and figures marked with a number in the text. Links open the original publisher’s page.
- CME Group. System-Based vs. Discretionary Trading (opens in a new tab) Checked .
- Charles Schwab. Backtesting (opens in a new tab) Checked .
Educational content, not financial advice. Examples use hypothetical prices and simplified costs; actual fees, margin rules and regulations vary by broker, market and country. We are not affiliated with any publisher linked above. Last reviewed . Report an error or request a source credit.