Skip to content
LeetQuant
E07 Advanced Time Series

E07 · Advanced Time Series · Lesson 1 of 4

State-Space Models

The state and observation equations, why one framework covers ARMA, unobserved-component and time-varying-coefficient models, and how to write AR(p), ARMA(1,1), the local level and a time-varying regression in state-space form.

15 min

Objective

The ARMA and GARCH lessons modelled the observed series directly. Many quantities a researcher cares about are never observed: the "true" price under microstructure noise, a fair-value spread, a drifting hedge ratio, a latent factor. A state-space model separates what is hidden (the state) from what is measured (the observation). This lesson sets up the framework and the standard rewrites; the next lesson filters it.

The two equations

The linear Gaussian state-space model has a state vector αt\alpha_t (dimension mm) and observations yty_t (dimension pp):

state:αt=c+T αt−1+R ηt,ηt∼N(0,Q),observation:yt=d+Zt αt+εt,εt∼N(0,H),\begin{aligned} \text{state:} \quad & \alpha_t = c + T\,\alpha_{t-1} + R\,\eta_t, & \eta_t &\sim N(0, Q), \\ \text{observation:} \quad & y_t = d + Z_t\,\alpha_t + \varepsilon_t, & \varepsilon_t &\sim N(0, H), \end{aligned}

with ηt\eta_t and εt\varepsilon_t independent of each other and over time. TT is the transition matrix, ZtZ_t the design (loading) matrix, QQ and HH the state and observation noise covariances. Any of the matrices may vary with tt as long as they are known at time tt; a time-varying ZtZ_t is what makes time-varying regressions possible.

Two facts follow directly:

  • The state is Markov. Everything the past says about the future passes through αt\alpha_t. That is what makes a one-step recursive filter possible.
  • Stationarity is about TT. If every eigenvalue of TT has modulus below 1, the state has a stationary distribution with mean (I−T)−1c(I - T)^{-1}c and covariance PP solving the discrete Lyapunov equation P=TPT′+RQR′P = TPT' + RQR' (take the variance of both sides of the state equation). With a unit eigenvalue (random-walk states) there is no stationary distribution and the filter needs a diffuse start.

The representation is not unique: any invertible change of variables α~t=Mαt\tilde\alpha_t = M\alpha_t gives an observationally equivalent model. So the state has meaning only through the structure you impose on it.

Standard forms

AR(pp): the companion form. Stack the last pp values into the state. For AR(2), Xt=ϕ1Xt−1+ϕ2Xt−2+εtX_t = \phi_1 X_{t-1} + \phi_2 X_{t-2} + \varepsilon_t:

αt=(XtXt−1),T=(ϕ1ϕ210),R=(10),Z=(10),H=0.\alpha_t = \begin{pmatrix} X_t \\ X_{t-1} \end{pmatrix}, \quad T = \begin{pmatrix} \phi_1 & \phi_2 \\ 1 & 0 \end{pmatrix}, \quad R = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad Z = \begin{pmatrix} 1 & 0 \end{pmatrix}, \quad H = 0 .

The second row only shifts Xt−1X_{t-1} down. The eigenvalues of TT are the inverse roots λ\lambda of λ2−ϕ1λ−ϕ2=0\lambda^2 - \phi_1\lambda - \phi_2 = 0, so "stationary iff eigenvalues inside the unit circle" is the same condition as in the ARMA lesson. All the noise is in the state; the observation is exact.

ARMA(1,1). Xt=ϕXt−1+εt+θεt−1X_t = \phi X_{t-1} + \varepsilon_t + \theta\varepsilon_{t-1} fits in a two-dimensional state:

αt=(Xtθεt),T=(ϕ100),R=(1θ),Z=(10).\alpha_t = \begin{pmatrix} X_t \\ \theta\varepsilon_t \end{pmatrix}, \quad T = \begin{pmatrix} \phi & 1 \\ 0 & 0 \end{pmatrix}, \quad R = \begin{pmatrix} 1 \\ \theta \end{pmatrix}, \quad Z = \begin{pmatrix} 1 & 0 \end{pmatrix} .

Check the first row: Xt=ϕXt−1+θεt−1+εtX_t = \phi X_{t-1} + \theta\varepsilon_{t-1} + \varepsilon_t. In general an ARMA(p,qp, q) needs a state of dimension max⁡(p,q+1)\max(p, q + 1). This is how statsmodels' SARIMAX computes exact ARMA likelihoods, with missing values handled for free.

Local level (random walk plus noise). The workhorse for a noisy, drifting quantity:

yt=μt+εt,εt∼N(0,r);μt=μt−1+ηt,ηt∼N(0,q).y_t = \mu_t + \varepsilon_t, \quad \varepsilon_t \sim N(0, r); \qquad \mu_t = \mu_{t-1} + \eta_t, \quad \eta_t \sim N(0, q) .

Scalar state, T=Z=1T = Z = 1. Everything depends on the signal-to-noise ratio s=q/rs = q/r. With q=0q = 0 the level is a constant and the best estimate is the sample mean; with r=0r = 0 the series is an exactly observed random walk and the best estimate is the latest observation. Adding a slope state νt\nu_t (μt=μt−1+νt−1+ηt\mu_t = \mu_{t-1} + \nu_{t-1} + \eta_t, νt=νt−1+ζt\nu_t = \nu_{t-1} + \zeta_t) gives the local linear trend.

Time-varying regression. Let the coefficients be the state and the regressors the design:

yt=(1xt)(atbt)+εt,(atbt)=(at−1bt−1)+ηt.y_t = \begin{pmatrix} 1 & x_t \end{pmatrix}\begin{pmatrix} a_t \\ b_t \end{pmatrix} + \varepsilon_t, \qquad \begin{pmatrix} a_t \\ b_t \end{pmatrix} = \begin{pmatrix} a_{t-1} \\ b_{t-1} \end{pmatrix} + \eta_t .

So T=IT = I, Zt=(1,xt)Z_t = (1, x_t) changes every period, and QQ sets how fast the intercept and beta may drift. With Q=0Q = 0 the coefficients are constant and the filter reproduces recursive (expanding-window) OLS. A positive QQ discounts old data smoothly, replacing the arbitrary window length of rolling OLS with a parameter that can be estimated by maximum likelihood. The last lesson of this module uses it for a hedge ratio.

Worked example

the AR(2) companion form and its stationary covariance

Write Xt=0.9Xt−1−0.2Xt−2+εtX_t = 0.9X_{t-1} - 0.2X_{t-2} + \varepsilon_t (σ2=1\sigma^2 = 1) in companion form. Is it stationary? Find Var⁡(Xt)\operatorname{Var}(X_t) and ρ1\rho_1 from the Lyapunov equation, and check against Yule–Walker.

Show solution

Form. T=(0.9−0.210)T = \begin{pmatrix} 0.9 & -0.2 \\ 1 & 0 \end{pmatrix}, RQR′=(1000)RQR' = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}, Z=(1,0)Z = (1, 0).

Stationarity. The characteristic equation of TT is λ2−0.9λ+0.2=0\lambda^2 - 0.9\lambda + 0.2 = 0, so λ=0.5\lambda = 0.5 and 0.40.4. Both are inside the unit circle: stationary.

Stationary covariance. Write P=(γ0γ1γ1γ0)P = \begin{pmatrix} \gamma_0 & \gamma_1 \\ \gamma_1 & \gamma_0 \end{pmatrix} (both state entries have the same variance). Multiplying out P=TPT′+RQR′P = TPT' + RQR':

  • Entry (1,2): γ1=0.9γ0−0.2γ1\gamma_1 = 0.9\gamma_0 - 0.2\gamma_1, so γ1=0.75 γ0\gamma_1 = 0.75\,\gamma_0.
  • Entry (1,1): γ0=0.81γ0−0.36γ1+0.04γ0+1\gamma_0 = 0.81\gamma_0 - 0.36\gamma_1 + 0.04\gamma_0 + 1. Substituting, γ0(1−0.85+0.27)=1\gamma_0(1 - 0.85 + 0.27) = 1, so γ0=1/0.42=2.381\gamma_0 = 1/0.42 = 2.381.

Hence γ1=1.786\gamma_1 = 1.786 and ρ1=0.75\rho_1 = 0.75. Yule–Walker agrees: ρ1=ϕ1/(1−ϕ2)=0.9/1.2=0.75\rho_1 = \phi_1/(1 - \phi_2) = 0.9/1.2 = 0.75, ρ2=0.9(0.75)−0.2=0.475\rho_2 = 0.9(0.75) - 0.2 = 0.475, γ0=1/(1−0.9×0.75+0.2×0.475)=1/0.42\gamma_0 = 1/(1 - 0.9 \times 0.75 + 0.2 \times 0.475) = 1/0.42.

In code, the Lyapunov equation is one call:

import numpy as np
from scipy.linalg import solve_discrete_lyapunov

# AR(2) X_t = 0.9 X_{t-1} - 0.2 X_{t-2} + e_t, sigma^2 = 1, in companion form
T = np.array([[0.9, -0.2],
              [1.0,  0.0]])
RQR = np.array([[1.0, 0.0],
                [0.0, 0.0]])
print("eigenvalues:", np.linalg.eigvals(T))
P = solve_discrete_lyapunov(T, RQR)   # solves P = T P T' + RQR'
print(np.round(P, 4))
print("rho1 =", round(P[0, 1] / P[0, 0], 4))

Output:

eigenvalues: [0.5 0.4]
[[2.381  1.7857]
 [1.7857 2.381 ]]
rho1 = 0.75

The same call gives the stationary covariance of any stationary state, which is how a filter is initialised for stationary components.

Worked example

what the local level model implies for the data

For the local level model with q=1q = 1 and r=4r = 4, find the autocorrelation function of Δyt=yt−yt−1\Delta y_t = y_t - y_{t-1}. Which ARIMA model is this, and what are its MA coefficient and innovation variance?

Show solution

Difference the observation equation: Δyt=ηt+εt−εt−1\Delta y_t = \eta_t + \varepsilon_t - \varepsilon_{t-1}.

  • Var⁡(Δyt)=q+2r=9\operatorname{Var}(\Delta y_t) = q + 2r = 9.
  • Cov⁡(Δyt,Δyt−1)=−r=−4\operatorname{Cov}(\Delta y_t, \Delta y_{t-1}) = -r = -4 (only εt−1\varepsilon_{t-1} is shared).
  • Covariances at lag 2 and beyond are zero.

So Δyt\Delta y_t is an MA(1) with ρ1=−r/(q+2r)=−4/9≈−0.444\rho_1 = -r/(q + 2r) = -4/9 \approx -0.444, and yty_t is an ARIMA(0,1,1). Solve θ/(1+θ2)=−4/9\theta/(1 + \theta^2) = -4/9, i.e. 4θ2+9θ+4=04\theta^2 + 9\theta + 4 = 0; the invertible root is θ=(−9+17)/8≈−0.610\theta = (-9 + \sqrt{17})/8 \approx -0.610. The innovation variance follows from σ2(1+θ2)=9\sigma^2(1 + \theta^2) = 9: σ2=9/1.372≈6.56\sigma^2 = 9/1.372 \approx 6.56.

Two lessons from this:

  • ρ1\rho_1 always lies in [−0.5,0][-0.5, 0]: the local level model can only produce negative first-order autocorrelation in changes, the signature of noise around a random walk (bid–ask bounce on a mid-price is the classic case). If the data show positive ρ1\rho_1 in changes, this model is wrong for them.
  • The ARIMA(0,1,1) forecast is exponential smoothing with weight 1+θ≈0.3901 + \theta \approx 0.390 on the newest observation. The next lesson derives the same number as the steady-state Kalman gain, and 6.566.56 as the steady-state innovation variance: the two descriptions are the same model.

Why bother with state space

  • One algorithm for everything. Once a model is in this form, the Kalman filter gives filtered states, forecasts with error variances, and the exact Gaussian likelihood. Estimation is then numerical optimisation over the few parameters in T,Q,HT, Q, H.
  • Missing and irregular data. A missing observation means skipping the update step; the prediction step carries the state forward. No interpolation, no dropping rows.
  • Interpretability. Components (level, trend, cycle, seasonal, time-varying beta) are explicit states you can plot, rather than implied by ARMA coefficients.

Limits. Linear-Gaussian structure is an assumption: fat-tailed noise makes the filter over-react to outliers, and nonlinear observation equations (prices observed through an option pricing formula, say) need extended or unscented filters or particle filters. Parameters such as q/rq/r are often weakly identified in short samples, and the likelihood can pile up at q=0q = 0.

In an interview

"Put X in state-space form" is a standard question. Say out loud what the state is (the smallest set of quantities that makes the future independent of the past), then write TT, RR, ZZ and say which noise lives where. Check the first row reproduces the model. Mention that stationarity is read from the eigenvalues of TT.

Knowledge check

In the local level model yt=μt+εty_t = \mu_t + \varepsilon_t, μt=μt−1+ηt\mu_t = \mu_{t-1} + \eta_t, what is the lag-1 autocorrelation of Δyt\Delta y_t when q=Var⁡(ηt)=2q = \operatorname{Var}(\eta_t) = 2 and r=Var⁡(εt)=1r = \operatorname{Var}(\varepsilon_t) = 1?

Knowledge check

You write a regression with a drifting intercept and beta in state-space form. What are the transition matrix T and the design Z_t?

Knowledge check

An AR(3) is written in companion form. Which statement is correct?

Key takeaways

  • State equation αt=c+Tαt−1+Rηt\alpha_t = c + T\alpha_{t-1} + R\eta_t, observation yt=d+Ztαt+εty_t = d + Z_t\alpha_t + \varepsilon_t; the state is Markov and stationarity is read from the eigenvalues of TT.
  • The stationary state covariance solves P=TPT′+RQR′P = TPT' + RQR'.
  • AR(pp) uses the companion form; ARMA(p,qp,q) needs a state of size max⁡(p,q+1)\max(p, q+1); the local level is random walk plus noise; a time-varying regression has T=IT = I and Zt=(1,xt)Z_t = (1, x_t).
  • The local level model equals ARIMA(0,1,1) with ρ1(Δy)=−r/(q+2r)∈[−0.5,0]\rho_1(\Delta y) = -r/(q+2r) \in [-0.5, 0]; its behaviour is governed by the signal-to-noise ratio q/rq/r.
  • State space buys one filter for likelihood, forecasts and missing data, at the price of linear-Gaussian assumptions and often weakly identified variance parameters.

Practice problems

Finished reading?

Answer the 3 knowledge checks to complete this lesson (0 done).