How to model transaction costs in a backtest
4 min read
Transaction costs should be modeled as fill-level components rather than as a single flat percentage. Commission, spread, and market impact arise through different execution mechanisms and vary with trading conditions, so averaging them into one number can hide implementation risk. The cited Sonar Sciences sources support this as a strategy-validation principle: realistic assumptions and friction-aware testing are necessary to judge whether a backtest remains credible after practical constraints are applied.
Transaction costs are the execution frictions that turn a theoretical trade into a realized trade. In a backtest, these frictions matter because a strategy is validated on net results, not on gross signals alone. A flat percentage cost can be a convenient simplification, but it compresses different sources of friction into one average number. That average can hide where losses are actually introduced and how those losses change with trading conditions.
A component-based model starts from the fill. Each fill can carry its own commission, spread cost, and market impact. Commission is the explicit fee charged for execution. Spread cost comes from crossing the bid ask spread rather than trading at the mid price. Market impact is the price movement caused by the trade itself or by the liquidity consumed while completing it. Modeling these items per fill ties cost to the mechanics of execution instead of assigning one uniform drag to all trades.
This matters in strategy validation because validation is about testing whether a result survives realistic assumptions. Sonar Sciences describes strategy validation as a process that checks whether apparent edge remains after practical constraints and robustness checks are applied, rather than accepting an attractive backtest at face value. In that context, transaction costs are not a cosmetic adjustment. They are part of the assumptions that determine whether a strategy remains credible once implementation frictions are included [1].
Per-fill cost modeling is more faithful to execution because costs are path dependent. A strategy that trades frequently, trades larger size, or trades in less liquid conditions will not experience the same friction on every order. Spread can vary by instrument and market state. Commission can vary by venue, broker schedule, or order type. Impact depends on how much liquidity is demanded relative to what is available at the time of execution. A flat percentage cost averages across these differences and can therefore understate costs in the trades where friction is highest and overstate them where friction is low.
A practical way to structure the model is to compute expected execution cost for each fill as the sum of its components. First assign explicit commissions according to the fee schedule relevant to the instrument and execution route. Then estimate spread cost from the portion of the spread paid by the order, which is often tied to whether the backtest assumes passive or aggressive execution. Then add an impact term that grows with order size and liquidity usage. The exact parameterization depends on the data and market being studied, but the principle is the same: costs should be attached to the specific fill event that creates them.
This approach also improves diagnostic power. If net performance deteriorates, a component model can show whether the problem came from frequent spread crossing, fee accumulation, or size-driven impact. A flat percentage cost cannot explain that mechanism. It only produces a single blended penalty. For a strategy developer, that distinction is important because validation should reveal implementation sensitivity, not hide it inside an average haircut [1][2].
The same logic fits the broader caution against overinterpreting backtests. Sonar Sciences' backtest overfitting audit emphasizes that a backtest can appear strong because assumptions are too favorable or because the design has adapted to noise. Realistic friction modeling is one way to tighten those assumptions. When cost modeling is too coarse, the test can retain false precision. When cost modeling is linked to fills and execution conditions, the backtest is closer to an implementation test and less likely to treat optimistic assumptions as genuine signal [2].
This point is consistent with why risk-adjusted statistics need careful interpretation. Sonar Sciences' glossary entry on the Deflated Sharpe Ratio explains that headline Sharpe ratios can be misleading when selection effects and multiple testing are present. Transaction cost assumptions feed directly into those headline metrics because net returns and volatility both depend on execution friction. If costs are averaged too crudely, the resulting Sharpe ratio can reflect the modeling shortcut as much as the strategy. More realistic cost attribution helps ensure that the measured statistic better represents the strategy under implementable conditions [3].
The claim that per-fill spread, commission, and impact modeling provides a more accurate representation of execution friction than a flat percentage cost is supported at the conceptual and validation-framework level by these sources. Those inputs would be needed to estimate the size of the error from flat-cost assumptions for a specific asset universe or execution style.
Drafted with AI assistance from cited sources. Reviewed and approved by Sonar Sciences Quant & Research Team.