Quant Memo
Advanced

The Kalman Filter

A recursive way to track a hidden quantity you can only measure noisily. Each step, it predicts, then blends the prediction with the new (imperfect) measurement, trusting whichever is less uncertain.

Prerequisites: Bayesian Inference, The Normal Distribution

You often want to know something you can't measure directly. The true price of a thinly-traded asset, a rocket's exact position, a slowly-drifting hedge ratio, none of these come with a clean readout. What you get instead is a stream of noisy measurements. The Kalman filter is the classic recipe for turning that noisy stream into a smooth, best-guess estimate of the hidden truth, updated in real time as each new observation arrives.

Its cleverness is that it never stores the whole history. At every step it carries just two things: its current best estimate and how uncertain it is. When a new measurement lands, it folds that in and moves on. This makes it fast, memory-light, and perfect for live systems, which is why it steered the Apollo spacecraft and now runs quietly inside countless trading and tracking systems.

The predict-update loop

The filter cycles through two moves, over and over:

  1. Predict. Use your model of how the state evolves to roll your estimate forward one step. Your best guess drifts to where the dynamics say it should go, and, crucially, your uncertainty grows, because prediction is never perfect.
  2. Update. A new measurement arrives. Blend it with the prediction. The blend isn't 50/50, it's weighted by which source you trust more. Fold it in and your uncertainty shrinks, because you just learned something.

The weight in that blend is the Kalman gain KK. For a simple one-dimensional state it is

K=PP+R,K = \frac{P}{P + R},

where PP is the variance of your prediction (how unsure you are before the measurement) and RR is the variance of the measurement noise (how unreliable the sensor is). The updated estimate then corrects the prediction by a fraction KK of the surprise:

x^new=x^pred+K(yx^pred).\hat x_{\text{new}} = \hat x_{\text{pred}} + K\big(y - \hat x_{\text{pred}}\big).

Read the gain: if your prediction is rock-solid (PP small) the gain is near 00 and you barely move for a noisy measurement; if the measurement is pristine (RR small) the gain is near 11 and you snap to it. It's an automatic, self-tuning trust dial.

noisy measurements filtered estimate true state (hidden) time
The clay dots are what you actually observe, noise around a hidden true path (dashed). The Kalman filter (green) threads a smooth estimate between them, trusting its own momentum when a measurement looks like an outlier.

The Kalman filter alternates predict (roll forward, uncertainty grows) and update (blend in the measurement, uncertainty shrinks). The blend weight is the gain K=P/(P+R)K = P/(P+R): trust the prediction when the sensor is noisy, trust the measurement when the prediction is stale.

Worked example: one update step

Your current best estimate of a hidden value is x^pred=100\hat x_{\text{pred}} = 100, and after the predict step its uncertainty is P=9P = 9 (a standard deviation of 33). A fresh measurement reads y=106y = 106, from a sensor with noise variance R=3R = 3.

First the gain:

K=PP+R=99+3=0.75.K = \frac{P}{P + R} = \frac{9}{9 + 3} = 0.75.

The measurement is more precise than your prediction (R=3<P=9R = 3 < P = 9), so the gain leans toward it. The surprise is 106100=6106 - 100 = 6, and you correct by three-quarters of it:

x^new=100+0.75×6=104.5.\hat x_{\text{new}} = 100 + 0.75 \times 6 = 104.5.

Finally, your uncertainty drops: the updated variance is (1K)P=0.25×9=2.25(1 - K)\,P = 0.25 \times 9 = 2.25, a standard deviation of 1.51.5, lower than both the prediction's 33 and the sensor's 31.73\sqrt 3 \approx 1.73. That's the quiet magic: combining two imperfect sources yields an estimate sharper than either one, exactly the Bayesian logic of pooling independent evidence, run recursively.

Where it fits in quant work

The filter is the engine behind State-Space Models, and a common use is estimating a time-varying hedge ratio in Pairs Trading: the relationship between two assets drifts, so you treat the hedge ratio as a hidden state and let the Kalman filter track it live instead of refitting a static regression on a rolling window.

A rolling-window regression throws away old data abruptly at the window edge; a Kalman filter fades old information smoothly through its uncertainty. For a slowly-drifting parameter (a hedge ratio, a beta), the filter usually tracks cleaner and reacts faster.

Where it misleads

  • It assumes linear-Gaussian. The plain filter is optimal only when the dynamics are linear and the noise is Gaussian. Real markets are neither; extensions (extended and unscented Kalman filters, particle filters) handle nonlinearity, at more cost and fragility.
  • Garbage tuning, garbage output. The filter's behaviour is set by the noise variances you feed it (the process noise and measurement noise). Set the process noise too low and it grows overconfident and ignores real changes; too high and it chases every wiggle. These knobs must be tuned or estimated, not guessed.
  • It trusts its model. If the true dynamics break from your assumed model (a regime shift, a structural break), the filter can lag badly or diverge, its uncertainty says it's confident right when it's most wrong.

The picture to carry: the Kalman filter is a running argument between what you expected and what you just saw, settled every step by whichever is less uncertain. It's Bayesian Inference made recursive, and the workhorse of estimating hidden, drifting quantities from noisy data.

Related concepts

Practice in interviews

Further reading

  • Kalman (1960), A New Approach to Linear Filtering and Prediction Problems
  • Hamilton, Time Series Analysis (Ch. 13)
  • Durbin & Koopman, Time Series Analysis by State Space Methods
ShareTwitterLinkedIn