Logo

Autoregressive Moving Average (ARMA) ModelΒΆ

In [1]: import numpy as np

In [2]: import statsmodels.api as sm

Generate some data from an ARMA process

In [3]: from statsmodels.tsa.arima_process import arma_generate_sample

In [4]: np.random.seed(12345)

In [5]: arparams = np.array([.75, -.25])

In [6]: maparams = np.array([.65, .35])

The conventions of the arma_generate function require that we specify a 1 for the zero-lag of the AR and MA parameters and that the AR parameters be negated.

In [7]: arparams = np.r_[1, -arparams]

In [8]: maparam = np.r_[1, maparams]

In [9]: nobs = 250

In [10]: y = arma_generate_sample(arparams, maparams, nobs)

Now, optionally, we can add some dates information. For this example, we’ll use a pandas time series.

In [11]: import pandas

In [12]: dates = sm.tsa.datetools.dates_from_range('1980m1', length=nobs)

In [13]: y = pandas.TimeSeries(y, index=dates)

In [14]: arma_mod = sm.tsa.ARMA(y, order=(2, 2))

In [15]: arma_res = arma_mod.fit(trend='nc', disp=-1)

This Page