Skip to main content
Backtesting

Commission and Fees in a Backtest

Pomegra Learn

How Do Backtest Fees and Commission Impact Strategy Returns?

When you run a backtest, the numbers on your screen often look spectacular. A 40% annual return, a 2.5 Sharpe ratio, barely any drawdown. Then you trade the strategy live and discover it barely covers your broker fees. The gap between backtest performance and reality is often fees—especially commissions—that were never modeled in the first place. Backtest fees and commission costs are not optional details; they are the difference between a profitable strategy and a money-losing one. Without accurate fee modeling, your backtest is fiction.

Quick definition: Backtest fees are the transaction costs—commissions, spreads, borrowing costs—you add to a simulated trading strategy to estimate what real trading will cost.

Key takeaways

  • Fees destroy edge. A 1% annual return disappears entirely if you pay 0.5% in commissions and 0.25% in bid-ask spreads over 20 trades per year.
  • Commission structure varies by asset class. Stocks have fixed-fee brokers or percentage-based commissions; futures have round-turn fees; crypto exchanges charge maker and taker rates that swing wildly.
  • Backtests without fees are optimistic fantasies. A test that ignores commissions will overstate returns by 10–40%, depending on trade frequency and position size.
  • Fee drag compounds over time. Small fees per trade add up quickly in high-turnover strategies, eating into net returns.
  • Accurate fee modeling separates real strategies from curve-fit garbage. Include all costs: commissions, spreads, exchange fees, and borrowing costs for shorts.

What fees should you include in a backtest?

Every backtest fee breaks down into specific categories. Not all fees apply to every strategy, but ignoring the ones that do is a critical mistake.

Commissions are the most obvious. If your broker charges $5 per trade on stocks, that's $10 per round-trip (entry and exit). On a $20,000 position, that's 0.05% of capital per trade. Over 100 trades in a year, that's 5% of your starting capital—or 50% of a 10% expected return. Many modern brokers offer zero commissions on stocks, but not all do, and other asset classes (futures, options, forex) still charge per trade.

Bid-ask spreads are the cost of instant execution. When you buy a stock, you pay the ask price. When you sell, you get the bid price. The gap between them is the spread, and it's gone the moment you trade. On large-cap stocks, spreads might be $0.01 (0.01% of a $100 stock). On mid-caps or illiquid securities, spreads can be $0.50 or more. For a trader entering and exiting 50 times per year, spreads can cost 1–3% annually.

Exchange fees exist on most regulated markets. A stock exchange might charge $0.0005 per share for execution. Futures exchanges charge a flat fee per contract round-turn. Crypto exchanges charge 0.1–0.5% per trade on both maker and taker orders. These fees are smaller than commissions but add up fast.

Borrowing costs for short positions apply if you short a stock or use leverage. Short borrowing fees range from 0.1% per year on easy-to-borrow stocks to 50%+ per year on hard-to-borrow names. If 10% of your capital is consistently short, and borrowing costs 10% per year, that's 0.1% annual drag on your portfolio.

Slippage beyond bid-ask spread occurs when your order impacts the market or fails to fill at expected prices during volatile moments. In a backtest, you can model slippage as a fixed percentage (e.g., 0.02% per trade) or as a volatility-based cost that increases on high-volume bars.

How much should you assume for each fee?

Use realistic numbers based on your actual trading setup, not best-case fantasy.

For stock strategies with zero-commission brokers: Assume 0.03–0.05% bid-ask spread on each trade. Add 0.0003% exchange fees. Total per round-trip: 0.06–0.1%. If you trade 20 times per year, that's 1.2–2% annual drag.

For futures: Assume $5–$15 per contract round-turn depending on the contract (ES costs less per dollar traded than ZC). On a $50,000 account with a typical 2-contract position, that's 0.02–0.06% per round-trip. Over 50 trades per year, expect 1–3% annual fee drag.

For options: Commission is often $0.50–$1 per contract, plus bid-ask spreads of 0.05–0.2%. For a 30-day options trader, this can consume 3–5% of returns.

For crypto: Assume maker fees of 0.1% and taker fees of 0.15–0.25% per trade. A trader executing 100 round-trips per year on a $10,000 account eats 2–5% annually.

For stocks, start with real numbers from your broker. For futures and crypto, check the fee schedule on your exchange's website or trading platform.

Building a fee schedule into your backtest code

Your backtest engine needs to deduct fees on every trade. Most production backtesting platforms (Backtrader, Zipline, VectorBT) have built-in fee handlers. Set them to match your reality.

In Backtrader, you specify commission per trade:

cerebro.broker.setcommission(commission=0.001)  # 0.1% per trade

In VectorBT, you pass a fee dictionary:

pf = vbt.Portfolio.from_signals(
close,
entries, exits,
init_cash=10000,
fees=0.001 # 0.1% per entry/exit
)

Manual calculation is straightforward: new_balance = balance - (position_size * entry_price * fee_rate) at entry, and subtract fees again at exit.

The critical step is testing the backtest with fees and without fees side by side. If fees cut your return from 15% to 8%, that's acceptable. If fees cut it from 15% to 2%, your strategy doesn't have enough edge to trade.

Real-world example: How fees kill a promising backtest

Imagine a mean-reversion stock strategy that trades the S&P 500. Backtest results:

  • Annual return: 18%
  • Sharpe ratio: 1.8
  • Max drawdown: 12%
  • Number of trades per year: 120

Looks great. Now model fees:

  • Entry commission: $5 per trade
  • Exit commission: $5 per trade
  • Bid-ask spread: 0.02% per trade
  • Average position size: $15,000

Per round-trip cost: $10 + ($15,000 × 0.0002 × 2) = $10 + $6 = $16. Over 120 trades, that's $1,920 per year in a $100,000 account, or 1.92% annual drag.

New results:

  • Annual return: 16.08% (down from 18%)
  • Sharpe ratio: 1.7 (still acceptable)
  • The strategy still works

But if the strategy had 200 trades per year instead:

  • Annual fee cost: $3,200 (3.2% of capital)
  • New return: 14.8%
  • Sharpe ratio: 1.5

The strategy is still profitable, but the margin for error shrinks. Add slippage during fast markets, and edge vanishes. This is why high-frequency strategies need either huge capital or near-zero fees to survive. It's also why professional traders often eliminate low-edge trades and focus on the highest-probability setups—fewer trades, lower fees, more profit.

Decision tree

Common mistakes

Forgetting to include bid-ask spreads. Commission is obvious, but spreads are invisible to programmers used to zero-commission brokers. Spreads often exceed stated commissions, especially on smaller-cap stocks or illiquid instruments.

Using "best case" spreads in the backtest. The average spread on a liquid stock is 0.02%, but during market panic or illiquidity spikes, spreads widen to 0.1% or more. A robust backtest models spreads that vary by market condition or assumes the worst case.

Ignoring slippage beyond spread. If a $1 million market order hits an illiquid stock with only $500K of volume at the best ask, you move the market. Backtests that assume you fill at the published price are unrealistic. Add 0.05–0.1% slippage to account for market impact.

Forgetting short-borrowing costs. Many backtests include long positions with accurate fees but never model the cost of short positions. If 20% of your strategy is consistently short, short-borrowing costs can be 0.5–2% per year—a material drag.

Comparing apples and oranges. If you backtest with fees but then compare against a buy-and-hold that ignores fees, you've rigged the game against yourself. Always test both strategies with the same fee assumptions.

FAQ

What if my broker offers zero commissions on stocks?

You still pay bid-ask spreads. Model 0.03–0.05% per trade depending on stock liquidity. Check your actual fills against quoted prices to find your real spread cost.

Should I include slippage in my backtest?

Yes, especially for strategies with large positions or high turnover. Start with 0.02% per trade and increase it if you're trading illiquid securities or market-moving sizes.

How do I know if my fee assumptions are realistic?

Paper trade for a month without real money. Compare your actual entry and exit prices to the backtest prices. If you're worse than the backtest assumes, increase fee assumptions.

What if I reduce trade frequency to lower fees?

Lower frequency reduces fee drag but also reduces opportunities and may hurt returns if you're filtering out lower-confidence trades. Instead, focus on edge: if your best trades have a 3% edge and marginal trades have 0.5% edge, drop the marginal ones regardless of fee impact.

Does a strategy with 18% return minus 2% in fees still beat the market?

Probably yes—the S&P 500 has returned ~10% annually over 100 years. But 16% is less than 18%, so you're worse off. The real question is whether your strategy's 16% after-fee return justifies the risk and the time spent vs. indexing.

Should I model different fees for entries vs. exits?

Only if your broker charges different rates. Most brokers charge the same fee per trade. If using a market maker or venue that charges different rates for buys, sells, and short entries, model each separately.

Summary

Backtest fees are not optional—they are the bridge between backtest fantasy and trading reality. Commission, spreads, exchange fees, and borrowing costs together can consume 1–5% of your annual return, depending on trade frequency and asset class. A strategy that returns 18% before fees but only 10% after fees is not as impressive as it first appears. Always include realistic fees in your backtest, always compare results with fees and without fees, and always remember that the strategy that survives fee modeling is the one worth trading. Ignoring fees is the fastest way to ruin a trading strategy that looked great on a spreadsheet.

Next

Walk-Forward Testing for Realistic Results