A trading engine that helps break up large stock orders into smaller pieces to minimize trading costs. It's based on the Almgren-Chriss mathematical model.
When you want to buy or sell a large number of shares:
- Trade too fast → You move the market price against yourself (market impact)
- Trade too slow → The market might move against you randomly (timing risk)
The engine finds the perfect balance between these two risks by calculating an optimal trading schedule.
The model simulates price changes using this simple equation: Price change = (Your trading impact) + (Random market noise)
text
- Your trading impact: When you sell, price goes down; when you buy, price goes up
- Random market noise: Normal up/down movements that happen anyway
- C++ core: Fast, multi-threaded execution engine
- Python bindings: Easy to use from Python (via pybind11)
- Multi-threaded design:
- Multiple threads can submit orders
- One dedicated thread executes the trades
- Submit large orders with custom parameters
- Get optimal trading schedules
- Track execution progress
- Monitor performance metrics
- Real-time callbacks for execution updates
import almgren_chriss as ac
# Create engine
engine = ac.TradingEngine()
engine.initialize()
# Submit a large order
order_id = engine.submit_order(
symbol="AAPL",
total_shares=100000,
is_buy=False, # Sell order
initial_price=150.0,
time_horizon=3600, # Execute over 1 hour
risk_aversion=0.1
)
# Start execution
engine.start_execution()
# Track progress
metrics = engine.get_order_metrics(order_id)
print(f"Executed: {metrics.executed_shares}/{metrics.total_shares}")
print(f"Average price: {metrics.average_execution_price}")Minimize trading costs for large orders
Handle institutional-sized trades
Quantify the trade-off between speed and cost
Real-time execution monitoring
P.S. the above is a screen shot of the Flask Web app but is not published yet due to some threading issue with Python