Slippage and Commission
How QuantJourney applies transaction costs in weight mode and order mode.
Costs exist in both execution paths, but the mechanics differ.
Source
backtester/execution/slippage.py + backtester/execution/commission.py + backtester/core.pyLayerCost model
ModeWeights and orders
Inputturnover in weight mode; fills in order mode
Outputnet returns, fill prices, commission and blotter costs
Primary API
slippage_model=..., commission_scheme=...Main caveatWeight-mode costs are turnover-based; order-mode costs are per fill.
Engine Contract
Weight mode models costs at the portfolio turnover level. Order mode models costs at the fill level after the theoretical price is selected.
WEIGHT MODE
actual weight change on rebalance day -> turnover -> bps cost -> net return
ORDER MODE
theoretical fill price -> slippage model -> commission model -> fill record
Level 1: Order Mode With Slippage And Commission
Configure order-mode costs
python
from backtester.execution import FixedBpsSlippage, PerShareCommission
strategy = MyOrderStrategy(
...,
execution_mode="orders",
slippage_model=FixedBpsSlippage(bps=5.0),
commission_scheme=PerShareCommission(
cost_per_share=0.005,
min_per_order=1.0,
),
)Level 2: Use Market Impact For Larger Orders
Market-impact slippage
python
from backtester.execution import MarketImpactSlippage, FixedBpsCommission
strategy = MyOrderStrategy(
...,
execution_mode="orders",
slippage_model=MarketImpactSlippage(
sigma_daily=0.02,
adv=1_000_000,
eta=0.10,
),
commission_scheme=FixedBpsCommission(bps=1.0),
)Level 3: Weight Mode Cost Interpretation
In weight mode, transaction cost is charged on rebalance-day turnover. It is not a fill-by-fill simulation.
text
turnover = abs(actual_weights.diff()).sum(axis=1)
transaction_cost_pct = turnover * TRANSACTION_COST_BPS
net_returns = portfolio_returns - transaction_cost_pctFailure Modes
- Comparing weight-mode cost output to order-mode fill cost without accounting for different mechanics.
- Setting zero costs while testing high-turnover systems.
- Treating limit orders as free execution.
- Forgetting that slippage is applied after the theoretical bar price.
- Ignoring minimum ticket commission for small orders.
Audit Checklist
- In weight mode, inspect turnover and rebalance flags.
- In order mode, inspect each fill's price, slippage and commission.
- Compare gross and net returns.
- Stress test bps assumptions.
- For illiquid assets, prefer conservative slippage or market-impact assumptions.