Forecasting with MA Model

As you did with AR models, you will use MA models to forecast in-sample and out-of-sample data using the plot_predict() function in statsmodels.

For the simulated series simulated_data_1 with \(\small \theta=-0.9\), you will plot in-sample and out-of-sample forecasts. One big difference you will see between out-of-sample forecasts with an MA(1) model and an AR(1) model is that the MA(1) forecasts more than one period in the future are simply the mean of the sample.

This is a part of the course

“Time Series Analysis in Python”

View Course

Exercise instructions

  • Import the class ARIMA and also import the function plot_predict
  • Create an instance of the ARIMA class called mod using the simulated data simulated_data_1 and the (p,d,q) order of the model (in this case, for an MA(1)), order=(0,0,1)
  • Fit the model mod using the method .fit() and save it in a results object called res
  • Plot the in-sample data starting with data point 950
  • Plot out-of-sample forecasts of the data and confidence intervals using the plot_predict() function, starting with data point 950 and ending the forecast at point 1010

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import the ARIMA and plot_predict from statsmodels
from statsmodels.tsa.arima.model import ARIMA
from statsmodels.graphics.tsaplots import plot_predict

# Forecast the first MA(1) model
mod = ARIMA(___, order=___)
res = mod.fit()

# Plot the data and the forecast
fig, ax = plt.subplots()
simulated_data_1.loc[950:].plot(ax=ax)
plot_predict(res, start=___, end=___, ax=ax)
plt.show()