State-Space Models and the Kalman Filter
A unifying framework for dynamic latent variables, and the recursive predict-update algorithm that is optimal for linear-Gaussian systems.
Leads to: Kalman filtering underlies dynamic hedge ratios and pairs trading (12.6).
Learning Objectives
Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.
- Write a linear-Gaussian state-space model with its state and observation equations.
- Derive the Kalman filter predict and update steps and interpret the Kalman gain.
- Explain in what sense the filter is optimal (MMSE) and how it relates to Bayesian updating.
- Implement one full Kalman step and track the state covariance.
- Apply the filter to a time-varying regression / dynamic hedge ratio in finance.
Key Vocabulary
- State-space model
- A latent state evolving by a transition equation, observed noisily through a measurement equation.
- State equation
- \(x_t=F x_{t-1}+w_t\), \(w_t\sim\Normal(0,Q)\); the hidden dynamics.
- Observation equation
- \(y_t=H x_t+v_t\), \(v_t\sim\Normal(0,R)\); the noisy measurement of the state.
- Kalman gain
- \(K_t\), the optimal weight on the new observation's surprise; blends prediction and measurement by their precisions.
- Innovation
- The one-step forecast error \(y_t-H\hat x_{t\mid t-1}\); a white-noise sequence if the model is correct.
- State covariance
- \(P_t\), the uncertainty of the state estimate; propagated and updated each step.
- Filtering vs smoothing
- Filtering uses data up to \(t\); smoothing uses the whole sample to re-estimate past states.
Intuition & Motivation
The Kalman filter is the optimal way to track such a state in real time. Each step is a two-move dance: predict the state forward using the dynamics (uncertainty grows), then update it with the new observation (uncertainty shrinks). The update is a precision-weighted average of what you expected and what you saw - the Kalman gain decides how much to trust the new data versus the model. When the noise is Gaussian this is exactly Bayesian updating and is the minimum-mean-squared-error estimate; when it is not, it is still the best linear one.
The linear-Gaussian state-space model
With hidden state \(x_t\in\R^k\) and observation \(y_t\in\R^m\):
with \(w_t,v_t\) independent white noise. Many models are special cases: a time-varying regression \(y_t=x_t^\top z_t+v_t\) with \(F=I\) (random-walk coefficients); an AR(\(p\)) by stacking lags into the state; a local-level (random walk plus noise) model with \(F=H=1\).
The Kalman recursion
Let \(\hat x_{t\mid t-1}\) and \(P_{t\mid t-1}\) denote the predicted state and covariance, and \(\hat x_{t\mid t},P_{t\mid t}\) the updated ones after seeing \(y_t\).
Read the gain as a trust dial. If measurement noise \(R\) is large (noisy data), \(S_t\) is large, \(K_t\) is small - barely move toward the observation. If the state is very uncertain (\(P_{t\mid t-1}\) large), \(K_t\) is large - lean on the data. In the scalar local-level model, \(K_t=P_{t\mid t-1}/(P_{t\mid t-1}+R)\) is literally the fraction of total variance owned by the state.
Interactive: one Kalman step
- Swapping \(Q\) and \(R\): large \(Q\) (volatile state) makes the filter track fast; large \(R\) (noisy data) makes it smooth - mixing them up mis-tunes everything.
- Confusing filtering (uses data up to \(t\)) with smoothing (uses all data); only filtered estimates are available in real time for trading.
- Assuming optimality under non-Gaussian noise; the filter is then only the best linear estimator, not the exact posterior.
- Letting \(P\) lose positive-definiteness from round-off; use the Joseph form or a square-root filter for stability.
- Ignoring look-ahead: a smoother uses future data, so smoothed states must never drive a backtest decision (12.6).
- Estimate \((F,H,Q,R)\) by maximizing the Gaussian innovation likelihood - the filter yields it for free via the prediction-error decomposition.
- Check that innovations are white with covariance \(S_t\); residual autocorrelation signals a misspecified state model.
- For a dynamic hedge ratio or drifting beta, set \(F=I\) and let \(Q\) control how fast the coefficient adapts - tune \(Q/R\) by validation.
- Use the RTS smoother only for research/analysis, never for live signals - it peeks at the future.
Knowledge Check
Practical Exercise
You model a drifting hedge ratio \(\beta_t\) between two assets as a random walk observed through the regression \(y_t=\beta_t z_t+v_t\). (a) Write the state-space form. (b) What do \(Q\) and \(R\) each control? (c) Why must you use filtered (not smoothed) \(\beta_t\) in a live pairs-trade, and what bias arises if you forget?
(a) State: \(\beta_t=\beta_{t-1}+w_t,\ w_t\sim\Normal(0,Q)\) (so \(F=1\)). Observation: \(y_t=z_t\beta_t+v_t,\ v_t\sim\Normal(0,R)\) with a time-varying \(H_t=z_t\). The Kalman recursion tracks \(\hat\beta_t\) and its variance \(P_t\).
(b) \(Q\) sets how quickly the hedge ratio is allowed to drift (large \(Q\) -> the estimate adapts fast, chasing recent data); \(R\) sets how noisy each observation is (large \(R\) -> the filter smooths, trusting the model). The ratio \(Q/R\) is the key tuning knob.
(c) A live decision at time \(t\) can only use data through \(t\), which is exactly the filtered estimate \(\hat\beta_{t\mid t}\). The smoothed estimate \(\hat\beta_{t\mid T}\) uses future observations up to \(T\gt t\) - a look-ahead bias. Backtesting with smoothed betas peeks at the future, inflating performance and producing a strategy that cannot be traded; the live P&L then disappoints (the 12.6 pitfall).
Lesson Summary
Formula Sheet Additions
- Did I keep \(Q\) (state drift) and \(R\) (measurement noise) straight?
- Am I using filtered estimates for any real-time/trading decision, never smoothed?
- Are the innovations white with covariance \(S_t\) (model adequacy)?
- Is \(P\) kept positive-definite (Joseph/square-root form)?
Retrieval Practice
Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.
A: State \(x_t=Fx_{t-1}+w_t,\ w_t\sim\Normal(0,Q)\); observation \(y_t=Hx_t+v_t,\ v_t\sim\Normal(0,R)\).
A: \(K_t=P_{t\mid t-1}H^\top S_t^{-1}\) with \(S_t=HP_{t\mid t-1}H^\top+R\); large when the state is uncertain or the data are precise.
A: Smoothing uses future observations up to \(T\) to re-estimate past states; using them in a live/backtest decision peeks at the future.
Flashcards
Click to flip. These feed the site-wide spaced-repetition queue.
Completion Checklist
- I can explain the core ideas in my own words
- I worked the derivations/examples by hand
- I completed the interactive workbench(es)
- I passed the knowledge check