Estimating and Forecasting an AR Model

Time Series Analysis in Python

Rob Reider

Adjunct Professor, NYU-Courant Consultant, Quantopian

Estimating an AR Model

  • To estimate parameters from data (simulated)

    from statsmodels.tsa.arima_model import ARMA
    mod = ARMA(data, order=(1,0))
    result = mod.fit()
    
  • ARMA has been deprecated and replaced with ARIMA

    from statsmodels.tsa.arima.model import ARIMA
    mod = ARIMA(data, order=(1,0,0))
    result = mod.fit()
    
  • For ARMA, order=(p,q)

  • For ARIMA,order=(p,d,q)
Time Series Analysis in Python

Estimating an AR Model

  • Full output (true $\large \mu=0$ and $\large \phi=0.9$)
    print(result.summary())
    

Time Series Analysis in Python

Estimating an AR Model

  • Only the estimates of $\large \mu$ and $\large \phi$ (true $\large \mu=0$ and $\large \phi=0.9$)
    print(result.params)
    
array([-0.03605989,  0.90535667])
Time Series Analysis in Python

Forecasting With an AR Model

from statsmodels.graphics.tsaplots import plot_predict
fig, ax = plt.subplots()
data.plot(ax=ax)
plot_predict(result, start='2012-09-27', end='2012-10-06', alpha=0.05, ax=ax)
plt.show()
  • Arguments of function plot_predict()
    • First argument is fitted model
    • Set alpha=None for no confidence interval
    • Set ax=ax to plot the data and prediction on same axes

Time Series Analysis in Python

Let's practice!

Time Series Analysis in Python

Preparing Video For Download...