我尝试在python中创建一个ARMA-GARCH模型,然后使用arch包。
但是在arch包中我找不到ARMA的平均模型。
我尝试使用ARX均值模型并让滞后= [1,1],但摘要看起来不像ARMA模型。
此套餐是否包含ARMA均值模型?
答案 0 :(得分:2)
我从Jason Brownlee博士那里学到了这项技术,他写了18余本与应用机器学习,数学和统计学有关的书:
为了在适当的时候给予应有的荣誉,我在此引用本材料所学到的知识:
引用参考书:
使用Python进行时间序列预测的简介©版权所有2020 Jason Brownlee。版权所有。版本:v1.10
机器学习精通博士Jason Brownlee
感谢杰森(Jason)数小时的工作,毫无疑问,头痛和眼睛疲劳。您告诉我机器学习可以很有趣!
Python中的ARCH和GARCH模型
# create a simple white noise with increasing variance
from random import gauss
from random import seed
from matplotlib import pyplot
# seed pseudorandom number generator
seed(1)
# create dataset
data = [gauss(0, i*0.01) for i in range(0,100)]
# plot
pyplot.plot(data)
pyplot.show()
# create dataset
data = [gauss(0, i*0.01) for i in range(1,100+1)]
# check correlations of squared observations
from random import gauss
from random import seed
from matplotlib import pyplot
from statsmodels.graphics.tsaplots import plot_acf
# seed pseudorandom number generator
seed(1)
# create dataset
data = [gauss(0, i*0.01) for i in range(0,100)]
# square the dataset
squared_data = [x**2 for x in data]
# create acf plot
plot_acf(np.array(squared_data))
pyplot.show()
# split into train/test
n_test = 10
train, test = data[:-n_test], data[-n_test:]
# example of ARCH model
from random import gauss
from random import seed
from matplotlib import pyplot
from arch import arch_model
# seed pseudorandom number generator
seed(1)
# create dataset
data = [gauss(0, i*0.01) for i in range(0,100)]
# split into train/test
n_test = 10
train, test = data[:-n_test], data[-n_test:]
# define model
model = arch_model(train, mean='Zero', vol='ARCH', p=15)
# fit model
model_fit = model.fit()
# forecast the test set
yhat = model_fit.forecast(horizon=n_test)
# plot the actual variance
var = [i*0.01 for i in range(0,100)]
pyplot.plot(var[-n_test:])
# plot forecast variance
pyplot.plot(yhat.variance.values[-1, :])
pyplot.show()
# example of ARCH model
# seed pseudorandom number generator
seed(1)
# create dataset
data = [gauss(0, i*0.01) for i in range(0,100)]
# split into train/test
n_test = 10
train, test = data[:-n_test], data[-n_test:]
# define model
model = arch_model(train, mean='Zero', vol='GARCH', p=15, q=15)
# fit model
model_fit = model.fit()
# forecast the test set
yhat = model_fit.forecast(horizon=n_test)
# plot the actual variance
var = [i*0.01 for i in range(0,100)]
pyplot.plot(var[-n_test:])
# plot forecast variance
pyplot.plot(yhat.variance.values[-1, :])
pyplot.show()
# define model
model = arch_model(train, mean='Zero', vol='GARCH', p=15, q=15)
看到的结果非常相似,但是迭代次数却是原来的两倍多...
引用参考书:
Python时间序列预测简介 ©版权所有2020 Jason Brownlee。版权所有。版本:v1.10
机器学习精通博士Jason Brownlee