Backtest transaction costs: commissions, spread and slippage
A small cost per trade can turn a winning backtest into a losing one. See how commissions, spread and slippage work, with a worked example and calculator.
Part of the Backtesting and Research track on Agenticks. About 12 minutes, written for a advanced reader.
Read first: What is backtesting, Reading results 2: expectancy and profit factor.
Last reviewed .
Risk notice. Backtested and hypothetical results are simulated: no trades were placed, the rules were applied to past data with the benefit of hindsight, and they may not reflect liquidity, slippage or every cost. Past results, real or simulated, do not predict future results.
Key takeaways
- Every round trip pays twice: commission and slippage on the entry, again on the exit, plus the spread you cross.
- Costs come off every single trade, so they matter most when the edge per trade is small and trades are frequent.
- In the worked example, a $12 round-trip cost turned a +$10 expectancy into -$2 and raised the break-even win rate from 50% to 56%.
- Read a result at realistic and at harsher cost settings. A result that only survives at zero cost is not a result.
A backtest that ignores costs is quietly assuming something that never happens: that every trade is free and fills at exactly the price on the chart. Real trading is never like that. Every order pays a fee, crosses a spread, and sometimes fills at a worse price than the one you saw. Those amounts look tiny next to a single trade, a few dollars here, a fraction of a point there. The trouble is that they are charged on every trade, while the edge a strategy has is usually small too. When both numbers are small, the costs can be the difference between a rule that makes money and one that loses it. This lesson shows how, with real arithmetic.
Every trade pays a toll
Think of costs as a toll booth on both ends of the road: one on the way in, one on the way out. The toll does not care whether the trip was profitable. It is paid on the winners and on the losers alike.
Trading costs come in three main kinds, together called transaction costs. Commission and fees. What the broker and exchange charge for each fill. It might be a fixed amount per order, per share or per futures contract. "Per side" means per fill, so a round trip, one entry plus one exit, pays it twice. More on how fees are charged is in fees and costs. The spread. At any moment there is a best price someone will pay (the bid) and a best price someone will sell at (the ask). A market buy pays the ask and a market sell gets the bid, so a round trip at market gives up roughly the whole gap between them. In very liquid markets the spread is tiny. In thin ones, or outside normal hours, it can be wide. Slippage. The difference between the price you expected and the price you actually got. It grows in fast markets, in thin markets, around news, and with larger orders. Stop orders are especially prone to it, because a triggered stop becomes a market order at the very moment price is moving against you. The slippage lesson covers why it happens in more detail.
Worked example: a $12 toll on a $10 edge
A rule wins 55% of its trades, with an average win of $100 and an average loss of $100 before costs. Each round trip costs $5 in commission and about $7 in spread and slippage.
| Expectancy before costs (0.55 x 100 - 0.45 x 100) | +$10 per trade |
|---|---|
| Cost per round trip ($5 commission + $7 spread and slippage) | $12 |
| Average win after costs (100 - 12) | $88 |
| Average loss after costs (100 + 12) | $112 |
| Expectancy after costs (0.55 x 88 - 0.45 x 112 = 48.40 - 50.40) | -$2 per trade |
| Over 500 trades (500 x 10 vs 500 x -2) | +$5,000 becomes -$1,000 |
| Break-even win rate (112 / (88 + 112)) | 50% before costs, 56% after |
| Same rule, costs included | From +$10 to -$2 a trade |
Illustrative numbers, not a real strategy or a quote of any broker's fees.
Try it: expectancy after costs
These defaults are the after-cost numbers from the worked example. Set the average win and loss back to 100 to see the before-cost result, or subtract your own cost per round trip from the win and add it to the loss.
Notice what the example did not need: a big cost. Twelve dollars is small next to a $100 average win. It was decisive because the edge was only $10 a trade. The ratio of cost to edge is what matters, not the cost on its own. That is why frequent trading feels costs most. A strategy that holds for months pays the toll a few times a year against large moves. A strategy that trades many times a day pays it constantly against small moves. Research on academic trading strategies found that costs reduced the profits of every strategy studied, and that few of the strategies that turned over more than half their positions each month still showed statistically reliable profits once costs were counted. A long-running study of individual investors found something similar: the households that traded most earned clearly lower returns than those that traded least. A useful habit is to read expectancy next to the cost of a round trip. When the cost of a round trip is close to the expectancy before costs, a small rise in slippage can wipe the edge out.
There is another way to see the damage: the break-even win rate, the share of trades a rule must win just to cover its losses. With equal $100 wins and losses and no costs, it is exactly 50%. Add a $12 round trip and the wins shrink to $88 while the losses grow to $112, so the rule now has to win 112 out of every 200 dollars at stake, which is 56% of its trades. Six percentage points sounds modest. For a rule whose real win rate is 55%, it is the whole story, because 55% now sits below the line it has to clear. This is why a strategy's win rate and its costs cannot be judged separately. A high win rate with tiny wins, the shape of many scalping systems, is the most sensitive of all: each win is small, so a fixed cost takes a large bite out of it, and the break-even line climbs quickly.
- Commission
- A fee charged on each fill by the broker or exchange
- Spread
- The gap between bid and ask that a market order crosses
- Slippage
- A fill worse than the price you saw when the order went in
- Round trip
- One entry plus one exit, so per-side costs are paid twice
Modelling costs honestly is mostly about not being optimistic. Charge costs on every fill, entries and exits, winners and losers. Match the units. Futures commissions are usually per contract per side; stock commissions may be per share or per order; slippage in futures is often counted in ticks. Mixing per side with per round trip is the most common mistake. Assume more slippage where it really happens: at the open, around scheduled news, on stops, and in thinly traded instruments. Remember missed trades. Limit orders save the spread but do not always fill. A backtest that fills every limit order the moment price touches it is quietly assuming the best case. Stress the result. Run the test again with costs doubled. A result that keeps most of its edge is sturdier than one that flips negative. Then read it alongside a check for look-ahead bias, because a fill at the wrong time and a fill at the wrong price inflate results in the same way.
A strategy's average trade earns $6 before costs. A realistic round trip in that market costs $9. What is the honest conclusion? As tested, the rule loses about $3 a trade once costs are counted 6 - 9 = -3. The edge is smaller than the toll, so every trade loses money on average.
commission spread slippage
You can read a result after its costs
You know the three kinds of trading cost, why they are paid twice on every round trip, and how a small toll can turn a thin positive expectancy into a losing one.
Check your understanding
- A rule's expectancy before costs is +$15 per trade and a round trip costs $9. What is the expectancy after costs?
- +$6 per trade. The cost comes off every trade, win or lose: 15 - 9 = +$6. Thinner, but still positive.
- Why does slippage tend to be larger on a stop order than on a limit order?
- A triggered stop becomes a market order and takes whatever price is available, often in a fast move. Right. Stops usually trigger when price is moving against you, which is exactly when the next available price can be well past your level.
- Which strategy is most exposed to a rise in trading costs?
- One that trades 20 times a day for a small average gain per trade. Costs are charged per trade. Many trades with a thin edge each means costs can eat most or all of it.
Common questions
- What transaction costs should a backtest include?
- At least three: the commission and fees charged on each fill, the bid-ask spread you cross when you trade at market, and slippage, the gap between the price you expected and the price you got. Each is paid on the entry and again on the exit.
- How can a small cost make a profitable strategy lose money?
- Costs come off every trade. If a rule makes $10 on an average trade and each round trip costs $12, the average trade now loses $2. Strategies that trade often with a thin edge per trade are the most exposed.
- How much slippage should I assume in a backtest?
- It depends on the market, the time of day and your order size. A sensible habit is to test with a realistic figure for the instrument and then again with a harsher one. If the result only survives at the most optimistic setting, it is fragile.
Terms defined in this lesson
Continue
- Previous: Survivorship bias: why testing only the winners lies
- Next: Out-of-sample testing and walk-forward analysis
- Reading results 2: expectancy and profit factor
- Fees, commissions, and the real cost of trading
- Slippage and why fills differ from the price you saw
- Look-ahead bias: when a backtest sees the future
- Backtesting and Research track
- All Agenticks lessons
- Trading glossary
Sources
- U.S. Securities and Exchange Commission. (n.d.). How stock markets work. Investor.gov.
- Investopedia. (n.d.). Bid-ask spread. Investopedia.
- Investopedia. (n.d.). Slippage. Investopedia.
- Novy-Marx, R., & Velikov, M. (2016). A taxonomy of anomalies and their trading costs. The Review of Financial Studies, 29(1), 104-147.
- Barber, B. M., & Odean, T. (2000). Trading is hazardous to your wealth: The common stock investment performance of individual investors. The Journal of Finance, 55(2), 773-806.
Written and reviewed by the Agenticks Learn editorial team. How we write and check lessons.
Agenticks Learn is general education. It is not financial, investment, tax or legal advice, it does not take your situation into account, and nothing on it is a recommendation to buy, sell or hold any security or to open any account. Examples use illustrative numbers. Investing involves risk, including losing money you put in, and past performance does not predict future results. Tax rules and limits change; the official sources linked in each lesson are the final word.