insideout Get Pro
Learn
Quant engineering · Module 03

Time Series

How market data behaves over time, and what it can predict.

Start here · Lesson 01

Prices and returns

Why quants model returns, not prices, and simple against log returns.

Start lesson

LessonsAll lessons

  1. 01 Prices and returnsWhy quants model returns, not prices, and simple against log returns. Free
  2. 02 Volatility clustersCalm and wild stretches, and how to measure volatility. Free
  3. 03 AutocorrelationWhether today's move says anything about tomorrow's. Free
  4. 04 Random walk or notTesting whether a series has any memory at all. Pro
  5. 05 StationarityWhich series you can model directly, and how to transform the rest. Pro
  6. 06 Mean reversionSeries that snap back, and how fast: the half-life. Pro
  7. 07 Momentum and trendSeries that keep going, and how to tell the difference. Pro
  8. 08 Autoregressive modelsPredicting the next value from the last few. Pro
  9. 09 Cointegration and pairsTwo prices that wander together, and trading the gap. Pro
  10. 10 Volatility modelsExponential weighting and the idea behind GARCH. Pro
  11. 11 Forecasting honestlyOut-of-sample tests, walk-forward and the baseline to beat. Pro

Build it yourself · on your own machine

Forecasting tomorrow's volatility

EWMA and GARCH volatility forecasts for the S&P 500, scored walk-forward on years they never saw against a plain rolling window.
  1. Download at least 15 years of daily closes for SPY, the S&P 500 fund on NYSE Arca, and compute log returns.
  2. Check autocorrelation of returns and of squared returns to 20 lags with a Ljung-Box test, and work out the kurtosis.
  3. Run the augmented Dickey-Fuller test on prices and on returns, and the variance ratio at 2, 5 and 10 days.
  4. Forecast each day's variance from earlier days only: a 20-day window as the baseline, EWMA with λ = 0.94, and GARCH(1,1) refitted each month with the arch package.
  5. Score the last five years walk-forward against each next day's squared return with QLIKE and mean squared error, and work out each forecast's skill score against the baseline.
  6. Write a test that changes one day's return and fails if that day's forecast, or any earlier one, moves.

How you'll know it worksA walk-forward table of QLIKE, mean squared error and skill score for all three forecasts over the last five years, and a passing test that no forecast uses its own day's return.

Python with NumPy, pandas, statsmodels and arch. You download the price CSV yourself from a free source such as Stooq or Yahoo Finance; it all runs on a laptop in minutes. Uses lessons 01 to 11.