Level 4 · 90–100 h
Portfolios, risk, execution and live trading
From backtest to a live account: build portfolios of strategies, size and control risk, execute with measured costs and set up a fault-tolerant live system.
- Prerequisite
- Levels 2 and 3; basic linear algebra
- Profile
- Manager or trader who wants to trade live
Portfolio theory and optimisation
4.1.1Markowitz mean-variance; efficient frontier; real-world constraints.4.1.2Covariance estimation: shrinkage (Ledoit-Wolf), factor models, denoising (random matrix theory).4.1.3Black-Litterman: incorporating views, including those from ML models.4.1.4Risk parity, maximum diversification, minimum variance; HRP and HERC (López de Prado).4.1.5Optimisation with CVaR, drawdown and turnover and cost constraints (cvxpy).4.1.6Factor models: CAPM, Fama-French, PCA; attribution.4.1.7Rebalancing (calendar or threshold-based) and portfolios of strategies.4.1.8Tools: Riskfolio-Lib, PyPortfolioOpt, skfolio, bt.
Risk management and position sizing
4.2.1Risk per trade, stops (fixed, ATR, time-based), risk of ruin.4.2.2The Kelly criterion (and fractional Kelly) and volatility targeting.4.2.3VaR (historical, parametric, Monte Carlo), CVaR or Expected Shortfall, VaR backtesting.4.2.4Stress testing with historical scenarios (1987, 2008, 2020, 2022); correlation, liquidity, gap and counterparty risk.4.2.5Drawdown control: exposure reduction, circuit breakers, kill switch.4.2.6Derivatives-specific risk: portfolio Greeks, margin, liquidations.
Microstructure and execution
4.3.1Implementation shortfall, VWAP and TWAP; impact models (square root, Almgren-Chriss).4.3.2Order flow imbalance and microstructure signals; latency (retail versus HFT).
Brokers and APIs
4.4.1Choosing a broker from Spain or the EU: regulation (CNMV, ESMA, passporting), assets, costs, API.4.4.2Interactive Brokers: TWS and IB Gateway, ib_async, contracts, data, orders.4.4.3Alpaca, Tradier; MetaTrader 5 with Python; OANDA v20.4.4.4Crypto: ccxt, native APIs (Binance, Bybit, Kraken, Coinbase), websockets.4.4.5Secure credentials: environment variables, secret managers, least privilege (no withdrawals).
Live trading system
4.5.1Architecture: data → signal → risk → OMS → broker → reconciliation.4.5.2Order management: states, partial fills, cancellations, reconnections.4.5.3Paper trading and shadow trading; backtest versus live comparison (slippage tracking).4.5.4Task scheduling (cron, APScheduler, Prefect) and alerts (Telegram, Slack, email).4.5.5Fault tolerance: idempotency, persistent state, reconciliation at startup.4.5.6NautilusTrader or LEAN live: from backtest to production with the same code.
Research on this site to practise this level