Quant Analytics: from scratch to pro · Backtesting done right · Intermediate
Costs in a backtest: spread, commission, slippage, funding
Every trade pays the spread, a commission, some slippage and, for leveraged or borrowed positions, a financing charge. A backtest that leaves these out overstates the edge, and the more often a rule trades, the larger the error.
In this lesson
- List the four cost components of a trade and compute a round-trip cost
- Compare a gross edge per trade with the cost per trade
- Show how trading frequency multiplies the cost drag
- Add a financing cost for a position held over several days
Read first: What a backtest is, and what it is not, Spreads and trading costs
A price chart shows a price at which nobody could be sure of trading. A backtest that fills every order at the quoted price, for free, answers a question that does not exist. The gap between that answer and the real one is the cost of trading, and for active rules it is often the whole edge.
The four components
| Component | What it is | Typical form |
|---|---|---|
| Spread | The gap between the price at which you can buy and the price at which you can sell | Paid once per round trip |
| Commission and fees | Charges by the broker, exchange or regulator | Per side, per share or per cent of value |
| Slippage | The difference between the price expected when the order is sent and the price obtained | Per side; grows with size and fast markets |
| Financing | Interest on borrowed money or on a leveraged position held overnight, or a cost to borrow shares to sell short | Per day held |
A round trip is one entry and one exit. The spread is crossed once per round trip in total (a half on each side). Commission and slippage are paid on both sides. Slippage is the hardest to model, because it depends on the order size, the time of day and the market. See spreads and trading costs for how the quotes work.
A fixed cost per trade is a start. A better model makes slippage larger in thin or volatile markets and tests the rule under costs higher than expected.
Worked example
A share trades at 50 with a quoted spread of 0.04, so the spread is 0.04 / 50 = 0.08% of the price. Commission is 0.05% per side, which makes 0.10% per round trip. Slippage is 0.03% per side, 0.06% per round trip.
Round-trip cost = 0.08% + 0.10% + 0.06% = 0.24%
The rule earns 0.35% per trade before costs. After costs it earns 0.35% - 0.24% = 0.11%. Two thirds of the edge goes to costs, and only a third is left.
Frequency multiplies this. With 100 round trips a year, adding the results gives 35% before costs and 11% after. Costs alone, compounded, remove 1 - (1 - 0.0024)^100, which is 21.4% of capital, as the chart shows. A rule that trades ten times a year loses a few per cent to the same costs; one that trades two hundred times loses about 38%. Whether the rule works depends on whether the edge per trade clears the cost per trade, not on the gross figure.
Financing works per day. A 3% annual rate is 3% / 365, or 0.0082% a day. A position held 10 days pays 0.082%. That is small for one trade, but it adds to every day of a leveraged book, and it can be larger for short positions in hard-to-borrow shares.
What to check
- Break-even cost: the cost per trade at which the net edge reaches zero. Here it is the gross edge, 0.35%. A rule that survives only at the assumed cost has no margin for error.
- Cost stress: rerun with costs 1.5 or 2 times higher. A real edge falls but stays positive.
- Turnover: the more a rule trades, the more it depends on cost assumptions. Compare the net edge per trade with the cost per trade.
- Capacity: costs rise with size. A result at a small size is not a result at a large one.
Common mistakes
- Using the closing price as the fill price for a signal computed from that same close.
- Charging the spread once on entry only, or not at all on exits made with stop orders, which can fill beyond the stop price.
- Using today's tight spreads for years in which spreads were wider (decimal prices and electronic markets lowered costs over time).
- Forgetting weekends, holidays and the financing charge on positions held over them.
- Reporting gross results next to net results of a benchmark.
In practice
Put the cost model in one place, state it next to the result, and report the net edge per trade and its break-even cost. Trading on FinUties starts on a demo account, where ideas like this can be practised without real money.
Share of capital lost to a 0.24% round-trip cost, by trades a year
Worked numbers
Each result is recomputed from the formula shown.
| What | Formula | Result |
|---|---|---|
| spread as a share of the price | 0.04 / 50 | 0.08% |
| round-trip commission | 2 * 0.0005 | 0.10% |
| round-trip slippage | 2 * 0.0003 | 0.06% |
| total round-trip cost | spread_pct + comm + slip | 0.24% |
| gross edge per trade | 0.0035 | 0.35% |
| net edge per trade | gross_edge - rt_cost | 0.11% |
| gross edge over 100 trades, added | 100 * gross_edge | 35% |
| net edge over 100 trades, added | 100 * net_edge | 11% |
| compounded cost drag over 100 round trips | 1 - (1 - rt_cost)**100 | 21.4% |
| compounded cost drag over 200 round trips | 1 - (1 - rt_cost)**200 | 38% |
| financing per day at 3% a year | 0.03 / 365 | 0.0082% |
| financing over 10 days | 10 * 0.03 / 365 | 0.082% |
Check yourself
A share is quoted 49.98 bid, 50.02 ask. What is the spread as a share of the price?
The spread is 0.04. Against a price of 50 that is 0.04 / 50 = 0.08%. A buyer who sells straight away loses about this amount.
Commission is 0.05% per side and slippage 0.03% per side. With the 0.08% spread, what is the round-trip cost?
Commission 2 x 0.05% = 0.10%. Slippage 2 x 0.03% = 0.06%. Total 0.08% + 0.10% + 0.06% = 0.24%.
A rule earns 0.35% per trade before costs. What does it earn after the round-trip cost above?
0.35% - 0.24% = 0.11% per trade. Costs took about two thirds of the edge.
A position borrowed at an annual financing rate of 3% is held for 10 days. What is the charge?
3% / 365 per day, times 10, is 0.082% of the position. Use the day-count the broker uses, and charge weekends.
Key terms
Sources
- Trading and Exchanges: Market Microstructure for Practitioners. Oxford University Press (Larry Harris), 2003. Accessed 9 Nov 2026
- Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society 61(5), 458-471 (Bailey, Borwein, López de Prado, Zhu), 2014. Accessed 9 Nov 2026