样本预测中的statsmodel ARMA

statsmodel ARMA in sample prediction

我正在使用 statsmodel ARMA() 来估计模拟的 MA(1) 过程:

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')

我得到以下信息:

样本内预测似乎是按比例缩放的。这是为什么?

我还绘制了实际值和预测值的累积总和,因为我们通常使用一阶差分来整合数据。

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')

我得到了这样的东西:

我做错了什么吗?为什么天平这么差?

这不是真正有意义的情节或练习。

您正在积累一个超前的预测,这些预测都是从该观察的历史记录或在该时间点给出的不同水平开始的。

具有一阶差分的模型可以作为 ARIMA(0,1,1) 进行估计和预测。在那种情况下,水平的预测,`typ="level"),是基于在前一个时间点添加到观察中的预测变化。