Kalman Pairs Trading
Statistical-arbitrage on a cointegrated pair of assets, with a time-varying hedge ratio estimated by a Kalman filter on the state-space form of the spread. The strategy enters trades when the recursively-standardised spread breaches a z-score band and exits when it mean-reverts.
Overview
Pairs trading exploits cointegration: two non-stationary price series can be combined linearly into a stationary, mean-reverting spread. The classical Engle-Granger (1987) framework treats the cointegration coefficient as constant, but in practice the relationship between two stocks — especially in emerging markets and across sector regimes — drifts slowly over time. A constant-hedge approach therefore generates large estimation error in the spread, which manifests as systematic losses in stress periods.
The Kalman-filter approach treats the hedge ratio as an unobserved time-varying state and updates it recursively as new prices arrive. Vidyamurthy (2004), Elliott, van der Hoek and Malcolm (2005), and a long line of subsequent work formalise this state-space view. Gatev, Goetzmann and Rouwenhorst (2006) and Krauss (2017) survey the practical evidence. Palomar (2025) Chapter 15, Section 15.6 gives a textbook treatment.
FolioLab implements a one-pair Kalman filter that estimates the time-varying intercept and hedge ratio, computes the recursively-standardised spread (z-score), and emits long/short signals when the z-score breaches user-configurable entry and exit bands.
Mathematical Formulation
State-space model
is the price (or log-price) of the dependent leg of the pair, is the independent leg, and the latent state vector holds the time-varying intercept and hedge ratio. The state evolves as a random walk; the magnitude of controls how fast the hedge ratio is allowed to drift.
Kalman recursions
For each new observation, the filter performs a predict step and an update step. With state estimate and state covariance :
Here . The innovation is the one-step-ahead spread: it is the standardised quantity used to generate trading signals.
Signal rule
Standardising the innovation by its predictive variance yields a recursively-standardised z-score. Open a short-spread trade when , open a long-spread trade when , and close the trade when . Typical thresholds are and .
Choosing the pair
Pair selection precedes the Kalman step. Standard tests are Engle-Granger cointegration (regression of one log-price on the other and an ADF test on the residuals; see Dickey and Fuller, 1979) and Johansen's system test for cointegration. On Indian equities, sector-pair candidates are typically the two majors in a duopoly (HDFC Bank / ICICI Bank, Reliance / ONGC for energy, Maruti / M&M for autos) or the two most liquid names in a tightly cointegrated industrial cluster.
Half-life of mean reversion (Ornstein-Uhlenbeck or AR(1) framework; see Lo and MacKinlay, 1988) is the diagnostic that tells you whether a pair is tradeable: a half-life of a few days to a few weeks is workable; multi-month half-lives are too slow to support a stat-arb book.
Advantages & Limitations
Advantages
- Time-varying hedge: Captures slow drift in the cointegration coefficient.
- Recursive standardisation: Z-score adapts to changing innovation variance.
- Market-neutral: Long-short structure neutralises broad market beta.
- Computationally cheap: Kalman recursions are O(1) per step.
Limitations
- Cointegration breakdowns: Structural breaks invalidate the spread.
- Hyperparameters Q, R: Drift speed and observation noise must be calibrated.
- Single-pair scope: Doesn't scale natively to multi-asset stat-arb baskets.
- Borrow constraints: Indian short-selling has frictions that erode the strategy edge.
References
- Engle, R. F., & Granger, C. W. J. (1987). "Co-integration and Error Correction: Representation, Estimation, and Testing." Econometrica, 55(2), 251-276.
- Kalman, R. E. (1960). "A New Approach to Linear Filtering and Prediction Problems." Journal of Basic Engineering, 82(1), 35-45.
- Gatev, E., Goetzmann, W. N., & Rouwenhorst, K. G. (2006). "Pairs Trading: Performance of a Relative-Value Arbitrage Rule." The Review of Financial Studies, 19(3), 797-827.
- Vidyamurthy, G. (2004). Pairs Trading: Quantitative Methods and Analysis. John Wiley & Sons.
- Elliott, R. J., Van Der Hoek, J., & Malcolm, W. P. (2005). "Pairs Trading." Quantitative Finance, 5(3), 271-276.
- Krauss, C. (2017). "Statistical Arbitrage Pairs Trading Strategies: Review and Outlook." Journal of Economic Surveys, 31(2), 513-545.
- Dickey, D. A., & Fuller, W. A. (1979). "Distribution of the Estimators for Autoregressive Time Series with a Unit Root." Journal of the American Statistical Association, 74(366a), 427-431.
- Lo, A. W., & MacKinlay, A. C. (1988). "Stock Market Prices Do Not Follow Random Walks." The Review of Financial Studies, 1(1), 41-66.
- Palomar, D. P. (2025). Portfolio Optimization: Theory and Application. Cambridge University Press, Chapter 15 (Pairs Trading Portfolios), Section 15.6 (Kalman Filtering for Pairs Trading).