Following a stock's beta as it moves
In this capstone you build three trackers for the beta of Apple against SPY and compare them. The model is a random-walk beta: each day the stock return is the beta times the market return plus noise, and the beta itself drifts a little. The first tracker is a rolling regression over the last 60 days, which equals a hard window. The second is a Kalman filter, the exact answer when everything is bell-shaped. The third is a bootstrap particle filter that you write with its own weight normalisation, effective sample size and systematic resampling. An exponentially weighted estimator follows the volatility of what the market does not explain.
βₜ=βₜ₋₁+wₜ, yₜ=βₜ mₜ+eₜ, K=(P⁻mₜ)/(P⁻mₜ²+r)
What the real data saysOn the 5,404 days of Apple and SPY since 2005, the full-sample beta is 1.07. On the last day, the 60-day regression says 0.20, the Kalman filter 0.40 and the particle filter with 500 particles 0.43. Predicting each day's return from yesterday's beta, the mean squared errors are 2.379×10⁻⁴ for one fixed beta, 2.378×10⁻⁴ for the rolling beta, 2.354×10⁻⁴ for Kalman and 2.362×10⁻⁴ for the particles. Following the beta helps by about 1%, not more, because daily returns are mostly noise. The particle filter resamples on 107 days, and its effective sample size drops to about 7 of 500. The exponentially weighted volatility of the residuals is about 32% a year at the end of the data.
- Same model, three solvers: a hard window, the exact Gaussian filter and a cloud of weighted particles.
- Reproducible randomness: the random numbers come in as arguments, so the same inputs give the same answer.
- Honest scoring: each method predicts a day's return with yesterday's beta only.
Simplifications to rememberThe beta is a random walk with a fixed step q=10⁻³ that was chosen by hand, and the noise is treated as normal with a constant variance, which ignores volatility clustering. The score uses the squared error of a single stock over one sample. In this linear Gaussian model Kalman is exact, so the particle filter can only match it, and its advantage appears when the noise is fat-tailed or the variance moves.
Lab · what's graded
- Safe normalisation5 pts
- Effective sample size5 pts
- Systematic resampling10 pts
- A rolling beta10 pts
- Exponentially weighted volatility10 pts
- The Kalman filter15 pts
- The bootstrap particle filter25 pts
- The beta study20 pts