Autoregressive Moving Average (ARMA): Artificial data¶

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.

arparams = np.r_[1, -arparams] maparams = np.r_[1, maparams] nobs = 250 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.

dates = pd.date_range("1980-1-1", freq="M", periods=nobs) y = pd.Series(y, index=dates) arma_mod = ARIMA(y, order=(2, 0, 2), trend="n") arma_res = arma_mod.fit() 
print(arma_res.summary()) 
SARIMAX Results ============================================================================== Dep. Variable: y No. Observations: 250 Model: ARIMA(2, 0, 2) Log Likelihood -353.445 Date: Thu, 14 Dec 2023 AIC 716.891 Time: 14:45:22 BIC 734.498 Sample: 01-31-1980 HQIC 723.977 - 10-31-2000 Covariance Type: opg ============================================================================== coef std err z P>|z| [0.025 0.975] ------------------------------------------------------------------------------ ar.L1 0.7905 0.142 5.566 0.000 0.512 1.069 ar.L2 -0.2314 0.124 -1.859 0.063 -0.475 0.013 ma.L1 0.7007 0.131 5.344 0.000 0.444 0.958 ma.L2 0.4061 0.097 4.177 0.000 0.216 0.597 sigma2 0.9801 0.093 10.514 0.000 0.797 1.163 =================================================================================== Ljung-Box (L1) (Q): 0.00 Jarque-Bera (JB): 0.29 Prob(Q): 0.96 Prob(JB): 0.86 Heteroskedasticity (H): 0.92 Skew: 0.02 Prob(H) (two-sided): 0.69 Kurtosis: 2.84 =================================================================================== Warnings: [1] Covariance matrix calculated using the outer product of gradients (complex-step).
y.tail() 
2000-06-30 0.173211 2000-07-31 -0.048325 2000-08-31 -0.415804 2000-09-30 0.338725 2000-10-31 0.360838 Freq: M, dtype: float64
import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(10, 8)) fig = plot_predict(arma_res, start="1999-06-30", end="2001-05-31", ax=ax) legend = ax.legend(loc="upper left")