1. What forecasting is
A forecast is a statement about what is likely to happen. It is used for sales, weather, inflation, elections, sport, epidemics and asset returns. The horizon runs from milliseconds (high-frequency trading) to years.
Why forecasting is hard
- Sources of difficulty: we don’t know the dynamics, information is missing, data are scarce or noisy, or the phenomenon is simply unpredictable. Major earthquakes have never been predicted more than minutes ahead.
- Randomness vs ignorance: a coin flip is random to a probabilist (we can learn p, not the next outcome), but in physics it is deterministic given enough information about the throw.
- Feedback: forecasts can change the thing being forecast. Sales forecasts trigger marketing spend. Inflation forecasts move central-bank rates. In markets, every participant is a forecaster, and their trades set the prices being predicted.
- Spurious predictors: Google Flu Trends leaned on searches that were only seasonally correlated with flu (e.g. high-school basketball). It missed the 2012–13 outbreak once the seasonal link broke.
- Communication: a forecast only helps if decision-makers act on it in time. The 2021 floods in Belgium and Germany were forecast days ahead, but the alerts were not acted on.
Input and output
- Input: historical data (past values of the target and of related series) plus knowledge, which drives both data selection and model choice.
- Point forecast: a single number. You score it by its error once the outcome is known. Before that, you validate it on held-out data you already have.
- Uncertainty: a ± standard deviation, or a prediction interval with a stated coverage (a 95% interval should contain the outcome 95% of the time).
- Predictive distribution: the full law of the future value. It answers questions like “P(value > threshold)”. It is drawn as a fan chart (e.g. Bank of England inflation fans) and scored with scoring rules.
Accuracy under one loss (e.g. MSE) is not the only goal. Methods produce different kinds of output. Decision-makers often need the full distribution of risks. They may also prefer a slightly less accurate model that is interpretable and easier to defend.
What makes data a time series
All data are collected at some time. We call data a time series when the time order matters to the question. Examples: J&J quarterly EPS (trend, seasonality, growing variance), the Nile’s annual flow, sunspots (cycles), daily bank-stock returns (volatility clusters).
- Beyond univariate: multivariate series / vector processes, panel data (many individuals over time), spatio-temporal data.
- Features to look for: trend, seasonality, and constant variance (homoskedastic) vs changing variance (heteroskedastic). Always start with a trace plot.
- The core difficulty: observations are dependent. A series is one trajectory, not an i.i.d. sample, so the usual LLN/CLT arguments don’t apply directly. The fix is to transform the data until they look stationary. That brings back an underlying fixed distribution to learn, and it is also why the bootstrap and cross-validation need adapting for time series.
2. Probability toolkit
Random variables
A random variable represents uncertainty. It takes values (realisations) in a state space, each with a probability. You can define one in two equivalent ways:
- By construction from known variables, e.g. X = −log U with U ~ Uniform(0,1) gives Exponential(1). This is also how you simulate it.
- By a density fX, with P(X ∈ (a,b)) = ∫ab fX(x) dx.
Change of variable (s one-to-one, Y = s(X)): f_Y(y) = f_X(s⁻¹(y)) · | d s⁻¹(y) / dy |Expectation and variance
- E[X] = ∫ x fX(x) dx. It can be infinite: a Cauchy variable has no mean.
- Linearity: E[aX + bY] = aE[X] + bE[Y]. No independence needed.
- V[X] = E[(X − E X)²] = E[X²] − E[X]², and V[aX + b] = a²V[X].
- Normal(μ, σ²) density φ(x) = (2πσ²)−1/2 exp(−(x−μ)²/2σ²). Simulate it with Box–Muller: Z = √(−2 log U₁) cos(2πU₂), then X = μ + σZ.
Two variables
- Independence: the joint density factorises, fX,Y = fX fY. Then E[XY] = E[X]E[Y], and g(X), h(Y) are independent too.
- Conditioning: fX,Y(x,y) = fX(x) fY|X(y|x), so fY|X = fX,Y / fX.
- Tower property: E[Y] = E[E[Y | X]]. This is one of the most used identities in the course.
- Covariance: Cov(X,Y) = E[XY] − E[X]E[Y]. It is symmetric, bilinear and unchanged by shifts, and Cov(X,X) = V[X].
- Correlation: Cor = Cov / √(V[X]V[Y]) ∈ [−1, 1] (by Cauchy–Schwarz). It equals ±1 only if Y = aX + b. It is unit-free, and it measures linear association only.
X symmetric around 0 and Y = X². X determines Y completely, yet Cov(X, Y) = E[X³] − E[X]E[X²] = 0. Independence ⇒ uncorrelated, but not the other way round. Exception: for jointly Normal variables, ρ = 0 ⇔ independent.
Multivariate Normal(μ, Σ): simulate it as X = μ + LZ with LLᵀ = Σ (Cholesky) and Z standard Normal.
Averages and convergence
LLN: X̄ₙ = (1/n) Σ Xₜ → E[X] almost surely (i.i.d., E|X| < ∞)Chebyshev: P(|X̄ₙ − E X| > ε) ≤ V[X] / (n ε²) (non-asymptotic, every n)CLT: √n (X̄ₙ − E X) → Normal(0, V[X]) in distributionThe empirical covariance is (1/n) Σ (xₜ − x̄)(yₜ − ȳ) and the empirical correlation is its normalised version. Replacing expectations with sample averages is the move behind almost every estimator that follows. The open question is whether LLN and CLT survive dependence (§7 says yes, under conditions).
3. Plot, transform, decompose
The course keeps two tasks side by side. Task 1 (time series): predict yn+1 from y1:n. Task 2 (regression): predict yn+1 from a new xn+1 and past pairs (xₜ, yₜ).
Visualise first
- Trace plot: yₜ against t.
- Scatter plot of one series against another (yₜ vs xₜ).
- Seasonal plot: cut the series by season and overlay the pieces, or use a seasonal-subseries plot.
Adjustments and transformations
- Adjustments: common-sense fixes such as calendar (days per month), population (per capita) and inflation (real vs nominal).
- Log: for positive series. It tells exponential from polynomial trends apart and stabilises the variance.
- Differencing: ∇yₜ = yₜ − yₜ₋₁ removes trends. It can be iterated (∇²). Seasonal differencing is yₜ − yₜ₋ₘ. Log-differences ∇log yₜ ≈ growth rates (e.g. GDP growth, log-returns).
- Back-transform the forecasts carefully if you care about the original scale.
- Others: moving-window averages, standardising, winsorising, unit conversion. Choosing the representation is a craft, essentially feature engineering.
Moving averages and decomposition
Moving average of order m = 2k+1: ỹₜ = (1/m) Σ_{j=−k..k} y_{t+j}For even m the window is asymmetric. You can weight the window or take moving averages of moving averages.
Additive decomposition: yₜ = ỹₜ (trend) + sₜ (seasonal, sₜ = s_{t+m}, centred) + rₜ (remainder)- The seasonally adjusted series is yₜ − sₜ.
- Apply the decomposition to log yₜ when seasonal swings grow with the level (e.g. the airline-passenger series).
- Standard methods: X-11, SEATS, STL.
- One way to forecast: predict each component separately, then recombine.
4. Baselines & exponential smoothing
Expert and crowd forecasts
Domain experts, the Delphi method (iterated expert consensus) and prediction markets (the wisdom of crowds).
Two baselines
- Average: ŷn+1 = (1/n) Σ yₜ. The whole past is equally relevant.
- Last value (naïve): ŷn+1 = yₙ. Only the latest point matters. This is the random-walk forecast.
Both are weighted averages Σ wₜyₜ with Σ wₜ = 1. They differ only in how much weight the past gets.
Simple exponential smoothing
This interpolates between the two baselines, with geometrically decaying weights:
ŷ_{n+1} = α yₙ + α(1−α) y_{n−1} + α(1−α)² y_{n−2} + … (α ∈ [0,1])recursive form: ŷ_{t+1} = α yₜ + (1 − α) ŷₜ (choose α and ŷ₁)The weakness: every horizon gets the same forecast, so the forecast is a flat line, ŷn+h = ŷn+1.
Holt–Winters: add trend and seasonality
ŷ_{t+h} = ℓₜ + h bₜ
ℓₜ = α yₜ + (1−α)(ℓ_{t−1} + b_{t−1}) (level)
bₜ = γ (ℓₜ − ℓ_{t−1}) + (1−γ) b_{t−1} (slope)Add a third equation for a seasonal term. Holt–Winters dates from the late 1950s and is still widely used (e.g. extrapolating the Mauna Loa CO₂ series). As written it is deterministic: no intervals, no distribution. Viewed as an ARIMA / state-space model (§12, §13), it gains prediction intervals.
Least-squares regression (Task 2)
min_{α,β} Σ (yₜ − α − β xₜ)² ⇒ β̂ = Σ(xₜ−x̄)(yₜ−ȳ) / Σ(xₜ−x̄)², α̂ = ȳ − β̂ x̄Forecast with α̂ + β̂ xn+1. β̂ is close to the sample covariance scaled by the variance of x. This is still a deterministic recipe until we add a probability model, which is also what lets you bootstrap the uncertainty of the fitted line.
5. Probabilistic prediction
The big step: treat the data y1:n as realisations of random variables Y1:n. Then build the conditional distribution of Yn+1 given what was observed.
- Loss function L(c, y) scores a guess c against the outcome y. Squared loss: (y − c)².
- Best constant guess under MSE: c = E[Y]. This justifies the “average” baseline.
- Best guess given X: expand the square with the tower property:
E[(Y − c(X))²] = E[ E[(Y − E[Y|X])² | X] ] + E[(c(X) − E[Y|X])²] ⇒ c*(X) = E[Y | X]Under squared loss the optimal forecast is the conditional expectation. Every model in this note is a way of approximating E[Yn+h | data].
- Estimating E[Y|X] in full is nonparametric regression. Restricting to the best linear predictor α + βX gives the normal equations E[Y − α − βX] = 0 and E[X(Y − α − βX)] = 0:
β* = Cov(X, Y) / V[X], α* = E[Y] − β* E[X]Plugging in sample moments gives OLS back. OLS is now an estimate of a population quantity, so it has an approximation error you can study. Lesson: state an objective (expected loss), then derive the method. Swap MSE for a scoring rule and you get probabilistic forecasts.
6. Statistical models
A model is a plausible probabilistic description of the data, with parameters. The workflow: estimate the parameters, then plug them in to predict. A good model captures the key features and stays simple: less overfitting, cheaper to fit, easier to interpret.
Linear regression as a model
Yₜ = α + β xₜ + εₜ, E[εₜ] = 0, Cov(εₜ, εₛ) = 0 (t ≠ s)These assumptions are what justify confidence and prediction intervals. Fully specified: Yₜ ~ind Normal(α + βxₜ, σ²).
- Likelihood = model density evaluated at the observed data, read as a function of the parameters: Π dnorm(yₜ; α + βxₜ, σ).
- Maximising it gives exactly OLS for (α, β), plus σ̂², which you need for prediction intervals.
- The method is flexible: swap the residual law (Laplace, Student-t) and still maximise. MLEs have good general properties.
First time-series models
Random walk with drift: Yₜ = δ + Yₜ₋₁ + Wₜ, Wₜ ~ i.i.d. Normal(0, σ²)Yₜ = (t−1)δ + Σ Wₛ, so E[Yₜ] = (t−1)δ and V[Yₜ] = tσ². The Yₜ are dependent, yet the likelihood is still computable. Prediction intervals widen with the horizon.
AR(1): Yₜ = δ + ρ Yₜ₋₁ + Wₜρ = 1 gives the random walk. It is like regressing Yₜ on Xₜ = Yₜ₋₁. Behaviour changes sharply between |ρ| < 1, ρ = 1 and |ρ| > 1; simulate all three to see it.
7. Stationarity & correlograms
The problem
For a process (Yₜ) define γ(s,t) = Cov(Yₛ, Yₜ) and ρ(s,t) = Cor(Yₛ, Yₜ). Two obstacles stand in the way of estimating them:
- We see one value of Yₜ at each t, so we cannot average over repeated draws of Yₜ.
- There are ~n² covariances and only n observations.
The resolution is to assume structure shared across time.
Weak stationarity
- E[Yₜ] = μ, constant and finite.
- V[Yₜ] is finite and constant, and γ(s,t) depends only on the lag |t − s|.
γ(h) = Cov(Y₁, Y₁₊ₕ), ρ(h) = γ(h) / γ(0)Now each lag h gives n − h usable pairs. White noise is a stationary process with γ(h) = 0 for h ≠ 0: uncorrelated, mean zero, constant variance.
Ergodic theorem (LLN for stationary processes)
Ȳ is always unbiased for μ, but stationarity alone doesn’t make V[Ȳ] → 0. You also need short memory:
If (Yₜ) is stationary and γ(h) → 0 as h → ∞, then (1/n) Σ Yₜ → μ in probability.Time averages converge to population averages. CLTs and concentration inequalities exist for stationary processes too, so the i.i.d. assumption can be relaxed a lot.
Sample ACF and PACF
γ̂(h) = (1/n) Σ_{t=1..n−h} (yₜ − ȳ)(y_{t+h} − ȳ), ρ̂(h) = γ̂(h) / γ̂(0)- Dividing by n (not n − h) is simpler and keeps the autocovariance non-negative definite.
- ACF / autocorrelogram: ρ̂(h) against h ≥ 0 (with ρ̂(0) = 1). It measures linear association between Yₜ and Yₜ₊ₕ.
- Lag plot: y1+h:n vs y1:n−h. It shows the whole relation, where the ACF reduces each lag to one number.
- PACF α(h): correlation between Yₜ and Yₜ₋ₕ after removing the effect of the lags in between. It equals the last coefficient ch,h in the regression of Yₜ on Yₜ₋₁…Yₜ₋ₕ. Equivalently, it is the correlation between the residuals of Yₜ and of Yₜ₋ₕ, each regressed on the intermediate lags. α(1) = ρ(1).
Residuals from a regression of LA cardiovascular mortality on trend, temperature and particulates. The ACF tails off and the PACF cuts off after lag 2, which suggests an AR(2) for the residuals.
8. Autoregressive models
AR(p): Yₜ = φ₁Yₜ₋₁ + … + φₚYₜ₋ₚ + Wₜ ⇔ φ(B) Yₜ = Wₜ, φ(z) = 1 − φ₁z − … − φₚzᵖB is the backshift operator: BYₜ = Yₜ₋₁ and BᵏYₜ = Yₜ₋ₖ. Wₜ is white noise with variance σ²W. Allow a mean with φ(B)(Yₜ − μ) = Wₜ.
When is an AR process stationary?
- Coefficients: AR(1) needs |φ₁| < 1. AR(p) needs every (complex) root of φ(z) to lie outside the unit circle, |λⱼ| > 1.
- Initial law: starting at Y₀ = 0 is not stationary. For AR(1) you need E[Y₀] = 0 and V[Y₀] = σ²W / (1 − φ₁²). Or picture the process having started infinitely long ago.
AR(1) from κ steps back: V[Yₜ] = φ₁^{2κ} V[Yₜ₋κ] + σ²_W (1 − φ₁^{2κ}) / (1 − φ₁²) → σ²_W / (1 − φ₁²)MA(∞) representation (linear process)
Yₜ = Σ_{j≥0} φ₁ʲ Wₜ₋ⱼ (AR(1), |φ₁| < 1); generally Yₜ = Σ ψⱼ Wₜ₋ⱼ with Σ|ψⱼ| < ∞This holds for any AR(p) whose roots lie outside the unit circle. The ψⱼ come from inverting φ (R: ARMAtoMA).
Correlograms of AR
γ(h) = σ²_W Σ_{k≥0} ψₖ ψₖ₊ₕ AR(1): ρ(h) = φ₁ʰ- ACF tails off smoothly (geometrically for AR(1)). R:
ARMAacf. - PACF cuts off after lag p: given Yₜ₋₁…Yₜ₋ₚ, the older lags add nothing.
Estimation
- Yule–Walker (method of moments): multiply the model by Yₜ₋ₕ and take expectations. That gives p + 1 equations in p + 1 unknowns. Plug in γ̂ and solve:
γ(h) = Σᵢ φᵢ γ(h − i) (h = 1..p), σ²_W = γ(0) − Σᵢ φᵢ γ(i)- Maximum likelihood (usually more efficient): with Gaussian noise, factor the joint density into conditionals,
p(y₁…yₙ) = Πₜ Normal(yₜ; Σⱼ φⱼ yₜ₋ⱼ, σ²_W) × p(y₁…yₚ)Dropping the initial term p(y₁…yₚ) gives the conditional likelihood, which barely matters when p ≪ n. Then maximise numerically.
9. MA & ARMA models
MA(q)
Yₜ = Wₜ + θ₁Wₜ₋₁ + … + θ_qWₜ₋q = θ(B) Wₜ, θ(z) = 1 + θ₁z + … + θ_q z^q- The name comes from a weighted average of the last q + 1 shocks, a window that moves forward in time. Dependence comes from shared shocks.
- Always stationary, mean zero, and no initial distribution needed.
- Invertible (roots of θ outside the unit circle) ⇒ AR(∞) representation Σ πⱼYₜ₋ⱼ = Wₜ.
γ(h) = σ²_W Σ_{j=0..q−h} θⱼ θⱼ₊ₕ for h ≤ q, γ(h) = 0 for h > q| AR(p) | MA(q) | ARMA(p,q) | |
|---|---|---|---|
| ACF | Tails off | Cuts off after lag q | Tails off |
| PACF | Cuts off after lag p | Tails off | Tails off |
Why MA is harder to estimate
- Moments: for MA(1), ρ(1) = θ/(1+θ²), which is a quadratic in θ. It has 0, 1 or 2 solutions, and none if |ρ̂(1)| > 0.5.
- Likelihood: Yₜ is written in terms of unobserved shocks, so there is no simple conditional density. Options: truncate the AR(∞) form, build the full n×n covariance Σ and evaluate an n-dimensional Normal, or (the efficient way) use the Kalman filter (§13).
ARMA(p, q)
φ(B) Yₜ = θ(B) WₜThe restrictions keep the model identifiable:
- φₚ ≠ 0 and θ_q ≠ 0.
- Both φ and θ are invertible, so MA(∞) and AR(∞) forms both exist.
- No common roots. Otherwise white noise Yₜ = Wₜ also solves Yₜ − aYₜ₋₁ = Wₜ − aWₜ₋₁ for any a.
Estimate by maximum likelihood (evaluated with the Kalman filter) plus numerical optimisation. That is what R’s arima does.
Wold representation theorem
Any zero-mean weakly stationary process: Yₜ = Σ_{j≥0} dⱼ εₜ₋ⱼ + ηₜ, Σ dⱼ² < ∞Here εₜ is white noise and ηₜ is a deterministic part, predictable from the past and uncorrelated with the shocks. So linear processes can represent any weakly stationary process, but with infinitely many coefficients. ARMA is the parsimonious subclass: p + q + 1 parameters, with dⱼ decaying geometrically and no ηₜ. That balance is why it is the workhorse.
10. Model selection
Visual identification
Read the ACF and PACF against the table above. This fails when both tail off (or both cut off), which is common with real data (e.g. sunspots).
Information criteria
Occam’s razor in numbers: fit (the maximised log-likelihood) minus a penalty for complexity. Choose the smallest value. Let k = p + q + 1.
AIC = −2 log L̂ + 2k
AICc = −2 log L̂ + 2kn / (n − k − 1) (small samples; → AIC as n grows)
BIC = −2 log L̂ + k log n (heavier penalty ⇒ simpler models)auto.arima(forecast package) searches a grid of (p, q) or steps up from simple models until the criterion stops improving.- ICs need no train/test split, which helps with short series. With long series, comparing out-of-sample accuracy is simpler and more direct.
- The methods can disagree. On sunspots: AIC → ARMA(7,7), BIC → ARMA(9,0), test MSE → ARMA(7,3). All three agree that pure MA does badly.
- Selection vs averaging: you don’t have to pick one model. Forecast combination (§14) is often better.
11. Forecasting with ARMA
Write Yn+h|n = E[Yn+h | Y−∞…n], the MSE-optimal forecast. Use the AR(∞) form for the point forecast and the MA(∞) form for its error (π₀ = ψ₀ = 1).
Point: Y_{n+h|n} = − Σ_{j=1..h−1} πⱼ Y_{n+h−j|n} − Σ_{j≥h} πⱼ Y_{n+h−j} (recursive in h; truncate at the data)Future shocks have conditional mean 0. Past shocks are known exactly from past Y. Hence Yn+h|n = Σj≥h ψⱼ Wn+h−j, and:
MSE: E[(Y_{n+h} − Y_{n+h|n})²] = σ²_W Σ_{j=0..h−1} ψⱼ²- Forecast ± z · √MSE gives prediction intervals.
- As h → ∞ the MSE → σ²W Σψⱼ² = V[Yₜ], a finite constant. A stationary forecast reverts to the mean and its interval stops widening. Often that is unrealistic, which motivates ARIMA.
12. From ARMA to SARIMAX, and VAR
The “I”: differencing to stationarity
∇ = 1 − B and ∇ᵈ = (1 − B)ᵈ. A random walk and a linear trend plus noise are both non-stationary, but their first difference is stationary.
- Integrated of order d: non-stationary, but stationary after d differences.
- ARIMA(p,d,q): φ(B) ∇ᵈ Yₜ = θ(B) Wₜ. Choose d by IC or by a test.
- Don’t over-difference. Differencing white noise gives MA(1) (∇²: MA(2)). The result is still stationary but more complicated.
Unit-root tests
If ∇Yₜ is ARMA, then Yₜ has the AR polynomial (1 − B)φ(B), which has a root at 1. So testing for non-stationarity means testing for a unit root.
Dickey–Fuller regression: ∇Yₜ = ϕ Yₜ₋₁ + Wₜ, H₀: ϕ = 0 (unit root, non-stationary) vs H₁: ϕ < 0- One-sided t-test.
- Under H₀ the statistic follows the non-standard Dickey–Fuller distribution (tabulated).
- Variants: Augmented DF, Phillips–Perron (R:
tseries::adf.test). - Note the direction: the null is non-stationarity.
ADF on levels: p = 0.18, so we can’t reject a unit root. Difference it. ADF on ∇Y: p = 0.01. Yet the amplitude still grows, and there is a clear 12-month pattern. Apply a seasonal difference ∇₁₂ as well and the series looks stable. That points to d = 1, D = 1, s = 12.
The “S”: seasonality with few parameters
An AR(12) or AR(52) captures seasonality but costs too many parameters. Instead, apply ARMA polynomials in Bˢ:
Seasonal AR(1), s = 12: (1 − Φ₁B¹²) Yₜ = Wₜ Pure SARMA(P,Q)ₛ: Φ(Bˢ) Yₜ = Θ(Bˢ) WₜMultiply seasonal and non-seasonal parts. For example (1 − φ₁B)(1 − Φ₁B⁴)Yₜ = Wₜ gives Yₜ = φ₁Yₜ₋₁ + Φ₁Yₜ₋₄ − φ₁Φ₁Yₜ₋₅ + Wₜ. That is a constrained AR(5).
SARIMA(p,d,q)×(P,D,Q)ₛ: Φ(Bˢ) φ(B) ∇ᵈ ∇ₛᴰ Yₜ = Θ(Bˢ) θ(B) Wₜ, ∇ₛ = 1 − Bˢ (≠ ∇ˢ = (1−B)ˢ)arima(y, order = c(p,d,q), seasonal = list(order = c(P,D,Q), period = s))
Forecasting with ARIMA
- Forecast the differenced series Zₜ = ∇Yₜ as an ARMA. Then integrate back: Yn+1|n = Yₙ + Zn+1|n, Yn+2|n = Yn+1|n + Zn+2|n, and so on.
- Intervals widen with h. For a random walk with drift (ARIMA(0,1,0)): Xn+h|n = Xₙ + hδ and MSE = hσ²W → ∞.
Exponential smoothing is an ARIMA(0,1,1)
Yₜ = Yₜ₋₁ + Wₜ − θWₜ₋₁ (|θ| < 1) ⇒ Y_{n+1|n} = Σ_{j≥1} (1−θ) θ^{j−1} Y_{n+1−j}That is simple exponential smoothing with α = 1 − θ. The model view supplies the prediction intervals, which is how HoltWinters produces them.
The “X”: exogenous regressors
SARIMAX: Yₜ = β Xₜ + Zₜ, Zₜ ~ SARIMA(p,d,q)×(P,D,Q)ₛ (R: arima(..., xreg = X))This is regression with autocorrelated errors, rather than OLS that assumes uncorrelated residuals. Caveat: you need Xn+h at forecast time. If X must be forecast too, model (X, Y) jointly with a VAR.
Vector autoregression
VAR(p): Yₜ = Φ₁Yₜ₋₁ + … + ΦₚYₜ₋ₚ + Wₜ, Yₜ ∈ ℝᴷ, Φⱼ ∈ ℝᴷˣᴷ, E[WₜWₜ'] = Σ, E[WₜWₜ₋ₛ'] = 0- Each component depends on lags of every component, and the shocks can be correlated through Σ.
- VAR(1) is stationary iff all eigenvalues of Φ have modulus < 1.
- Cross-correlation ρ₁₂(h) = Cor(Y₁,ₜ₋ₕ, Y₂,ₜ) is not symmetric (12 ≠ 21). Partial cross-correlations are defined similarly.
- Parameters grow as K²p, so keep orders small. Further topics: Granger causality, impulse responses (R:
vars,MTS).
13. State space models & the Kalman filter
Observations of a hidden Markov process
X₀ ~ μ_θ, Xₜ | Xₜ₋₁ ~ f_θ(· | Xₜ₋₁) (transition), Yₜ | Xₜ ~ g_θ(· | Xₜ) (emission / measurement)- Yₜ depends only on Xₜ, and Xₜ only on Xₜ₋₁. This is also called a hidden Markov model.
- Stochastic volatility: Xₜ − μ = φ(Xₜ₋₁ − μ) + σWₜ and Yₜ = exp(Xₜ)Vₜ. Observed returns, latent volatility.
- SIR epidemic models: latent infection status, observed case surveys.
- RNNs and LSTMs have a similar latent-state architecture.
Markov chains
The distribution of Xₜ given the whole past depends only on Xₜ₋₁. The trajectory law is p(x₀…xₜ) = π₀(x₀) Π P(xₛ | xₛ₋₁): an initial law plus a transition kernel. A chain of order m depends on the last m states. An AR(p) is an order-p chain, or an order-1 chain on the stacked vector (Yₜ₋ₚ₊₁…Yₜ). Xₜ = f(Xₜ₋₁) + Wₜ is a nonlinear AR(1). Markov invented chains to show that the LLN can hold without independence.
Linear Gaussian models (LGM)
Yₜ = A Xₜ + Vₜ, Xₜ = Φ Xₜ₋₁ + Wₜ, X₀ ~ N(m₀, C₀), Wₜ ~ N(0, Σ_W), Vₜ ~ N(0, Σ_V)The latent state is a VAR(1). Parameters: m₀, C₀, A, Φ, ΣW, ΣV. They can be extended with covariates or made time-varying.
- AR(p) as LGM: state = (Yₜ₋ₚ₊₁…Yₜ), companion matrix with φ in the last row, A = (0…0 1), V = 0.
- MA(q) as LGM: state = (Wₜ₋q…Wₜ) as a shift matrix, A = (θ_q…θ₁ 1).
- ARMA(p,q): r = max(p, q+1). The state follows φ(B)Xₜ,ᵣ = Wₜ and Yₜ = θ(B)Xₜ,ᵣ, so φ(B)Yₜ = θ(B)Wₜ. This is how
arimaworks internally: convert to an LGM, then use the Kalman likelihood. - Structural models (R:
StructTS):- Local level Xₜ = Xₜ₋₁ + Wₜ, Yₜ = Xₜ + Vₜ. This is ARIMA(0,1,1), i.e. exponential smoothing.
- Local linear trend: add a slope Bₜ = Bₜ₋₁ + Wᵇₜ, with state (Xₜ, Bₜ) and transition [[1,1],[0,1]].
- Stochastic seasonal: Sₜ = −Σj=1..s−1 Sₜ₋ⱼ + Wˢₜ, which sums to zero on average over a period but can drift.
Two Gaussian facts the filter runs on
Conditioning: X₁ | X₂ = x₂ ~ N( μ₁ + Σ₁₂Σ₂⁻¹(x₂ − μ₂), Σ₁ − Σ₁₂Σ₂⁻¹Σ₂₁ )Affine map: AX + β ~ N( Aμ + β, AΣA' )Kalman filter: filtering p(Xₜ | Y₁:ₜ)
In an LGM the filtering law is Normal. Track its mean and covariance mt|s, Ct|s (moments of Xₜ given Y1:s). Start from m1|0 = Φm₀ and C1|0 = ΦC₀Φ' + ΣW.
Update (Bayes, absorb yₜ)
Sₜ = A C_{t|t−1} A' + Σ_V (innovation variance)
Kₜ = C_{t|t−1} A' Sₜ⁻¹ (Kalman gain)
m_{t|t} = m_{t|t−1} + Kₜ (yₜ − A m_{t|t−1})
C_{t|t} = C_{t|t−1} − Kₜ A C_{t|t−1}
Predict (push through the dynamics)
m_{t+1|t} = Φ m_{t|t}
C_{t+1|t} = Φ C_{t|t} Φ' + Σ_W- Likelihood for free: Yₜ | Y1:t−1 ~ N(Amt|t−1, Sₜ), so p(y1:n | θ) = Π N(yₜ; Amt|t−1, Sₜ). One forward pass costs O(n), and every operation is differentiable, so gradient-based MLE works.
- Forecasting: run h prediction steps from (mn|n, Cn|n). Then Yn+h ~ N(Amn+h|n, ACn+h|nA' + ΣV). You can also simulate whole future paths.
- Missing data: skip the update step (mt|t = mt|t−1) whenever yₜ is missing. Irregular observation times are easy to handle.
- For nonlinear or non-Gaussian models, use a particle filter instead.
Kalman smoother: p(Xₜ | Y₁:ₙ)
Run the filter forward, then go backward from t = n. Given Xₜ, the variable Xₜ₋₁ is independent of the later observations. Combine the tower property with the law of total variance:
Lₜ₋₁ = C_{t−1|t−1} Φ' C_{t|t−1}⁻¹
m_{t−1|n} = m_{t−1|t−1} + Lₜ₋₁ (m_{t|n} − m_{t|t−1})
C_{t−1|n} = C_{t−1|t−1} + Lₜ₋₁ (C_{t|n} − C_{t|t−1}) Lₜ₋₁'Path sampling (backward simulation): draw Xₙ ~ N(mn|n, Cn|n), then each Xₜ₋₁ given Xₜ from the conditional Normal above. Use it for path quantities such as P(max Xₜ > η | y1:n). R: astsa::Kfilter0/Ksmooth0, dlm::dlmFilter/dlmSmooth.
14. Assessing forecasts
Out-of-sample evaluation
- Single split: train on the first m points, test on the last n − m.
- Random k-fold CV suits exchangeable tabular data but not time series. Predicting the middle of a series is a different task from predicting the future, and the future is usually what matters.
- Expanding window (train on 1..m, then 1..m+1, …) or rolling window (fixed length, sliding). You average over many splits and still only ever predict forward.
Point forecasts: loss functions
| Loss | Formula (e = ŷ − y) | Optimal forecast |
|---|---|---|
| Squared | e² | Conditional mean |
| Absolute | |e| | Conditional median |
| Lin-Lin (pinball) | α(y − ŷ) if y > ŷ, else (1 − α)(ŷ − y) | Conditional α-quantile |
| Linex | exp(a(y − ŷ)) − a(y − ŷ) − 1 | Asymmetric: linear one side, exponential the other |
RMSSE (M5) = √[ (1/h) Σ_{n+1..n+h} (yₜ − ŷₜ)² / (1/(n−1)) Σ_{2..n} (yₜ − yₜ₋₁)² ] < 1 ⇒ beats the random walkProbabilistic forecasts: proper scoring rules
We observe only one outcome, yet we want to reward forecasts p close to the true law p*. A scoring rule is proper if its expected value under p* is minimised by reporting p* itself, so honesty is optimal.
- Log score −log p(y). For N(m, v): log√(2πv) + (y − m)²/2v. It penalises both bias and over- or under-confidence. Proper by Jensen: E*[log(p/p*)] ≤ log E*[p/p*] = 0. The naïve linear score −p(y) is not proper.
- CRPS = ∫ (F(x) − 𝟙(y ≤ x))² dx, a distance between the forecast CDF and a step at y. Proper, because E*[CRPS(F)] − E*[CRPS(F*)] = ∫ (F − F*)² ≥ 0.
- Interval score for the central (1 − α) interval (l, u):
IS_α((l,u), y) = (u − l) + (2/α)·(l − y)·𝟙(y < l) + (2/α)·(y − u)·𝟙(y > u)The first term rewards narrow intervals. The second penalises misses. The factor 2/α is exactly what makes the true α/2 and 1 − α/2 quantiles optimal. The M5 scaled pinball loss applies Lin-Lin at each quantile level, scaled by the in-sample naïve MAE.
Are the differences significant?
- Diebold–Mariano: dₜ = loss(ŷᴬₜ, yₜ) − loss(ŷᴮₜ, yₜ), H₀: E[dₜ] = 0. Statistic √n·d̄ / √V̂ₙ ~ N(0,1) asymptotically. V̂ₙ must be a long-run variance, because dₜ is autocorrelated.
- Model Confidence Set (Hansen, Lunde & Nason): start from all models and remove the worst by sequential DM-like tests. The surviving set contains the best models with probability → 1 − α.
- Forecast combination (Bates & Granger, 1969): averaging forecasts, e.g. ½ŷᴬ + ½ŷᴮ, often beats choosing the single best. Weights can depend on past performance. For densities, use mixtures pᶜ = ½pᴬ + ½pᴮ.
Calibration
A (1 − α) interval is calibrated if it contains the outcome with probability 1 − α.
- Online fix: track the hit rate and widen or narrow the intervals with decreasing step sizes.
- Conformal prediction (exchangeable data):
- For each candidate y, refit on the data plus (Xₙ₊₁, y) and compute absolute residuals Rᵢ.
- Keep y if the rank of Rₙ₊₁ among all residuals is ≤ 1 − α.
- Then P(Yₙ₊₁ ∈ (l, u)) = 1 − α ± 1/(n+1) in finite samples, for any model and any noise law. A bad model gives wide intervals, not miscalibrated ones.
- For time series exchangeability fails, and adapting conformal prediction is an active research area (split conformal for dependent data, adaptive conformal, beyond exchangeability).
15. Checklist
I should be able to do each of these without notes:
- Explain why dependence breaks i.i.d. tools, and how stationarity plus ergodicity rescue LLN/CLT.
- Derive that E[Y | X] minimises MSE, and that the best linear predictor has β = Cov/Var.
- Write simple exponential smoothing and Holt–Winters, and show SES = ARIMA(0,1,1) with α = 1 − θ.
- State weak stationarity, and the AR(p) stationarity condition (roots outside the unit circle).
- Compute V[Yₜ] and ρ(h) for a stationary AR(1), and γ(h) for an MA(q).
- Read ACF/PACF patterns to suggest AR, MA or ARMA, and say when this fails.
- Write the Yule–Walker equations, and explain why MA moments and likelihoods are awkward.
- Compare AIC, AICc and BIC, and say which favours simpler models.
- Derive the h-step ARMA forecast MSE σ² Σψⱼ², and contrast it with the random walk’s hσ².
- Explain Dickey–Fuller: the regression, the null, and why the distribution is non-standard.
- Write SARIMA(p,d,q)×(P,D,Q)ₛ and explain ∇ₛ vs ∇ˢ. Know when SARIMAX is usable.
- Put an AR(p) or local-linear-trend model in state-space form.
- Write the Kalman predict/update steps and the prediction-error likelihood. Handle a missing yₜ.
- Choose rolling or expanding evaluation. Match each loss to its optimal forecast.
- Define a proper scoring rule. Prove the log score is proper. Explain the 2/α in the interval score.
- Run a Diebold–Mariano comparison, and argue for forecast combination.
Source: my own notes from a graduate course on forecasting and predictive analytics (lecture notes 1–8), in my own words. The main references are Hyndman & Athanasopoulos, Forecasting: Principles and Practice (fpp3), and Shumway & Stoffer, Time Series Analysis and Its Applications.