Lesson 6 of 15

AR(p) Model

Autoregressive AR(p) Model

An Autoregressive model of order p expresses each value as a linear combination of its own past values:

y[t] = φ₁·y[t-1] + φ₂·y[t-2] + ... + φp·y[t-p] + ε[t]

where φ are the AR coefficients and ε[t] is white noise. For simplicity, our simulation omits the noise term.

AR models are stationary when the roots of the characteristic polynomial lie outside the unit circle. For AR(1): |φ₁| < 1.

One-step Forecast

ŷ[t+1] = φ₁·y[t] + φ₂·y[t-1] + ... + φp·y[t-p+1]

Task

Implement:

  • ar_simulate(xs_init, phi, n) — simulate n new values starting from initial values xs_init; return only the new values
  • ar_forecast(xs, phi) — one-step forecast using the last p values
Python runtime loading...
Loading...
Click "Run" to execute your code.