Objective
The time-series primer covered AR(1), MA(1) and the random walk. This lesson goes one level deeper, to the questions a researcher interview actually asks: when is an AR(2) stationary, why do we insist an MA be invertible, how do you identify the order from the ACF and PACF, how do you get parameters from autocorrelations (Yule–Walker), and how fast does forecast uncertainty grow.
The models
With white noise of variance and the lag operator :
where and . A non-zero mean is handled by writing the model for .
Intuition: an AR process remembers its own past values, so a shock echoes forever with decaying strength. An MA process remembers the last shocks and then forgets them completely.
Stationarity and invertibility
Stationarity (AR part). An AR() is stationary when every root of lies outside the unit circle, equivalently when every root of has . For AR(1) this is . For AR(2) it reduces to the stationarity triangle:
If the roots are complex and the ACF is a damped oscillation (a pseudo-cycle). Example: has inverse roots of modulus , so it is stationary and cycles.
Any finite MA is stationary. It is a finite sum of white noise.
Invertibility (MA part). An MA is invertible when the roots of lie outside the unit circle; for MA(1), . Why care? and give the same autocorrelation function:
With and both giving , the data cannot tell them apart. Only the invertible one lets you write as a convergent sum of current and past 's, , so only it lets you recover shocks (and forecast) from observed data. Software therefore always reports the invertible root. A side fact worth knowing: an MA(1) can never have .
ACF and PACF signatures
The partial autocorrelation at lag , , is the last coefficient when you regress on : the correlation with lag after removing what lags explain.
| Model | ACF | PACF |
|---|---|---|
| AR() | Decays (geometric or damped oscillation) | Cuts off after lag |
| MA() | Cuts off after lag | Decays |
| ARMA() | Decays after lag | Decays after lag |
Under white noise both sample functions have standard error about , so the usual bands are . With 20 lags plotted, about one bar outside the band is expected by chance. For mixed models the table is only a starting point; in practice compare a few candidate orders by AIC or BIC and check that the residuals pass a Ljung–Box test for remaining autocorrelation.
Yule–Walker equations
Multiply the AR equation by , take expectations and divide by . For AR(2):
At : , so . At : . The equation gives the variance:
Run backwards, the same two equations estimate the parameters from sample autocorrelations:
For AR(1) everything collapses to and . Note is exactly the lag-2 partial autocorrelation, which is why the PACF of an AR(2) is zero from lag 3.
Worked example
the ACF of an AR(2)
with . Is it stationary? Find , , , the variance, and the PACF at lags 2 and 3.
Show solutionHide solution
Stationarity. , , . Stationary. (The inverse roots solve : and , both inside the unit circle. Real roots, so no oscillation.)
Autocorrelations.
- .
- .
- .
The ACF decays slowly, at a rate governed by the larger root .
Variance. .
PACF. (check: ), and because a third lag adds nothing once two are included.
Forecasting and forecast variance
Write the stationary process in its MA() form with . The optimal (minimum mean-squared error) -step forecast replaces future shocks by zero, so the forecast error is and
For AR(1), :
The forecast decays to the mean and the error variance rises to the unconditional variance . For an MA() the forecast equals the mean after steps: an MA(1) forecast is one step ahead and from two steps on. Beyond a few half-lives, no ARMA model knows more than the unconditional mean.
These intervals assume known parameters. With estimated parameters they are too narrow, more so for persistent series, where small errors in compound over the horizon.
Worked example
forecasting a mean-reverting spread
A spread follows with . Today . Give the 1-, 2- and 5-step forecasts, their error variances, and a 95% interval at two steps.
Show solutionHide solution
The deviation from the mean is and shrinks by each step.
| Forecast | Error variance | Error s.d. | |
|---|---|---|---|
| 1 | 4.40 | 1.00 | 1.00 |
| 2 | 3.92 | 1.64 | 1.28 |
| 5 | 2.98 | 2.48 | 1.57 |
| 2.00 | 2.78 | 1.67 |
The two-step variance is , so the 95% interval is , roughly . Notice the interval at two steps already contains the mean: the expected reversion is real but small relative to the noise, which is the usual situation for a trading signal.
Estimating an AR(2) by Yule–Walker
This simulates the AR(2) from the first example and recovers its coefficients from two sample autocorrelations, using only the standard library.
import random
def acf(x, k):
n = len(x)
m = sum(x) / n
c0 = sum((v - m) ** 2 for v in x) / n
ck = sum((x[t] - m) * (x[t - k] - m) for t in range(k, n)) / n
return ck / c0
random.seed(1)
phi1, phi2, n = 0.5, 0.3, 20000
x = [0.0, 0.0]
for _ in range(n):
x.append(phi1 * x[-1] + phi2 * x[-2] + random.gauss(0, 1))
x = x[500:] # drop burn-in
r1, r2 = acf(x, 1), acf(x, 2)
phi2_hat = (r2 - r1**2) / (1 - r1**2)
phi1_hat = r1 * (1 - r2) / (1 - r1**2)
print(f"rho1={r1:.3f} rho2={r2:.3f}")
print(f"phi1_hat={phi1_hat:.3f} phi2_hat={phi2_hat:.3f}")
Output:
rho1=0.723 rho2=0.665
phi1_hat=0.506 phi2_hat=0.299
The sample autocorrelations are close to the theoretical and . Yule–Walker is fine for pure AR models with plenty of data; for MA or mixed models, or short persistent samples, use maximum likelihood, because Yule–Walker estimates are biased towards zero in small samples.
Knowledge check
A series' sample ACF has significant spikes at lags 1 and 2 and nothing beyond; its PACF decays gradually. Which model is suggested?
Knowledge check
Is stationary?
Knowledge check
Which statement about is correct?
Knowledge check
For an AR(1) with and , what is the variance of the two-step-ahead forecast error?
Key takeaways
- AR() is stationary when the roots of lie outside the unit circle; for AR(2), , , . Complex roots give a damped cycle.
- Finite MAs are always stationary; invertibility ( for MA(1)) picks the one of two observationally equivalent models that lets you recover shocks from data.
- AR: PACF cuts off at . MA: ACF cuts off at . ARMA: both decay. Confirm with AIC/BIC and residual Ljung–Box tests.
- Yule–Walker for AR(2): , , .
- -step forecast error variance is ; for AR(1), , rising to the unconditional variance.
Practice problems
Finished reading?
Answer the 4 knowledge checks to complete this lesson (0 done).