Kalman Filter Trend
Use a 1D Kalman filter to estimate the latent price trend; trade in the direction of the filter.
Understand what this strategy is actually betting on before you touch the parameter panel.
Read the model brief like a skeptic
Strategy families & selection
Validation & skepticism
The Intuition
The Kalman filter, developed by Rudolf Kálmán (1960), is a recursive Bayesian estimator for the hidden state of a linear dynamical system observed with noise. In trading, we treat the true latent price trend as the hidden state, and the observed price as a noisy measurement of that state. The filter optimally combines the prior state estimate with the new observation, weighted by their relative uncertainties.
The key innovation over simple moving averages: the Kalman gain K(t) is adaptive. When observations are very noisy (high R) relative to the state process noise (Q), K is small — the filter trusts its prior prediction more than the new data. When observations are relatively reliable, K is large — the filter updates heavily on the new price. This makes the Kalman filter a self-calibrating smoother that is optimal in the least-squares sense under Gaussian assumptions.
In equities and futures, the Kalman filter has been used for: (1) Pairs trading — estimating a time-varying hedge ratio between two assets (Chan 2013); (2) Kalman-smoothed trend signals — the filtered state estimate is a more principled trend estimate than a fixed-window moving average; (3) Online regression — the filter can track the OLS relationship between two series in real time without a fixed window.
Key assumptions: (1) The system is linear: the state transition (x(t) = x(t-1) + w) and observation model (z(t) = x(t) + v) are both linear. (2) Noise is Gaussian: process noise w and observation noise v follow normal distributions. (3) Q and R are correctly specified. In practice, these noise variances must be estimated or tuned — wrong values give systematically over- or under-reactive filters. (4) The state dimension is appropriate — our 1D filter tracks a single latent price level; real implementations often use 2D state (level + trend).
The main failure mode: if Q/R is too high (too much trust in the state model), the filter is slow to respond to genuine price moves — it lags badly. If Q/R is too low, the filter is very noisy and essentially tracks the raw price. Tuning Q and R is an empirical problem; many practitioners use expectation-maximisation (EM) algorithms to estimate them from the data. Without careful calibration, Kalman filter trading signals can underperform simple moving averages.
The Math
Read this as a compact model summary: what the signal sees, what it ignores, and where fragility can creep in.
State: x(t) = x(t-1) + w(t), w ~ N(0, Q)
Obs: z(t) = x(t) + v(t), v ~ N(0, R)
Predict: x̂(t|t-1) = x̂(t-1)
P(t|t-1) = P(t-1) + Q
Update: K(t) = P(t|t-1) / (P(t|t-1) + R)
x̂(t) = x̂(t|t-1) + K(t) × (z(t) - x̂(t|t-1))
P(t) = (1 - K(t)) × P(t|t-1)
Signal(t) = +1 if Δx̂(t) > 0 [trend rising]
= -1 if Δx̂(t) < 0 [trend falling]
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| process_noise | float | 0.0001 | Kalman process noise variance (Q) |
| obs_noise | float | 0.01 | Kalman observation noise variance (R) |
Source Code
Live source — fetched from engine/strategies/kalman.py
Further Reading
- Kalman, R. (1960). A New Approach to Linear Filtering and Prediction Problems. ASME Journal of Basic Engineering, 82(1), 35–45.
- Chan, E. (2013). Algorithmic Trading, Ch. 6. Wiley.
- Welch, G. & Bishop, G. (2006). An Introduction to the Kalman Filter. UNC Technical Report TR 95-041.
Related Statistical Strategies
Use nearby strategies to compare the same market hypothesis under different signal constructions.