Transaction Cost Modeling in Backtesting — Avoiding Hidden Profit Erosion

Transaction cost modeling is one of the most underestimated aspects of backtesting. This guide details how to accurately model costs to avoid profit erosion.

Algo Lab Quant TeamPublished on 2026-08-11 17:15

Transaction Cost Modeling in Backtesting Complete Guide

Transaction costs are one of the most overlooked and destructive factors in quantitative backtesting. A strategy that looks great in backtests ignoring costs may be completely unprofitable when real costs are included.

Understanding and properly modeling transaction costs is an essential skill for every quantitative strategy developer.

Four Components of Transaction Costs

1. Commission

Commission is the trading fee paid to your broker:

  • Fixed commission: Flat fee per trade (e.g., $1/trade)
  • Percentage commission: Based on trade amount (e.g., 0.03%)
  • Tiered commission: Segment-based pricing by trade size

Real-World Reference:

Broker TypeUS CommissionHK Commission
Online broker$0-1/trade0.003% + $1.5 min
Traditional broker$1-10/trade0.03%
Institutional$0.001/share0.002%

2. Slippage

Slippage is the difference between expected and actual execution price:

  • Positive slippage: Execution better than expected (rare)
  • Negative slippage: Execution worse than expected (common)

Slippage Determinants:

FactorDirectionDescription
Order SizeLarger = more slippageLarge orders cannot execute without moving price
LiquidityLower = more slippageIlliquid stocks have wider slippage
Market VolatilityHigher = more slippagePrices move faster during volatile periods
Execution SpeedFaster = more slippageUrgent orders often require worse prices

Estimation Method:

Estimated Slippage = Avg Spread × (Order Size / Avg Daily Volume) × Amplification Factor

Amplification Factor: typically 1.5-3.0, accounting for market volatility

3. Bid-Ask Spread

The bid-ask spread is the difference between the ask (buy) price and the bid (sell) price:

  • Hidden cost: Even without slippage, you immediately lose a spread on entry
  • Dynamic: Spreads widen during volatile markets

Real Impact:

Entry Cost: Ask Price
Exit Proceeds: Bid Price
Implicit cost per round-trip: Ask - Bid = Spread

4. Taxes

Taxes vary by market and trade type:

  • Capital gains tax: US short-term up to 37%, long-term up to 20%
  • Stamp duty: Some markets charge (e.g., Hong Kong 0.13%)
  • Exchange fees: Fees charged by exchanges and regulators

Complete Transaction Cost Model

Model Formula

Total Cost per Trade = Commission + Slippage + Spread + Taxes

Where:
- Commission = Trade Amount × Commission Rate
- Slippage = Order Size × Estimated Slippage Price
- Spread = Bid-Ask Spread (in dollar terms)
- Taxes = Gain Amount × Tax Rate (only on profitable trades)

Real-World Example

Assuming you buy 1,000 shares of Company A at $100:

Cost ItemCalculationAmount
Commission1,000 × $0.005$5
Slippage1,000 × $0.02 (0.02% slippage)$20
Spread1,000 × $0.01 ($0.01 spread)$10
Total Entry$100,035

Selling 1,000 shares at $110:

Cost ItemCalculationAmount
Commission1,000 × $0.005$5
Slippage1,000 × $0.02$20
Spread1,000 × $0.01$10
Taxes($110,000 - $100,000) × 15% (long-term)$1,500
Net Proceeds$110,000 - $5 - $20 - $10 - $1,500$108,465

Actual Profit: $108,465 - $100,035 = $8,430 Profit Ignoring Costs: $110,000 - $100,000 = $10,000 Cost Erosion: $10,000 - $8,430 = $1,570 (15.7%)

Cost Sensitivity by Strategy Type

High-Frequency (Intraday)

  • Frequency: Multiple trades per day
  • Cost Sensitivity: Very high
  • Key Costs: Commission + Slippage
  • Impact: Costs can represent 50-80% of total profit

Medium-Frequency (Weekly)

  • Frequency: 1-3 trades per week
  • Cost Sensitivity: Moderate
  • Key Costs: Slippage + Spread
  • Impact: Costs can represent 15-30% of total profit

Low-Frequency (Monthly)

  • Frequency: 1-2 trades per month
  • Cost Sensitivity: Lower
  • Key Costs: Taxes (cumulative)
  • Impact: Costs can represent 5-15% of total profit

Common Transaction Cost Modeling Errors

Error 1: Using Fixed Costs

Assuming every trade costs a flat $5, ignoring order size and liquidity.

Correct approach: Calculate costs dynamically based on trade amount and order size.

Error 2: Ignoring Taxes

Many backtests completely ignore taxes or assume a uniform rate.

Correct approach: Distinguish short-term and long-term capital gains tax based on holding period and jurisdiction.

Error 3: Narrow Slippage Estimation

Using only historical average spreads, ignoring liquidity changes.

Correct approach: Use dynamic slippage models considering order size, liquidity, and market volatility.

Transaction Cost Modeling at Algo Lab

Every Algo Lab strategy uses a complete transaction cost model:

  1. Commission: $0.005/share, minimum $1
  2. Slippage: Tiered by liquidity (large-cap 0.01%, mid-cap 0.03%, small-cap 0.05%)
  3. Spread: 1.5× historical average spread
  4. Taxes: Short-term 37%, long-term 15%
  5. Liquidity Filter: Only trade stocks with daily volume > 100,000 shares

Conclusion: Costs are the Silent Enemy of Strategies

Transaction costs are like termites — individually seemingly insignificant, but cumulative long-term erosion can severely damage strategy structure. Only rigorous transaction cost modeling reveals a strategy's true potential.

Every Algo Lab strategy undergoes complete transaction cost modeling validation, ensuring you face strategies that remain effective after all costs are deducted.

Learn about Algo Lab's strategy validation | Explore AI stock picking guide | [Join VIP for daily quantitative signals]

Frequently Asked Questions

How much impact do transaction costs have on backtest results?

For high-frequency strategies, transaction costs can erode 50%+ of profits. For medium-to-low frequency strategies, the impact is typically 10-30%. Even for low-frequency strategies, ignoring costs can turn a profitable strategy into a losing one.

How should transaction costs be estimated in backtesting?

A complete transaction cost model should include: (1) Commission: based on actual broker rates; (2) Slippage: estimated based on stock liquidity and order size; (3) Bid-ask spread: using historical spread data; (4) Taxes: based on trade type and jurisdiction. Total cost = Commission + Slippage + Spread + Taxes.

If my strategy trades infrequently, do I need detailed cost modeling?

Even for low-frequency strategies, basic transaction cost modeling is needed. For a strategy trading 1-2 times per month, cost per trade is typically 0.1-0.3%. While smaller than for high-frequency strategies, cumulative effects significantly impact total returns.

#Transaction Cost#交易成本#backtesting model#回測模型#slippage#滑價#quantitative backtesting#量化回測

Want daily high-probability signals?

Subscribe to VIP for daily TOP 20 signals — pattern recognition + AI stock selection to help you make informed decisions.

Related Reading

Related Questions