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.

Fig. — Efficient frontier and three portfolios: minimum variance, risk parity and HRP (schematic)
05/08
Prerequisite
Levels 2 and 3; basic linear algebra
Profile
Manager or trader who wants to trade live

Portfolio theory and optimisation

  • 4.1.1 Markowitz mean-variance; efficient frontier; real-world constraints.
  • 4.1.2 Covariance estimation: shrinkage (Ledoit-Wolf), factor models, denoising (random matrix theory).
  • 4.1.3 Black-Litterman: incorporating views, including those from ML models.
  • 4.1.4 Risk parity, maximum diversification, minimum variance; HRP and HERC (López de Prado).
  • 4.1.5 Optimisation with CVaR, drawdown and turnover and cost constraints (cvxpy).
  • 4.1.6 Factor models: CAPM, Fama-French, PCA; attribution.
  • 4.1.7 Rebalancing (calendar or threshold-based) and portfolios of strategies.
  • 4.1.8 Tools: Riskfolio-Lib, PyPortfolioOpt, skfolio, bt.

Risk management and position sizing

  • 4.2.1 Risk per trade, stops (fixed, ATR, time-based), risk of ruin.
  • 4.2.2 The Kelly criterion (and fractional Kelly) and volatility targeting.
  • 4.2.3 VaR (historical, parametric, Monte Carlo), CVaR or Expected Shortfall, VaR backtesting.
  • 4.2.4 Stress testing with historical scenarios (1987, 2008, 2020, 2022); correlation, liquidity, gap and counterparty risk.
  • 4.2.5 Drawdown control: exposure reduction, circuit breakers, kill switch.
  • 4.2.6 Derivatives-specific risk: portfolio Greeks, margin, liquidations.

Microstructure and execution

  • 4.3.1 Implementation shortfall, VWAP and TWAP; impact models (square root, Almgren-Chriss).
  • 4.3.2 Order flow imbalance and microstructure signals; latency (retail versus HFT).

Brokers and APIs

  • 4.4.1 Choosing a broker from Spain or the EU: regulation (CNMV, ESMA, passporting), assets, costs, API.
  • 4.4.2 Interactive Brokers: TWS and IB Gateway, ib_async, contracts, data, orders.
  • 4.4.3 Alpaca, Tradier; MetaTrader 5 with Python; OANDA v20.
  • 4.4.4 Crypto: ccxt, native APIs (Binance, Bybit, Kraken, Coinbase), websockets.
  • 4.4.5 Secure credentials: environment variables, secret managers, least privilege (no withdrawals).

Live trading system

  • 4.5.1 Architecture: data → signal → risk → OMS → broker → reconciliation.
  • 4.5.2 Order management: states, partial fills, cancellations, reconnections.
  • 4.5.3 Paper trading and shadow trading; backtest versus live comparison (slippage tracking).
  • 4.5.4 Task scheduling (cron, APScheduler, Prefect) and alerts (Telegram, Slack, email).
  • 4.5.5 Fault tolerance: idempotency, persistent state, reconciliation at startup.
  • 4.5.6 NautilusTrader or LEAN live: from backtest to production with the same code.

Research on this site to practise this level

Practice

  1. Volatility Targeting in PythonResearch-0004 · 7 min
  2. Price Discovery & Arbitrage Pricing TheoryResearch-0006 · 6 min
  3. Quantitative Models and Algorithmic ExecutionResearch-0009 · 11 min
  4. Finite-State Machines for Quantitative Trading Execution in Python: From Knight Capital to LangGraphResearch-0029 · 47 min