What is backtesting? A plain guide to testing a trading rule

Backtesting runs a trading rule over historical prices to see what it would have done. It is the cheapest way to find out that an idea does not work, and the easiest way to fool yourself that one does. This guide explains how a backtest works, which results matter and which mistakes to avoid.

By Kereon · Published November 14, 2026 · 5 min read

Key points

  • A backtest applies fixed buy and sell rules to past prices and records every trade the rules would have made.
  • Judge a result by its drawdown, its number of trades and its costs as well as its return, and always against simply holding the same stocks.
  • The most common errors are look-ahead bias, survivorship bias, overfitting and ignoring trading costs.
  • A backtest describes the past under its own assumptions. It is evidence for further study, not a forecast.

What a backtest is

A backtest is a simulation. You write down a rule precise enough for a computer to follow, such as buying a stock when its 50-day moving average crosses above its 200-day average and selling when it crosses back below, and the test applies that rule to years of past prices, one day at a time.

The output is a record of every trade the rule would have made and the value of an account that followed it. From that record come the statistics: how much the account grew, how far it fell along the way and how consistent the gains were.

Because the rule is fixed in advance, a backtest removes the hindsight that creeps into looking at a chart. It answers a narrow question: if I had followed exactly these rules over this period, with these costs, what would have happened?

How a backtest works, step by step

  1. Define the rules: the entry condition, the exit condition, the position size and any stop or target.
  2. Choose the universe and the period: one stock, or every stock that passes a filter, over a stated span of years.
  3. Set the costs: the commission per trade and the slippage, the gap between the price you see and the price you get.
  4. Run the simulation: the test walks forward one bar at a time and acts only on information available at that moment.
  5. Read the results against a benchmark, usually buying and holding the same stocks over the same period.

The numbers that matter

Return is the headline, but on its own it is the least informative number. A strategy that doubled your money while once losing 60% of it is a different proposition from one that returned less with a worst loss of 15%.

  • Compound annual growth rate (CAGR): the constant yearly rate that turns the starting value into the ending value.
  • Maximum drawdown: the largest fall from a peak to a later low, the worst loss an investor following the rule would have sat through.
  • Sharpe ratio: the average return divided by its volatility, annualized. Higher means more return for each unit of risk taken.
  • Profit factor: gross profit divided by gross loss. Above 1, the winning trades outweigh the losing ones.
  • Win rate: the share of trades that made money. A low win rate can still be profitable when the winners are much larger than the losers.
  • Number of trades: the sample size behind every other number on the list.

Read them together. A high Sharpe ratio over twelve trades is weaker evidence than a modest one over three hundred.

A worked example: what costs do to a busy rule

Suppose a rule makes 9% a year before costs and trades often: 50 round trips a year, each buying and later selling a full position. If commission and slippage together cost 0.2% per round trip, the costs take roughly 50 × 0.2% = 10 percentage points a year.

The rule that looked like a 9% winner loses about 1% a year after costs. The same arithmetic barely touches a rule that trades four times a year, where costs take 4 × 0.2% = 0.8 points. This is why every serious backtest charges realistic costs, and why frequent trading needs a much larger edge to survive them.

The example is hypothetical and simplified: real costs depend on the position size, the stock's liquidity and the broker, and they compound with the account rather than adding up exactly.

The mistakes that flatter a backtest

Look-ahead bias uses information that was not available when the trade would have been made, such as a quarterly figure that was revised after its release, or the day's closing price used to decide a trade at that day's open.

Survivorship bias tests only companies that still exist. Firms that went bankrupt or were delisted are missing from today's lists, so a test over current companies quietly removes many of the worst outcomes and flatters the result.

Overfitting tunes a rule until it matches the past too well. Test 100 random rules that have no real edge, and about five of them will look statistically significant at the usual 5% level by chance alone. The more variations you try, the more likely it is that the best one is luck.

Ignoring costs and trusting tiny samples complete the list. A rule that trades rarely may show a perfect record over six trades, which proves almost nothing about the next six.

How to check whether a result is real

  • Hold data out: tune the rule on one period and test it on another that it has never seen.
  • Walk forward: repeat that tune-then-test cycle across the whole history, and judge only the out-of-sample results.
  • Vary the settings: a rule that works with a 50-day average but fails at 45 or 55 days is probably fitted to noise.
  • Reshuffle the trades: dealing the same trades in a different order shows how much of the drawdown was the sequence.
  • Compare with buy and hold: a strategy that trails simply owning the same stocks has to justify its complexity another way, such as a smaller drawdown.

Backtesting on Kereon

Kereon's Strategies page builds rules from plain conditions over 122 indicators, or starts from one of twenty templates, and runs them over one stock or over every stock a numeric filter admits. Each test charges the commission and slippage you set, compares the result with holding the same stocks and reports the full statistics.

Its robustness tools deal the same trades in a different order, rerun the rule under other settings and run a walk-forward test, and Optimize recommends a setting only when it holds up out of sample. The backtesting guide describes the page in more detail, and the glossary defines every statistic it reports.

Questions

Is backtesting reliable?

It is reliable as a description of the past under the test's assumptions, and unreliable as a prediction. Its value is in rejecting ideas that would not have worked and in showing the risks of the ones that might.

What is the difference between backtesting and paper trading?

A backtest replays the past with fixed rules in seconds. Paper trading follows the rules in real time without real money, which tests the idea on data it has never seen but takes months to build a useful sample.

Can I backtest a strategy without coding?

Yes. Many tools, including Kereon's Strategies page, let you build rules from menus of indicators and conditions instead of writing code.

Terms in the glossary

Read next

Educational content, not investment advice. Every example uses hypothetical numbers.