Lipton
Lipton

Reputation: 13

statsmodel ARMA in sample prediction

I'm using statsmodel ARMA() to estimate a simulated MA(1) process:

import statsmodels.tsa.api as smt
import numpy as np
import matplotlib.pyplot as plt

# Simulate an MA(1) process
n = int(1000)
alphas = np.array([0.])
betas = np.array([0.6])
ar = np.r_[1, -alphas]
ma = np.r_[1, betas]
ma1 = smt.arma_generate_sample(ar=ar, ma=ma, nsample=n) #input

# Fit the MA(1) model to our simulated time series
max_lag = 30
mdl = smt.ARMA(ma1, order=(0, 1)).fit(maxlag=max_lag, method='mle', trend='nc')


# in sample predict
pred = mdl.predict()

#plotting
plt.style.use('bmh')
fig = plt.figure(figsize=(9,7))
ax = plt.gca()
plt.plot(ma1, label='Actual')        
plt.plot(pred, 'r-', label = "In-sample predict")
plt.legend(loc='upper left')

I get the following:

The in-sample prediction seems to be scaled. Why is that?

I also plotted the cumulative sum of the actual and the predicts, given that usually we do first order difference to integrate the data.

fig = plt.figure(figsize=(9,7))
ax = plt.gca()
plt.plot(ma1.cumsum(), label='Actual')
plt.plot(pred.cumsum(), 'r-', label='Predict')
plt.legend(loc='upper left')

I got something like this:

enter image description here

Did I do anything wrong? Why is the scale so off?

Upvotes: 1

Views: 1008

Answers (1)

Josef
Josef

Reputation: 22907

That's not really a meaningful plot or exercise.

You are accumulating one step-ahead forecasts that all start at different levels given by the history for that observation or at that time point.

A model with first difference can be estimated and prediction as ARIMA(0,1,1). In that case the prediction of the level, `typ="level"), is based on the predicted changes added to the observation at the previous time point.

Upvotes: 1

Related Questions