Trade Execution Modeling
Overview
Provide more realistic execution assumptions for backtests, including slippage models, market-impact estimation, and execution-algorithm principles. This skill is for backtest simulation only and does not involve live order execution.
Slippage Models
Why Slippage Models Are Needed
Idealized backtest: filled at the close, zero slippage
Real world:
1. The order book has a bid-ask spread
2. Large orders push prices (market impact)
3. Execution is delayed (there is latency from signal to fill)
No slippage model -> overly optimistic backtest -> losses in live trading
Do not retype these models. All four are implemented and tested in
src/quantlib/impact.py; import them. The tested versions validate their inputs —
a zero ADV raises instead of dividing by zero, and a negative delay_bars raises
instead of silently introducing look-ahead bias.
from src.quantlib.impact import fixed_slippage, linear_impact, sqrt_impact, delayed_execution
1. Fixed Slippage Model
fixed_slippage(price=100.0, direction=1, bps=5.0) # 100.05 (buy pays up)
fixed_slippage(price=100.0, direction=-1, bps=5.0) # 99.95…