Implementation of the Almgren-Chriss optimal execution model — the framework real trading desks use to decide how to execute a large order (e.g. sell 100,000 shares) without either (a) dumping it all at once and crashing the price against yourself, or (b) trading so slowly that you're exposed to days of price risk before the order is filled.
This is execution-algorithm work, not alpha-generation: it doesn't try to predict where the market goes, it solves the cost-minimization problem of how to trade a position you've already decided to trade. This is what sits underneath TWAP/VWAP/IS algos on real trading desks and in broker execution products.
Trading faster increases market impact cost (you're consuming more liquidity per unit time, pushing the price against you) but reduces timing risk (less time exposed to adverse price moves while you're still holding the position). Almgren-Chriss finds the trade trajectory that optimally balances these two, given a risk-aversion parameter (lambda) representing how much the trader/desk cares about variance vs. expected cost.
- Low risk aversion → trade slowly, close to TWAP (linear) — minimizes expected cost, accepts more variance
- High risk aversion → trade fast, front-loaded — minimizes variance (gets the position off quickly), accepts higher expected impact cost
almgren_chriss.py— implements the closed-form Almgren-Chriss optimal trajectory (hyperbolic-sine solution), plus naive baseline schedules (TWAP, immediate execution) for comparison.execution_simulator.py— simulates executing each schedule against hundreds of stochastic price paths with realistic temporary (reverts immediately) and permanent (persists) market impact, and computes realized implementation shortfall (the actual dollar cost vs. the arrival price) for each.main.py— runs everything and produces:- The optimal vs. TWAP vs. immediate trade trajectories
- The realized cost distribution across simulated markets for each strategy
- The efficient frontier: expected cost vs. risk as the risk-aversion parameter varies — the actual decision tool a trading desk uses
| Strategy | Mean Implementation Shortfall | Std Dev (Risk) |
|---|---|---|
| Almgren-Chriss (optimal, λ=0.02) | $34,074 | $92,235 |
| TWAP (naive, linear) | $32,320 | $111,371 |
| Immediate (dump all at once) | $500,000 | $0 |
How to read this: TWAP has slightly lower expected cost than the optimal trajectory at this risk-aversion setting, but the Almgren-Chriss schedule reduces the standard deviation of cost by ~17% — i.e. fewer bad-tail outcomes — by trading faster and accepting a small increase in expected impact cost. That's the entire point of the model: it's not about minimizing cost in expectation, it's about choosing the cost/risk tradeoff deliberately rather than by accident. "Immediate" execution shows the other extreme: zero timing risk (it's all over in one interval) but a brutal, guaranteed impact cost — useful as a worst-case reference point.
See outputs/efficient_frontier.png for the full cost-vs-risk tradeoff as
the risk-aversion parameter varies — this is the chart a trading desk
actually uses to pick an execution speed appropriate to their risk
tolerance and urgency.
.
├── almgren_chriss.py # closed-form optimal execution model + naive baselines
├── execution_simulator.py # Monte Carlo execution simulation with market impact
├── main.py # runs everything, produces plots + CSV
├── requirements.txt
└── outputs/
├── trajectories.png # optimal vs TWAP vs immediate trade schedules
├── cost_distributions.png # realized cost distribution per strategy
├── efficient_frontier.png # cost vs risk tradeoff across risk-aversion levels
└── strategy_comparison.csv
pip install -r requirements.txt
python main.pyAll parameters (order size, time horizon, volatility, impact coefficients,
risk aversion) are set as constants at the top of main.py — change them
and rerun to explore different scenarios (e.g. a more liquid stock with
lower impact coefficients, or a more urgent execution with higher lambda).
- Calibrate impact coefficients (eta, gamma) to real market data instead of illustrative values — these are typically estimated from historical trade/quote data per instrument.
- Add a discrete optimal-control (dynamic programming) solver to verify the closed-form trajectory matches the numerically optimal one.
- Model intraday volume curves (U-shaped volume) for a more realistic VWAP comparison instead of treating volume as uniform.
- Extend to multi-asset execution with cross-impact between correlated names.
Almgren-Chriss optimal execution · market microstructure (temporary vs. permanent impact) · implementation shortfall · mean-variance optimization · efficient frontier construction · Monte Carlo simulation of execution risk