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.

Category
Trading Psychology and Performance
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

  1. Write unambiguous rules

    Every decision must be defined in advance. If two people could read a rule differently, the test cannot be trusted.

  2. 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.

  3. 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).

  4. Model real costs

    Include commissions, spreads, Slippage and financing. Short-term strategies often live or die on costs.

  5. Avoid look-ahead

    Only use information available at the moment of each decision. See Look-Ahead Bias.

  6. 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

Costs

A 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.

Example 1 — Costs change the verdict — calculation
Gross per trade500 × $0.04 = +$20
Costs per trade500 × $0.05 = −$25
Net over 400 trades400 × −$5 = −$2,000

A strategy that looked profitable is a loser once realistic costs are included.

Example 2 — In-sample vs. out-of-sample

Overfit

A 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.

Example 2 — In-sample vs. out-of-sample — calculation
In-sample (tuned)+38% a year
Out-of-sample (untouched)+3% a year
ReadingMost 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-ahead

A backtest buys at a day’s close whenever that day’s close is above its 20-day high. It shows a 75% win rate.

Example 3 — Look-ahead bias — calculation
ProblemThe signal needs the close; the trade uses the same close
Realistic versionTrade at the next day’s open
Win rate after fixingMuch lower

Using information that would not have been available at decision time is one of the most common backtesting errors.

Figure 1

In-sample, out-of-sample and walk-forward

In-sample, out-of-sample and walk-forward testingThe top bar splits nine years of data: the strategy is designed and tuned on 2017 to 2022 (in-sample) and then tested once on 2023 to 2025 (out-of-sample). Below, walk-forward testing repeats this on rolling windows: tune on three years, test on the next year, then move forward one year.201720182019202020212022202320242025in-sample: design and tuneout-of-sample: test onceWalk-forwardtune 3 years → test 1tune 3 years → test 1tune 3 years → test 1tune 3 years → test 1
Tune on one period, test once on a later untouched period. Walk-forward testing repeats this on rolling windows.

Ways to test a strategy

AspectWhat it showsMain weakness
Backtest (in-sample)Whether the idea worked on past dataEasily overfitted
Out-of-sample testPerformance on data not used for tuningOnly one sample; use it once
Walk-forward analysisRepeated out-of-sample results over timeMore work; still historical
Forward / paper testingBehaviour in live market conditionsSlow; no real fills or emotions
Small live tradingReal fills, costs and psychologyCosts 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

  1. Optimising until it looks perfect

    The best of many variations is usually the luckiest, not the best.

  2. Ignoring costs

    Spreads, fees and slippage can erase a small edge entirely.

  3. Testing on too few trades

    Twenty trades cannot distinguish skill from luck. See Sample Size and Statistical Significance.

  4. 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.

Q1A backtest shows +$12 per trade before costs; costs are $15 per trade. What is the result over 300 trades?
Q2Why keep an out-of-sample period untouched?

Key points to remember

  1. Backtesting applies exact rules to historical data to estimate performance.
  2. Split data: tune in-sample, test once out-of-sample.
  3. Include realistic costs and slippage, and avoid look-ahead.
  4. Beware overfitting, survivorship bias and data snooping.
  5. Forward-test and start small before trusting a backtest with real money.

Frequently asked questions

How many trades does a backtest need?

There is no fixed number, but dozens are too few to judge an edge reliably. Aim for hundreds where the strategy allows it, across different market conditions.

Why does my strategy work in the backtest but not live?

Common causes are overfitting, underestimated costs and slippage, look-ahead bias, or a change in market conditions.

Is paper trading the same as backtesting?

No. Backtesting uses historical data; paper (forward) trading runs the strategy in real time without real money. Both are useful before risking capital.

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.

  1. CME Group. System-Based vs. Discretionary Trading (opens in a new tab) Checked .
  2. 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.