Introduction

Why Algorithmic Trading?

Algorithmic trading is the practice of using computer programs to execute trading strategies automatically. Nearly all professional trading today is algorithmic — from high-frequency market making to systematic hedge funds. Understanding the mathematics and code behind these strategies gives you a window into one of the most quantitative fields in finance.

This course teaches algorithmic trading by implementing everything from scratch in pure Python. No pandas, no numpy, no scipy — just the mathematics expressed as functions. Each lesson introduces one concept, explains the financial intuition, and asks you to write the implementation.

You will build:

  • Moving Averages — Simple and exponential moving averages; the building blocks of all technical indicators
  • Bollinger Bands — Volatility envelopes using rolling mean and standard deviation
  • RSI — Relative Strength Index; a momentum oscillator ranging from 0 to 100
  • MACD — Moving Average Convergence Divergence; a trend-following momentum indicator
  • SMA Crossover — The classic trend-following signal: buy when fast crosses above slow
  • Momentum Strategy — Return over a lookback period; buy winners, short losers
  • Trend Following Returns — Simulate strategy P&L using momentum signals
  • Z-Score Mean Reversion — Rolling z-score to identify statistical extremes
  • Pairs Trading — Spread between correlated assets; trade the divergence from equilibrium
  • Portfolio Rebalancing — Compute trades needed to return to target weights
  • Backtest Engine — Simulate a trading strategy on historical prices, tracking cash and position
  • Slippage & Transaction Costs — Model the real-world impact of market impact and commissions
  • Sharpe Ratio — The canonical risk-adjusted performance metric; annualized via sqrt(252)
  • Walk-Forward Validation — Time-series cross-validation that prevents look-ahead bias
  • Kelly Criterion — Optimal position sizing to maximize long-term geometric growth
Next →