Strasmore Research
Learn Matt ConnorBy Matt Connor

What Is Backtesting in Trading?

Backtesting replays a trading rule over past bars, seeing only what was known at the time. What comes out, four ways it lies, and when a result is too good.

Backtesting is the process of running a trading rule over historical price bars, one bar at a time, where the rule sees only the data that existed at each bar and every trade it generates is priced at the next available price rather than the price that produced the signal. The output is a record of what the rule would have done over one stretch of the past: an equity curve, a drawdown profile, a trade list, and a few summary statistics such as the Sharpe ratio. What comes out describes history. It does not forecast anything.

What is backtesting, precisely?

A bar is one fixed interval of price history: an open, a high, a low, a close, and the volume traded, at whatever interval the rule works on (our guide on how OHLCV bars are built covers where those five numbers come from). A backtest is a loop that walks forward through those bars in order. At bar t the rule is handed every bar up to and including t, and nothing past it.

Two constraints turn that loop into an honest test. The first is the information constraint: the rule may use only what was knowable when bar t closed. Prices from bar t+1, fundamentals restated after the fact, index membership as it stands today, a dividend not yet declared: none of it is admissible. The second is the fill constraint: an order decided on bar t's close is filled at the next available price, usually the open of bar t+1. The close that produced the signal was already printed when the decision was made; nobody can buy at a price whose printing is the very thing that told them to buy.

The size of that gap is measurable. The panel below takes 5 liquid names over the 2025 calendar year and, for every session, compares the close with the following session's open, reporting the average and the median absolute distance in basis points.

QueryDistance from one close to the next open, liquid names, 2025 (basis points)
tickeravg_abs_gap_bpsmedian_abs_gap_bps
AAPL73.336.4
MSFT66.339.8
TLT47.137.5
SPY46.728.5
KO38.123.5
The exact SQL behind every number
WITH
    px AS
    (
        SELECT
            ticker,
            date,
            toFloat64(open)  AS open_px,
            toFloat64(close) AS close_px
        FROM global_markets.stocks_daily_aggs
        WHERE ticker IN ('SPY', 'AAPL', 'MSFT', 'KO', 'TLT')
          AND date >= '2025-01-01'
          AND date <= '2025-12-31'
    ),
    gaps AS
    (
        SELECT
            ticker,
            date,
            close_px,
            leadInFrame(open_px) OVER (PARTITION BY ticker ORDER BY date ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS next_open
        FROM px
    )
SELECT
    ticker,
    round(avg(abs(next_open / close_px - 1)) * 10000, 1)     AS avg_abs_gap_bps,
    round(median(abs(next_open / close_px - 1)) * 10000, 1)  AS median_abs_gap_bps
FROM gaps
WHERE next_open > 0
GROUP BY ticker
ORDER BY avg_abs_gap_bps DESC, ticker ASC
Run this yourself

Across the 5 names, the average absolute move from one close to the next open ran from 38.1 basis points (KO) to 73.3 basis points (AAPL). A backtest that fills at the signal close is off by that distance on every trade, and the error never appears as a line item in the equity curve.

Every fill is then charged a commission plus an allowance for slippage, the gap between the price you expected and the price you got, which for a small market order is at least half the bid-ask spread. The account is marked to market at each subsequent bar. Repeat until the last bar. Everything else in a backtesting framework is bookkeeping around this loop.

What does a backtest produce?

The equity curve is the account value at every bar, marked to the prevailing price. Its shape carries more information than its endpoint: a rule that made its whole return in one lucky month and then flat-lined is a different rule from one that compounded steadily.

Drawdown is the distance from the running peak of the equity curve down to the current value, and maximum drawdown is the deepest such fall over the whole test. Our note on maximum drawdown walks through the measurement.

The trade list records every entry and exit with its timestamp, price, size, and cost. This is the audit trail, and most backtest bugs are found by reading it: a fill timestamped before its own signal, or a trade dated on a day the market was closed.

The summary statistics compress all of that into a handful of numbers: total return, annualized volatility, the Sharpe ratio (average excess return per unit of volatility), hit rate, and exposure (the share of bars with a position open).

What the loop does not produce is a forecast. A backtest reports what one rule did on one path through history, and the statistics arrive without error bars unless you build them: a single Sharpe figure says nothing about how much of it is luck, which is the question bootstrapping a backtest exists to answer.

The four ways a backtest lies

A backtest that fails is informative. A backtest that succeeds for the wrong reason is expensive. Four failure modes account for most of the expensive kind.

Look-ahead bias

Look-ahead bias is any leak of future information into the rule's view at bar t. The obvious form is filling a trade at the same close that produced the signal. The subtle forms hide in the data: a fundamentals table carrying the restated figure instead of the one first published, an indicator normalized by a full-sample mean, a present-day index list applied to years past, a price filter run on split-adjusted prices that did not exist at the time. The common leaks and their fixes are catalogued in look-ahead bias in backtesting.

Survivorship bias

Survivorship bias is testing on the stocks that still exist today. Companies that went bankrupt or were acquired drop out of a current-constituents universe, and the sample that remains tilts toward names that did well enough to survive. The fix is a point-in-time universe that includes the dead, and the reasons this is harder than it sounds, including the way ticker symbols get reused by unrelated companies, are covered in survivorship bias in stock data.

Overfitting to the sample

Overfitting is tuning a rule until it fits the one history you have, noise included. Every free parameter (a lookback length, a threshold, a stop distance, a filter) is a dial, and enough dials will fit anything. The symptoms are recognizable: performance that collapses on a held-out period, or a parameter that works at one value and fails at its neighbors. The defense is fewer dials and a held-out sample that is touched exactly once.

Ignoring costs and slippage

The fourth lie is the cleanest to state: a fill at the mid-price with no commission is a fill nobody gets. A market order pays the spread; a limit order waits in a queue and may never fill (see estimating queue position); a large order moves the price against itself; a fast market widens all of it. Suppose, hypothetically, a rule earns eight basis points per round trip before costs and the spread costs five basis points each way: the costless backtest shows a winner and the honest one shows a steady loser.

Backtest vs paper trading vs forward test

The three are often confused, and they test different things.

  • Backtest: historical bars, simulated fills, runs in minutes, covers years of history, tests whether the logic had an edge in the past.
  • Paper trading: live data, simulated fills, runs in real time, covers only the days since it started, tests the plumbing (data feed and order generation) with no capital at risk.
  • Forward test: live data, real fills at small size, runs in real time, tests the execution assumptions (slippage and fill rates) with money at risk.

A backtest covers twenty years in an afternoon; the other two cover one day per day, which is why the sequence runs in this order and why none of the three replaces another.

Why a backtest is necessary and never sufficient

Necessary, since a rule that cannot pass its own history has no claim on the future, and the loop finds that out in minutes at zero cost. Most ideas die here, which is the point.

Never sufficient, for two reasons. First, the sample is one path. A rule that survived a past crash in a test did so once, on one sequence of prices; the test cannot say what it does on a sequence that has not happened yet. Second, the rule was selected on that path. Any process that keeps the variants that scored well and discards the rest has, by construction, produced a survivor whose score overstates its skill.

That second point is the multiple-testing problem, and it is how to recognize a result that is too good. Test enough rules on the same history and some will clear any bar you set through chance alone; the more variants tried before the one that passed, the less the pass means. The report cannot tell a first attempt from a twentieth; only the researcher's log can. As a rule of thumb used on many desks, a simple daily rule reporting a Sharpe ratio above two over a decade is more often a symptom of one of the four lies above than a discovery. A reproducible backtest, where the same data and code yield the same trade list on every run, is what makes the hunt for the leak possible.

FAQ

What is backtesting in simple terms?

Replaying history to see what a trading rule would have done. The rule walks through past price bars one at a time and sees only what was known at each bar; its trades are priced at the next available price. The result is an equity curve and a trade list, not a prediction.

Is backtesting the same as paper trading?

No. A backtest runs on historical data with simulated fills and covers years in minutes. Paper trading runs on live data in real time with simulated fills; it covers one day per day and mainly tests the data feed and order logic rather than the strategy's history.

Why do backtests fail in live trading?

Four reasons account for most failures: the rule saw future information (look-ahead bias), the universe excluded dead companies (survivorship bias), the parameters were tuned to the sample (overfitting), or the simulated fills ignored spread and slippage. Live trading removes all four advantages at once.

How far back should a backtest go?

Far enough to include more than one market regime, at minimum a rising period and a falling period. Data from before a structural change in market plumbing, such as the move to decimal pricing in 2001, may describe a market that no longer exists.


When you are ready to put a rule against real historical bars, the Strasmore terminal is where that data lives.

#backtesting#quant#strategy#bias#definition