Look-Ahead Bias and Trading Costs in Backtests
Trace when a signal becomes known and include explicit execution costs before interpreting a historical strategy curve.
Write down the information clock
A rule based on a daily closing price is known only after that close is complete. Buying at that bar’s earlier opening price uses future information. A model can use a justified closing-auction convention, but it must specify what was actually known and executable. Our lab instead places the target order at the next supplied bar open.
Watch more than the entry expression
Future data can enter through centered indicators, full-sample scaling, revised fundamentals, survivorship-biased symbol lists or selecting the best parameters after looking at every period. Passing a simple one-bar timing test does not remove these other risks. Preserve versions of data and code so a result can be reproduced.
Separate price impact and commission
A fixed per-order commission, a notional basis-point fee and adverse execution price affect cash differently. Include both buy and sell costs for a closed trade. Set an explicit spread/slippage convention rather than assuming that the presence of a settings field means it was enabled. Backtrader’s opening slippage setting is an example of why defaults matter.
Handle the final position explicitly
A final marked position is not a realized sale. If a test marks at the last close without liquidating, report open units, market value and unrealized profit separately, including which exit costs are absent. A last-bar signal cannot fill at a later bar that is not in the data. Our lab exposes both boundaries instead of inventing a closing trade.
Reconcile an order ledger
Starting cash plus order cash changes should equal ending cash. Add the marked position to obtain ending equity. Closed-trade net plus open unrealized profit should match total net profit under the same rounding convention. Check a gap, a rejected order and a no-trade series; a smooth chart alone cannot establish these identities.
Keep evaluation independent of development
Choose rules and costs before evaluating an untouched period. Repeatedly changing the rule based on that period makes it part of development. Our fixed-parameter tool does not run an optimizer or claim an untouched out-of-sample result. Synthetic data tests verify the implementation, not the economic value of the rule.
Inspect the assumptions
Compare source-linked software workflows · Trace the local SMA model · Official sources