Backtesting fees and slippage: model real trading costs

A backtest that buys and sells at a candle's ideal price is measuring a market that nobody can trade. Real orders pay fees, cross spreads, arrive late, consume liquidity, and sometimes carry funding or borrow. This guide builds a transparent cost model, works through the math in basis points, and shows how to stress the assumptions before a bot reaches live money.

On this page
  1. The complete cost stack
  2. Worked round-trip example
  3. Realistic fill models
  4. Cost sensitivity testing
  5. Calibrate with real fills
  6. FAQ

The complete cost stack

Separate costs into components so each assumption can be inspected and changed. One unexplained “0.1% cost” input hides too much.

ComponentWhy it occursHow to model it
Commission or venue feeExplicit charge on executed notional, shares, or contractsApply the correct maker/taker or broker schedule to every fill
Bid-ask spreadAn immediate buy trades near the ask; an immediate sell near the bidUse historical bid/ask data or a side-aware spread estimate
SlippagePrice moves between decision and executionAdverse adjustment by side, volatility, order type, and delay
Market impactThe order consumes depth and moves its own execution priceScale cost with size versus available depth or traded volume
CarryPerpetual funding, margin interest, or stock borrowAccrue over the actual holding intervals
Other chargesExchange, regulatory, clearing, conversion, or data costsInclude when material to the venue and instrument

Apply execution costs to both sides of a round trip. A fee quoted per trade side is paid at entry and exit. Spread and slippage are also direction-aware: increasing a long entry price is a cost, while decreasing its exit price is a cost. Short trades reverse the price directions but still suffer adverse execution.

net expectancynet return = gross strategy return
             - explicit fees
             - spread cost
             - slippage and impact
             - applicable carry and other charges

Worked round-trip example in basis points

One basis point (bp) is 0.01%. Suppose a strategy's average gross gain is 30 bps per completed trade. The assumptions—not venue quotes—are 5 bps commission per side, 3 bps spread cost per side, and 4 bps slippage per side.

ItemEntryExitRound trip
Commission5 bps5 bps10 bps
Spread3 bps3 bps6 bps
Slippage4 bps4 bps8 bps
Total12 bps12 bps24 bps

The 30-bp gross edge becomes only 6 bps net before carry. On $10,000 of notional, that is $30 gross versus $24 of modeled cost, leaving $6. Across 100 round trips with the same notional, costs total $2,400 and the modeled net is $600 rather than the attractive $3,000 gross result.

Turnover multiplies small errors

Underestimating cost by just 5 bps per round trip is $500 across 100 trades at $10,000 notional. High-frequency or high-turnover strategies need a much larger gross edge than slow strategies to survive the same friction.

Choose a fill model that matches the data

A candle bar contains open, high, low, and close—not the sequence inside the bar, bid/ask spread, queue position, or available depth. The model must not claim precision that the data cannot support.

Do not give limit orders guaranteed maker fees. A marketable limit crosses immediately and can be treated as taker activity; a resting order may not fill at all. Model the execution condition first, then apply the fee class supported by that simulated fill.

For a dedicated round-trip worksheet and post-only tradeoffs, see maker vs taker fees for trading bots.

Run a cost frontier, not one lucky assumption

No historical estimate is exact. Test a grid from favorable to severe, using values grounded in the target market. A simple report might show:

ScenarioFeeSpread + slippageQuestion answered
Frictionless00Does the raw signal contain any edge at all?
OptimisticBest plausible tierQuiet, liquid conditionsWhat is the upper bound?
BaseExpected account tierMedian measured executionWhat is the planning case?
StressedConservative tierVolatile or thin conditionsDoes the edge survive deterioration?

Plot net return, profit factor, drawdown, and trade count across the grid. A robust strategy degrades gradually. If profitability exists only at zero cost or vanishes with a tiny assumption change, reject or redesign it. Also segment costs by asset, time of day, volatility regime, and order-size bucket; one global average can subsidize the worst trades with the best.

Calibrate assumptions with paper and small live fills

Record signal timestamp and price, order-send time, acknowledgement, every fill, side, quantity, fee, best bid/ask at decision, and market volatility. From that journal calculate implementation shortfall: the difference between the decision price and actual average execution, including explicit fees. Keep latency and market movement separate where the data permits.

  1. Start with conservative public spread and fee assumptions.
  2. Paper trade to validate order logic, while recognizing simulated liquidity may be generous.
  3. Use the smallest practical live size to observe real fill behavior.
  4. Group results by the factors that drive execution rather than averaging everything together.
  5. Update the backtest model and rerun the entire cost frontier.
  6. Monitor live-versus-modeled shortfall; pause scaling when it drifts beyond limits.

The site's free strategy backtester includes an adjustable fee input for a first-pass test. A production decision still needs spread, slippage, timing, and instrument-specific carry added to the broader process in how to backtest a strategy.

Not financial advice. This content is educational. Automated and algorithmic trading carries a real risk of financial loss. Never trade money you cannot afford to lose. Review the SEC investor.gov and CFTC resources before trading.

Frequently asked questions

What trading costs should a backtest include?

Include explicit commissions or venue fees, bid-ask spread, slippage, and market impact on entry and exit. Add funding, borrow, exchange, regulatory, data, and currency-conversion costs when they apply to the instrument and holding period.

How do I model slippage in a backtest?

Start with side-aware fills that cross the spread, then add adverse slippage based on order type, liquidity, volatility, size, and delay. Test a range rather than one optimistic constant, and calibrate assumptions against timestamped paper and small live fills.

Can a limit order backtest assume every touched price fills?

No. A bar touching a limit does not prove the bot had queue priority or enough volume traded after its order arrived. Use a conservative rule such as price trading through the limit, a volume or queue model, or report optimistic and conservative scenarios.

How can I tell if a strategy is too sensitive to costs?

Run a cost frontier across plausible fee and slippage assumptions. If a small increase turns expectancy negative or only the best-case scenario works, the edge is fragile. Compare average gross profit per trade and turnover with total round-trip cost.

MB

Mustafa Bilgic

Algorithmic trading practitioner · Founder, AITradingBot.us

Mustafa builds and backtests automated trading systems and writes about them without the hype. Every tool on this site is free and runs entirely in your browser.