Skip to content
Learning path Silver Repeatable method

Transaction costs in backtests

How to model fills, commissions and costs in backtests without counting spread and slippage twice, with a worked gross-to-net example.

Cite this entry

This reference cites the Cyclepedia entry. The documents it draws on are listed in the entry’s sources.

Transaction costs in backtests are the charges and execution effects separating a theoretical result from a simulated one. Signals and order choices use information already available. After submission, the simulator replays later events chronologically: subsequent quotes and volumes can determine a simulated fill without being exposed to the strategy beforehand. Cost-model parameters must also be estimated without using the period being evaluated.

Who this is for — Anyone moving from theoretical signals to simulated orders who needs to know whether the theoretical advantage remains after execution. Subtracting a fixed commission is not enough when spread, impact, borrow, funding and fill probability change with instrument, time and quantity.

In simple terms — The signal says what one would like to buy or sell. The cost model asks whether, when, how much and at what price it would actually have been possible to do so.

From reference prices to 88 euros net100 shares · full entry and exit · hypothetical values. Deviations already in fills: −4 −4. Separate commissions: −4. Other charges excluded.From reference prices to 88 euros net100 shares · full entry and exit · hypothetical valuesDeviations already in fills: −4 −4. Separate commissions: −4. Other charges excluded.1Theoretical1002Entry−43Exit−44At fills925Commissions−46Net88Cyclepedia · conditional teaching diagram, not a forecast or promise
Hypothetical trade of 100 shares: deviations already included in fill prices are not deducted a second time.

From signal to net result

For a closed position, a reconcilable calculation starts from simulated fill prices and quantities:

net result = result at fill prices − commissions and other charges not already included

If fill prices incorporate spread, slippage or impact, those components must not be deducted again. Comparing the implemented position with a theoretical portfolio at reference prices instead diagnoses implementation shortfall. It requires a common valuation horizon and currency, requested and executed quantities, and timestamped benchmarks. The component for an unfilled order is a counterfactual comparison, not another commission to deduct from the actual position. This distinction follows the SEC’s 2003 discussion, §§ II.A and III.B, concerning fund securities transactions rather than a universal model for every market.

Component What it represents Main drivers
Commissions and fees applicable broker, venue, clearing, exchange and tax charges instrument, market, volume, fee schedule
Spread cost of crossing the bid/ask difference liquidity, time of day, volatility, order type
Slippage difference between the fill and the stated benchmark latency, gaps, depth, event sequence
Market impact price movement associated with one's own demand for liquidity size, participation, urgency, volatility, resilience
Delay and opportunity cost movement while the order waits or remains incomplete duration, limit, competition, signal decay
Partial fill and non-fill executed quantity below the requested quantity priority, depth, cancellations, venue
Borrow securities lending, availability, recalls and short fees lending demand, supply, security specificity
Funding and margin financing positions, collateral and leverage rate, currency, haircut, duration, intermediary
Roll and basis closing and reopening contracts or exposures curve, calendar, spread between maturities, liquidity

Other elements may include currency conversion, stamp duty or tax treatment. They should enter only where relevant and under a documented rule.

Margin is collateral or a capital requirement, not an expense to deduct in full every period. Interest and the financing cost of committed capital are modelled separately. A roll accounts for contract executions and charges; the price difference between maturities does not automatically become another commission, especially when already reflected in the performance series.


Why a fixed cost is not universal

An assumption of “one tick per trade” can be a teaching scenario, not a market property. The same order changes cost between an auction and continuous trading, normal conditions and stress, a liquid security and a micro-cap, or a passive and an aggressive order. Even the sign of slippage may be favourable or unfavourable relative to the benchmark; that does not make impact free or guarantee that the improvement can be repeated.

The model should therefore depend, when the data permit, on:

  • order quantity and notional value;
  • available volume and participation rate;
  • observable spread and depth;
  • volatility and time regime;
  • side, order type, urgency and duration;
  • venue, currency and asset class;
  • borrow, funding and contract state.

A simple function that increases with participation may be more transparent than a complex, uncalibrated simulation. Complexity should follow the data, not precede them.


Causal orders and fills

The correct chain is: available data → signal → order → market interaction → fill → position. A daily OHLC bar does not reveal the intraday sequence or the quantity available. If both a stop and a target are crossed within the same bar, the backtest cannot retrospectively choose the favourable outcome. It needs more granular data or a stated conservative rule.

For a limit order, “price touched” does not automatically mean filled: orders may be ahead in the queue or volume may be insufficient. For a market order, the price is not guaranteed and the order may cross several levels. Latency and partial fills change quantity, risk and subsequent signals. These constraints must respect the pipeline described in data leakage and look-ahead bias.


Strategy capacity

Capacity is the scale beyond which net return, risk or fidelity to the signal deteriorates materially. It is not a fixed amount valid forever. It depends on assets, turnover, concentration, horizon, crowding and execution method.

A practical check reruns the test at several levels of capital or participation. At each level it records:

Output Why it matters
requested and executed quantity separates desired exposure from the position obtained
percentage of volume measures relative pressure on the market
average and marginal cost shows scale non-linearity
incomplete orders identifies signals that cannot be implemented
net return and drawdown measures economic deterioration
liquidation time connects capacity with exit risk

Capacity is not demonstrated merely by comparing average size with average volume: stress days, concentrated instruments and simultaneous exits may dominate the risk.


Modelling protocol

  1. Define the benchmark. State the price and timestamp against which the fill is measured.
  2. Generate explicit orders. Quantity, side, type, limit, duration and logical priority must derive from the signal.
  3. Align calendars, contracts and data. Point-in-time: Replay events chronologically: a fill must be compatible with order acceptance and the liquidity then available; later data must not enter earlier decisions.
  4. Apply verifiable explicit costs. Version fee schedules, regime changes and currency.
  5. Model spread and impact without duplication. State the benchmark and the chosen function.
  6. Allow partial fills and non-fills. The position must use the quantities actually simulated.
  7. Add relevant holding costs. Borrow and funding follow rates and duration; treat margin as a capital constraint. Rolls follow contracts and calendars.
  8. Calibrate against reality when possible. Compare actual fills with forecasts by order class; paper trading remains a simulation and does not establish real queue position, impact or executability.
  9. Run scenarios. Base, favourable and severe cases should vary observable drivers, not multipliers presented as laws.
  10. Test multiple scales. Publish the cost and net-return curve against capital or participation.
  11. Freeze the model before OOS. Parameters and rules used in the out-of-sample evaluation must not be adapted to its result.

Reproducible example — A hypothetical long trade of 100 shares in euros, fully closed, with no financing, taxes or dividends. Reference prices are 100 at entry and 101 at exit: theoretical result 100 × (101 − 100) = 100 euros. Simulated fills are 100.04 and 100.96: result at fills 92 euros. Commissions of 2 euros per side give 92 − 4 = 88 euros net. The shortfall is 4 euros at entry + 4 at exit + 4 in commissions = 12 euros. The 8 euros already reflected in fills are not deducted again as spread or slippage.

Separately, an order for 20,000 units filled for 12,000 and then 5,000 leaves 3,000 unfilled: an 85% fill rate. The ledger holds 17,000 units; the theoretical result on the missing 3,000 belongs in the implementation comparison over a stated horizon. Scaling capital requires recalculating prices and quantities.


Limitations and communication

Counterfactual impact cannot be observed precisely: the market without one's own order cannot be seen. Models calibrated on quiet periods may fail under stress; quote data do not always reconstruct queue position; historical borrow and funding data may be incomplete. A backtest should therefore not present cost as a point truth, but as a conditional estimate with assumptions, intervals and scenarios.

Gross return remains useful for studying the signal; net return is needed to assess implementability. Publishing both, together with turnover, quantities, fill rate and capacity, makes visible where the result is created or lost.


Sources