gpt4 book ai didi

python - 如何在 python 中拟合 ARMA-GARCH 模型

转载 作者:行者123 更新时间:2023-12-03 15:14:38 25 4
gpt4 key购买 nike

我正在尝试在 python 中制作一个 ARMA-GARCH 模型,我使用了 arch 包。

但是在 arch 包中我找不到 ARMA 均值模型。

我尝试使用 ARX 均值模型并让滞后 = [1,1],但摘要看起来不像 ARMA 模型。

这个包是否包括 ARMA 均值模型?

最佳答案

我从 Jason Brownlee 博士那里学到了这项技术,他着有超过 18 本书,与应用机器学习、数学和统计学有关:
为了在适当的地方给予适当的赞扬,我引用了我通过本 Material 获得的学习来源:
引用引用书:
使用 Python 进行时间序列预测简介 © 版权所有 2020 Jason Brownlee。版权所有。版本:v1.10
Jason Brownlee,博士,精通机器学习
https://machinelearningmastery.com/develop-arch-and-garch-models-for-time-series-forecasting-in-python/
感谢杰森无数个小时的时间,毫无疑问,头痛和眼睛疲劳。你教会了我机器学习可以很有趣!
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()
enter image description here
# 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()
enter image description here
# 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()
enter image description here
enter image description here
# 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)
enter image description here
并看到结果非常相似,但是迭代次数增加了两倍多......
enter image description here
引用引用书:
Python时间序列预测简介
© 版权所有 2020 杰森·布朗利。版权所有。版本:v1.10
Jason Brownlee,博士,精通机器学习
https://machinelearningmastery.com/develop-arch-and-garch-models-for-time-series-forecasting-in-python/

关于python - 如何在 python 中拟合 ARMA-GARCH 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41477162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com