Three end-to-end exercises that integrate everything we've covered. Each case is a workflow a desk quant might run on a Monday morning. We won't reproduce the code in detail — that's for the Python and R courses — but we'll articulate the analytical steps, the diagnostics, and the conclusions.
Case 1 — GARCH vol model on NSE-20 daily returns
- Pull 5 years of daily NSE-20 closing prices. Compute log returns. Plot the time series — look for breaks, gaps, regime changes (a multi-week trading halt or a dramatic policy shift).
- Test for stationarity on returns: ADF should reject unit root easily. KPSS should not reject stationarity.
- Inspect ACF of returns (should be ≈ zero) and ACF of squared returns (should be strongly positive — evidence of vol clustering).
- Fit GARCH(1,1) with Gaussian innovations. Get α̂, β̂, ω̂. Check α + β ≈ 0.95-0.99 (typical), and the implied unconditional vol.
- Refit with Student-t innovations. Compare log-likelihood and AIC.
- Compute conditional one-day VaR_95 and VaR_99 using the fitted GARCH. Compare to historical-simulation VaR over the same period.
- Back-test: count how often realised loss exceeds predicted VaR. Run Kupiec and Christoffersen tests. A correctly-calibrated 99% VaR has ~1% violation rate.
What this teaches
GARCH dramatically outperforms i.i.d. Gaussian VaR during volatile periods (it correctly inflates the predicted VaR when recent moves have been large) but can be slow to come down after a vol spike has passed. This is the conservatism-vs-responsiveness trade-off every risk team negotiates.
Case 2 — Cointegration test, Safaricom vs the NSE-20
- Pull 3 years of daily prices for Safaricom (SAFCOM) and the NSE-20 index. Work in log levels.
- ADF on each series in levels: both should fail to reject the unit-root null (both are I(1)).
- ADF on first differences (log returns): both should reject (returns are I(0)). Confirms both are I(1).
- Estimate the cointegrating regression: log SAFCOM_t = α + β log NSE20_t + u_t. Note β̂ ≈ 1 in many empirical setups — a 1% move in the index corresponds to ~1% move in Safaricom.
- Engle-Granger ADF on residuals. If you reject the unit root (using Engle-Granger critical values, not standard ADF), the two are cointegrated.
- Estimate the speed of adjustment: fit AR(1) to the residuals. The AR coefficient ρ gives half-life log(0.5)/log(ρ).
- Translate into a trading rule: when residual exceeds 2σ_u, take the spread position; exit when it returns to zero.
- Back-test on out-of-sample data. Compute the Sharpe of the rule. Stress-test on subperiods.
Cointegration is fragile
Pairs that cointegrated for 3 years can break for fundamental reasons — M&A, regulatory change, sector rotation. Rolling-window cointegration tests and dynamic re-fitting are essential. The half-life is also unstable: a pair with 10-day half-life this quarter can drift to 60-day half-life next quarter, blowing up the capital requirements of the strategy.
Case 3 — Kalman filter on a noisy commodity price
- Take daily Brent crude futures settlements. Construct a 'noisy proxy' by adding observation noise (or use a high-frequency tick series).
- Specify state-space: latent log-price follows random walk, observation = latent + noise.
- Estimate Q (process variance) and R (observation variance) by MLE through the Kalman filter likelihood.
- Run the filter: get the smoothed log-price estimate and its uncertainty band at each time.
- Use the filtered series as input to a downstream model (e.g., a forecasting AR or GARCH). Compare performance to the raw series.
- Extension: allow a slowly-drifting state mean by adding a level-and-slope local-linear-trend model. Compare BIC.
What this teaches
The Kalman filter is not just an academic curiosity — it is the right tool whenever you have a model for a latent state and noisy observations. Even when you can compute a moving average that approximates the same smoothing, the Kalman version gives you uncertainty bands and adaptively re-weights based on the data. The Q/R ratio is the most important hyperparameter; small Q/R means heavy smoothing, large Q/R means trust the data.
Where to go next
- Stochastic Calculus course: continuous-time analogues of these models — Brownian motion, Ornstein-Uhlenbeck for mean-reverting series, Heston for stochastic vol.
- Optimization course: portfolio construction takes the covariance estimated here and turns it into a portfolio.
- Numerical Methods course: putting these algorithms into production code with the right variance reduction and numerical stability.
- Python and R courses: the implementations of every model in this course.
Exercise
You're handed the brief: 'Build me a daily VaR system for the firm's equity book.' Outline a 4-week plan integrating GARCH, multivariate factor structure, and back-testing. What questions do you ask the risk committee before coding?