Phase 12 - Lesson 12.5

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.

⏱ 55 min● Advanced🔗 Prereqs: 12.2, 11.2, 4.x linear algebra
↖ Phase 12 hub
Builds on: Regression (11.2) and ARMA (12.2) are special cases of the state-space form.
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.

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

Intuition
Many quantities we care about are hidden and moving: a true fair value beneath noisy quotes, a slowly-drifting hedge ratio, an unobserved volatility state. A state-space model says exactly two things: how the hidden state evolves (a dynamics equation) and how it shows up in what we can measure (an observation equation), each with its own noise. This one template contains linear regression, ARMA, and random walks as special cases.

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\):

\[x_t=F x_{t-1}+w_t,\quad w_t\sim\Normal(0,Q);\qquad y_t=H x_t+v_t,\quad v_t\sim\Normal(0,R),\] (12.6)

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\).

Worked Example - Predict then update
1
Predict the state: \(\hat x_{t\mid t-1}=F\hat x_{t-1\mid t-1}\), and its covariance \(P_{t\mid t-1}=F P_{t-1\mid t-1}F^\top+Q\) (uncertainty grows by process noise).
2
Innovation: \(e_t=y_t-H\hat x_{t\mid t-1}\) with covariance \(S_t=H P_{t\mid t-1}H^\top+R\).
3
Kalman gain: \(K_t=P_{t\mid t-1}H^\top S_t^{-1}\) - the prediction's uncertainty relative to the total, i.e. how much to move toward the observation.
4
Update: \(\hat x_{t\mid t}=\hat x_{t\mid t-1}+K_t e_t\) and \(P_{t\mid t}=(I-K_t H)P_{t\mid t-1}\) (uncertainty shrinks by the information gained).

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.

Key Idea
For linear-Gaussian systems the Kalman filter is exact Bayesian inference and the minimum-MSE estimator; the sequence of innovations is white with known covariances \(S_t\), which gives the Gaussian log-likelihood used to estimate \(F,H,Q,R\) by MLE (the prediction-error decomposition). For nonlinear systems, the EKF/UKF linearize or sample.

Interactive: one Kalman step

Common Mistakes to Avoid
  • 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).
Quant Practitioner Tips
  • 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

Q1 Medium
In the Kalman filter, the predict step changes the state covariance by:
Shrinking it by the measurement
Inflating it by the process noise \(Q\)
Setting it to zero
Leaving it unchanged
Q2 Medium
The Kalman gain \(K_t\) is large when:
Measurement noise \(R\) is large
The predicted state uncertainty is large relative to measurement noise
The state is perfectly known
The process noise \(Q\) is zero
Q3 Medium
For a linear-Gaussian model, the Kalman filter produces:
A biased estimate
The exact Bayesian posterior and the minimum-MSE estimate
Only a point estimate with no uncertainty
The smoothed estimate using future data

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?

▶ Show full solution

(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).

After the reveal, answer for yourself: The filter/smoother distinction is a look-ahead trap in disguise: research may smooth, but any tradable signal must be strictly filtered.

Lesson Summary

A state-space model pairs a latent-state transition equation with a noisy observation equation, unifying regression, ARMA, and random walks. The Kalman filter tracks the state by a predict step (covariance grows by \(Q\)) and an update step (covariance shrinks), blending model and data through the Kalman gain \(K_t=P_{t\mid t-1}H^\top S_t^{-1}\). For linear-Gaussian systems it is exact Bayesian, MMSE-optimal, and yields the innovation likelihood for parameter estimation. Filtered estimates are tradable; smoothed ones use future data and must never drive live decisions.

Formula Sheet Additions

Kalman gain
\[K_t=P_{t\mid t-1}H^\top(HP_{t\mid t-1}H^\top+R)^{-1}\]
Precision weight on the innovation; balances model vs data.
Covariance recursion
\[P_{t\mid t-1}=FP_{t-1\mid t-1}F^\top+Q,\ \ P_{t\mid t}=(I-K_tH)P_{t\mid t-1}\]
Predict inflates, update deflates uncertainty.
Error Log Checklist
  • 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.

▶ Show retrieval prompts & answers
Q: Write the two equations of a linear-Gaussian state-space model.
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)\).
Q: Give the Kalman gain and say what makes it large.
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.
Q: Why can smoothed states cause look-ahead bias?
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.

State-space model
State \(x_t=Fx_{t-1}+w_t\), observation \(y_t=Hx_t+v_t\); unifies regression, ARMA, random walk.
Kalman step
Predict (\(P\) grows by \(Q\)) then update (gain \(K\) blends model and data; \(P\) shrinks).
Filter vs smoother
Filter: data up to \(t\) (tradable). Smoother: all data (look-ahead; research only).

Completion Checklist

Confidence / mastery rating
Personal notes

Source References

This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.