Concept

Kalman Filter

Kalman Filter is a Statistics concept. The Library holds 1 implementation, a working definition you can pull into Quant.

trend. adaptive hedge ratio

Top Kalman Filter indicator

The top custom implementation, built on the original standard Kalman Filter formula.

1 total

This Kalman Filter implementation is strategy-ready: open it in Quant, set your rules, and it backtests automatically.

What is a Kalman Filter?

A Kalman filter is a recursive estimator, introduced by Rudolf Kálmán in 1960 for control engineering, that tracks the hidden state of a noisy system one observation at a time. Applied to markets, the usual assumption is that each print is an unobserved 'true' level plus noise. Every bar the filter predicts where that level should be from a simple motion model, then blends the prediction with the new price. The blending weight, called the Kalman gain, is recomputed each step from two variances: how much the true state is allowed to wander (process noise) and how noisy observations are (measurement noise).

Traders use it as an adaptive smoother: when the settings imply prices are informative, the gain rises and the filter hugs price; when they imply noise, it flattens and rides out chop. The same recursion can estimate an evolving hedge ratio between two instruments in pairs trading, an example of adaptive parameterization done with explicit statistics. The caveat is that the output is only as good as the assumed model: the filter still lags at genuine turning points, and badly chosen noise settings produce smooth, confident-looking lines that are simply wrong.

How a Kalman filter works

The filter is a two-step loop, predict then update, run once per bar.

  1. 1Specify the model: choose the state to track (a smoothed price level, often paired with its velocity) and set the two noise variances, process and measurement. Their ratio is the filter's real tuning knob.
  2. 2Predict: project the state one bar forward with the motion model (unchanged level, or level plus velocity) and widen its uncertainty by the process noise.
  3. 3Update: when the bar arrives, compute the Kalman gain from the predicted uncertainty relative to measurement noise, then pull the prediction toward the observed price by that fraction and shrink the uncertainty.
  4. 4Repeat every bar. The output plots like a moving average whose responsiveness follows the noise settings; two-state versions also emit a velocity estimate that reads as trend slope.

How it's calculated

A recursively updated price estimate that blends each bar's prediction with the newly observed price, weighted by their relative uncertainties.

Priort=Estt1\operatorname{Prior}_t = \operatorname{Est}_{t-1}
PriorVart=Vart1+Q\operatorname{PriorVar}_t = \operatorname{Var}_{t-1} + Q
Kt=PriorVartPriorVart+RK_t = \frac{\operatorname{PriorVar}_t}{\operatorname{PriorVar}_t + R}
Estt=Priort+Kt×(PtPriort)\operatorname{Est}_t = \operatorname{Prior}_t + K_t \times (P_t - \operatorname{Prior}_t)
Vart=(1Kt)×PriorVart\operatorname{Var}_t = (1 - K_t) \times \operatorname{PriorVar}_t
P_t: observed price at bar t (the measurement), typically the close
Est_t: filtered price estimate after the bar t update
Prior_t: predicted estimate carried forward from bar t-1
PriorVar_t: predicted error variance before the update
Var_t: error variance after the update
K_t: Kalman gain, the weight from 0 to 1 given to the new observation
Q: process noise variance, how much the true level is assumed to move per bar (no universal default)
R: measurement noise variance, how noisy prices are around the true level (no universal default)
t: bar index

This is the scalar random-walk form (state transition and observation both equal to 1) used by chart implementations; the general filter runs the same predict and update cycle with state vectors and covariance matrices.

Only the ratio Q / R matters in steady state: raise it for a faster, noisier estimate, lower it for a smoother, laggier one.

Initialize Est_0 to the first price and Var_0 to any positive value; the gain converges to its steady state regardless.

How traders use it

  • As an adaptive baseline: the filtered level serves the familiar moving-average roles (slope color, crossovers, a trailing reference) with responsiveness governed by the noise model rather than a fixed length setting.
  • As a dynamic hedge ratio: modeling the regression slope between two assets as the state lets the ratio update bar by bar, replacing a fixed-window linear regression in spread construction.
  • As a velocity gauge: constant-velocity variants expose the estimated rate of change directly, which some systems use as a trend/chop classifier or a momentum input.
  • As pre-processing: filtering a noisy series before it feeds another indicator trades a little delay for fewer whipsaw flips downstream.

Kalman Filter vs related concepts

EMA: An EMA is effectively a Kalman filter frozen solid: constant gain, no uncertainty tracking. The Kalman recursion recomputes its gain every bar from the modeled variances, so its effective speed floats; in the steady state on a simple level-plus-noise model, the two converge to the same line.

KAMA: Both adapt their speed, but KAMA drives it from an efficiency ratio computed on recent price action, a heuristic. The Kalman gain comes from an explicit noise model. The difference is philosophy and tunability rather than one being reliably better.

Hodrick-Prescott Filter: The HP filter fits the whole sample at once and uses future data, so its historical values change as new bars arrive. A standard Kalman filter is causal: each estimate uses only information available at that bar, which makes it usable for live signals, not just description.

Concept family

Statistics

46 concepts mapped · 46 in the Library

Kalman Filter FAQ

Turn Kalman Filter into a trading strategy.

Take the implementation from this page into Quant, then build on it, backtest it on real data, and keep refining it in conversation.