Trade Execution Matters
The best predictions are worthless if you can't execute trades efficiently. Poor execution can erode all profits through slippage, delays, and market impact.
Execution Algorithms
VWAP (Volume-Weighted Average Price)
Execute order to match the volume-weighted average price over a time period
- Breaks large order into smaller chunks
- Matches historical intraday volume pattern
- Minimizes market impact
- Benchmark: Did we beat VWAP?
def vwap_schedule(total_shares, historical_volume_profile, num_periods):
"""Generate VWAP execution schedule"""
# Historical volume profile (% of daily volume each period)
# E.g., [0.05, 0.08, 0.12, ...] for each 30-min period
schedule = []
for period, vol_pct in enumerate(historical_volume_profile[:num_periods]):
shares_to_trade = int(total_shares * vol_pct)
schedule.append({
'period': period,
'shares': shares_to_trade,
'participation_rate': 0.10 # Trade 10% of market volume
})
return schedule
TWAP (Time-Weighted Average Price)
Execute equal amounts over regular time intervals
- Simpler than VWAP, equal slices
- Used when volume pattern unknown
- Lower market impact than single large order
Implementation Shortfall
Minimize difference between decision price and execution price
- Trades aggressively early to capture alpha
- Balances market impact vs. opportunity cost
- Optimal for time-sensitive signals
POV (Percentage of Volume)
Trade fixed percentage of market volume
- E.g., trade 10% of all market volume
- Adapts to market liquidity
- Completion time depends on market activity
Smart Order Routing (SOR)
Automatically route orders to best execution venue
Execution Venues
- Lit Exchanges: NYSE, NASDAQ, etc. (visible orders)
- Dark Pools: Hidden liquidity, no market impact
- ECNs: Electronic communication networks
- Alternative Trading Systems (ATS)
SOR Logic
- Compare prices across all venues
- Account for fees and rebates
- Consider fill probability and speed
- Route to best net price
Market Microstructure
Order Types
- Market Order: Execute immediately at best available price
- Limit Order: Execute only at specified price or better
- Stop Order: Becomes market order when price reached
- Stop-Limit: Becomes limit order when stop triggered
- IOC (Immediate or Cancel): Fill immediately or cancel
- FOK (Fill or Kill): Fill entire order or cancel
- Iceberg: Show only small portion of large order
Transaction Cost Analysis (TCA)
def calculate_tca(execution_price, benchmark_price, shares, side):
"""Calculate transaction cost metrics"""
# Slippage
if side == 'buy':
slippage = (execution_price - benchmark_price) / benchmark_price
else: # sell
slippage = (benchmark_price - execution_price) / benchmark_price
# Cost in basis points
cost_bps = slippage * 10000
# Dollar cost
dollar_cost = abs(execution_price - benchmark_price) * shares
return {
'slippage_pct': slippage,
'cost_bps': cost_bps,
'dollar_cost': dollar_cost
}
Technology Stack
Data Storage
- Time Series DB: TimescaleDB, InfluxDB, QuestDB
- Historical Data: HDF5, Parquet, Arctic
- Real-Time: Redis, Apache Kafka
Compute Infrastructure
- On-Premise: Full control, high cost
- Cloud: AWS, GCP, Azure (flexible, scalable)
- Hybrid: Research in cloud, trading on-premise
Development Stack
# Python Stack for Algo Trading
Data: pandas, numpy, polars
ML: scikit-learn, PyTorch, TensorFlow
Backtesting: Backtrader, Zipline, VectorBT
Execution: ccxt (crypto), ib_insync (IB), alpaca-py
Visualization: matplotlib, plotly, dash
Infrastructure: Docker, Kubernetes, Airflow
Production Deployment
Deployment Checklist
- ✓ Strategy validated on out-of-sample data
- ✓ Risk limits configured and tested
- ✓ Paper trading results acceptable
- ✓ Execution infrastructure tested
- ✓ Monitoring and alerting configured
- ✓ Disaster recovery plan in place
- ✓ Capital allocated appropriately
Monitoring
- Real-time P&L tracking
- Position monitoring
- Order execution quality (TCA)
- System health (latency, errors, uptime)
- Market data feed status
- Model performance degradation detection
Best Practice: Start small in live trading. Allocate 10-20% of intended capital initially, then scale up as confidence builds.