Transaction Costs & Market Impact: Models & Analysis › Practical Implementation: Complete Cost Model

Michael BrenndoerferJanuary 8, 20263 min read
Quantitative FinanceAll chapters
Part 14 of 15Strategy Development and Backtesting
Chapter 74Transaction Costs & Market Impact: Models & Analysis › Practical Implementation: Complete Cost Model
Reading section 10 of 16 · Practical Implementation: Complete Cost Model · 3 minSection 10 of 16 · 3 min

Book contents

Section 10 of 16 · 3 min read

Transaction Costs & Market Impact: Models & Analysis › Practical Implementation: Complete Cost ModelOne section · Sections in this chapter10 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Let's now build a transaction cost model that combines all the elements we've discussed: explicit costs, spread costs, and market impact.

In[29]:
Code
class TransactionCostModel:
    """
    Comprehensive transaction cost model combining explicit costs,
    bid-ask spread, and market impact.
    """

    def __init__(
        self,
        commission_per_share=0.005,
        exchange_fee_rate=0.0003,
        spread_bps=5,
        impact_eta=0.1,
        impact_gamma=0.5,
        daily_volume=1_000_000,
        daily_volatility=0.02,
    ):
        """
        Initialize the cost model with market-specific parameters.
        """
        self.commission_per_share = commission_per_share
        self.exchange_fee_rate = exchange_fee_rate
        self.spread_bps = spread_bps
        self.impact_eta = impact_eta
        self.impact_gamma = impact_gamma
        self.daily_volume = daily_volume
        self.daily_volatility = daily_volatility

    def explicit_costs(self, shares, price):
        """Calculate explicit trading costs."""
        trade_value = shares * price
        commission = shares * self.commission_per_share
        exchange_fee = trade_value * self.exchange_fee_rate
        return commission + exchange_fee

    def spread_cost(self, shares, price):
        """Calculate bid-ask spread cost (half spread for single trade)."""
        trade_value = shares * price
        return trade_value * (self.spread_bps / 10000) / 2

    def market_impact(self, shares, price):
        """Calculate market impact using square-root model."""
        participation_rate = shares / self.daily_volume
        impact_pct = (
            self.daily_volatility
            * self.impact_eta
            * (participation_rate**self.impact_gamma)
        )
        return shares * price * impact_pct

    def total_cost(self, shares, price):
        """Calculate total transaction cost for a trade."""
        explicit = self.explicit_costs(shares, price)
        spread = self.spread_cost(shares, price)
        impact = self.market_impact(shares, price)

        return {
            "explicit": explicit,
            "spread": spread,
            "impact": impact,
            "total": explicit + spread + impact,
        }

    def cost_summary(self, shares, price):
        """Return cost breakdown as percentage of trade value."""
        costs = self.total_cost(shares, price)
        trade_value = shares * price

        return {
            "trade_value": trade_value,
            "explicit_bps": costs["explicit"] / trade_value * 10000,
            "spread_bps": costs["spread"] / trade_value * 10000,
            "impact_bps": costs["impact"] / trade_value * 10000,
            "total_bps": costs["total"] / trade_value * 10000,
        }


# Create cost models for different market conditions
liquid_large_cap = TransactionCostModel(
    commission_per_share=0.003,
    spread_bps=2,
    impact_eta=0.05,
    daily_volume=10_000_000,
    daily_volatility=0.015,
)

mid_cap = TransactionCostModel(
    commission_per_share=0.005,
    spread_bps=10,
    impact_eta=0.10,
    daily_volume=500_000,
    daily_volatility=0.025,
)

small_cap = TransactionCostModel(
    commission_per_share=0.008,
    spread_bps=30,
    impact_eta=0.20,
    daily_volume=50_000,
    daily_volatility=0.035,
)

# Analyze costs for different trade sizes
price = 50.0
trade_sizes = [1000, 10000, 50000, 100000]

cost_comparison = []
for model, name in [
    (liquid_large_cap, "Large Cap"),
    (mid_cap, "Mid Cap"),
    (small_cap, "Small Cap"),
]:
    for size in trade_sizes:
        summary = model.cost_summary(size, price)
        summary["market"] = name
        summary["shares"] = size
        cost_comparison.append(summary)

cost_df = pd.DataFrame(cost_comparison)
Out[30]:
Console
Transaction Cost Comparison Across Market Segments:
=====================================================================================

Large Cap:
-------------------------------------------------------------------------------------
    Shares     Trade Value   Explicit     Spread     Impact      Total
-------------------------------------------------------------------------------------
     1,000 $        50,000       3.6       1.0       0.1       4.7
    10,000 $       500,000       3.6       1.0       0.2       4.8
    50,000 $     2,500,000       3.6       1.0       0.5       5.1
   100,000 $     5,000,000       3.6       1.0       0.8       5.3

Mid Cap:
-------------------------------------------------------------------------------------
    Shares     Trade Value   Explicit     Spread     Impact      Total
-------------------------------------------------------------------------------------
     1,000 $        50,000       4.0       5.0       1.1      10.1
    10,000 $       500,000       4.0       5.0       3.5      12.5
    50,000 $     2,500,000       4.0       5.0       7.9      16.9
   100,000 $     5,000,000       4.0       5.0      11.2      20.2

Small Cap:
-------------------------------------------------------------------------------------
    Shares     Trade Value   Explicit     Spread     Impact      Total
-------------------------------------------------------------------------------------
     1,000 $        50,000       4.6      15.0       9.9      29.5
    10,000 $       500,000       4.6      15.0      31.3      50.9
    50,000 $     2,500,000       4.6      15.0      70.0      89.6
   100,000 $     5,000,000       4.6      15.0      99.0     118.6

The analysis reveals the dramatic differences in trading costs across market segments. For a 100,000-share trade, large-cap stocks incur about 6 basis points total cost, while small-caps cost over 100 basis points, a seventeen-fold difference. Market impact dominates the cost structure for larger trades in less liquid markets.