597 / 736BT

Backtesting

Historical strategy testing

Backtesting simulates predefined rules on historical data. Its result depends on when information became available, data selection, the fill model and costs. A historical profit is neither an actual executed trade nor a guarantee of future returns.

Backtesting is a historical simulation of trading or decision rules with explicitly defined data, chronological order and execution assumptions. It allows a rule's behavior in a past sample to be examined, but its evidential value depends on the design of the entire test.

Backtesting replays rules on historical data and calculates what result they would have produced under the chosen assumptions. Bailey and coauthors describe it as a historical simulation of an algorithmic strategy while warning about the risk of false discoveries. Our editorial boundary is that the result belongs to a particular version of the rules, data and execution model. It does not establish that anyone actually executed those trades. A reproducible calculation can reveal an error or an unsuitable idea, but does not itself turn the past into a reliable forecast. [1]

QuantConnect describes the bias that arises when a simulation uses future information, such as financial figures before their publication or subsequent revisions. Our own timing contract requires the availability time of each input, not just the date of the period it describes. A signal from a closed candle cannot, without an additional assumption, obtain a trade at a price that was no longer available. In our example, prior closing prices are used only for the following period, whose opening fill is explicitly specified by the model. [2]

QuantConnect warns about testing only securities that survived to the end of the period and applying today's index composition retrospectively. Our broader question is whether the historical dataset also preserves instruments available at the time that later disappeared. Missing data, changes in methodology and market selection must be documented. For a Bitcoin simulation, a price from one service cannot automatically be treated as an attainable price on another. Clean data means traceable corrections, not removal of inconvenient results. [2]

QuantConnect documentation separates the signal and order from the model determining fill price and quantity. It also highlights the difference between partial fills in live trading and the assumption of complete fills in prebuilt models. Our own requirement is to describe when an order may execute, what happens with insufficient liquidity and how stale prices are handled. A price level touched in historical data does not itself establish an available counterparty for an arbitrarily large order. The fill model's output remains a simulation assumption. [3]

QuantConnect describes Slippage as the difference between expected and actual fill prices and notes the effects of latency, connectivity and market conditions; the deviation can be favorable or unfavorable. Our cost check separates fees, fill prices and any other holding or financing costs. A cost already included in the fill price must not be deducted again. A zero value is a specific modeling assumption, not evidence of a costless market. Sensitivity to worse costs helps establish whether a small historical profit depends on optimistic settings. [4]

The TimeSeriesSplit documentation explains chronological splitting to avoid training a model on the future and evaluating it on the past. Our methodological requirement is to designate a period for designing the rules and a period for subsequently validating them before looking at results. If failed rules are adjusted again based on the validation period, that period has already influenced development. Chronological splitting alone does not resolve leakage from preprocessing, overlapping targets or repeated variant selection. Both the process and the data boundaries must be described. [5]

Bailey and coauthors show that repeatedly searching for the best configuration on the same data increases the risk of false discoveries and fitting past noise. Our reporting rule is to disclose the history of attempts, not just the winning curve. This includes changes to parameters, periods and instrument selection. A result chosen after many trials does not carry the same evidential value as a predefined, unchanged rule. Their method for estimating the probability of overfitting is neither performed in our simple example nor replaced by a single data split. [1]

NFA warns that hypothetical results do not reflect actual trading, may benefit from hindsight and may imperfectly model liquidity, slippage or behavior under a real loss. Our report should therefore retain the data and code versions, rules, fill assumptions, included costs and complete list of simulated trades. Total return needs risk context and comparison under identical conditions; a selected attractive chart is insufficient. Even a flawless implementation of a historical test does not guarantee feasibility or returns in a future market. [6]

ExampleEXAMPLE · BT

A signal from the previous period, a fill in the next

Our fictional example uses four equally long periods A, B, C and D. Initial cash is 1000 USD, with no open position, debt, deposits or withdrawals. The two closing prices before period A are [100, 100] USD/BTC. Opening prices for periods A through D are [101, 103, 102, 105] USD/BTC and closing prices are [102, 101, 104, 103] USD/BTC. The predefined rule buys 1 BTC at the start of a period only if the last completed closing price exceeds the preceding completed closing price; it sells everything at the end of the same period. Signals are therefore [0, 1, 0, 1], where 1 means a trade and 0 inactivity. The model assumes complete fills at exactly the stated opening and closing prices, zero spread and Slippage, with no other costs except a fee of 0.1 USD for each purchase or sale. In B, it buys at 103 USD and sells at 101 USD; in D, at 105 USD and 103 USD. Gross period results are [0, -2, 0, -2] USD. The four executed trade sides cost a total of 0.4 USD and net results are [0, -2.2, 0, -2.2] USD. The gross total is -4 USD, the net total -4.4 USD and final cash 995.6 USD. The chart shows individual periods' net contributions, not an account balance or probability. This is a manually verifiable simulation of timing and accounting, not actual market data, optimization or evidence of future performance.

For the clearest picture, read this entry together with Trading Plan, Trading Journal, Slippage, Overfitting, Walk-forward Analysis. The reverse links also lead from Technical analysis, OHLCV, Timeframe, Candlestick chart.

01Does a profitable backtest prove that a strategy will make money?

No. The result may depend on specific data, costs, the fill model or selection of the best variant. Timing correctness, assumptions and the selection process need verification; even then, there is no guarantee of future returns.

02Is it enough to deduct fees only from the final profit?

Only if that method exactly matches the model and does not affect available capital or subsequent decisions. Usually costs need to be booked at the corresponding events, with fill prices distinguished from fees and double deduction prevented.

DOC · 001Bailey et al. — The Probability of Backtest OverfittingPrimary DOC · 002QuantConnect — Research GuideDocumentation DOC · 003QuantConnect — Trade Fills: Key ConceptsDocumentation DOC · 004QuantConnect — Slippage: Key ConceptsDocumentation DOC · 005scikit-learn — TimeSeriesSplitDocumentation DOC · 006NFA — Use of Promotional Material Containing Hypothetical Performance ResultsDocumentation
Revised: Source-first · No investment advice