Time Series Forecasting with GARCH

╄→尐↘猪︶ㄣ 提交于 2020-08-03 08:16:09

问题


I am trying to forecast a time series object in R with GARCH(1,1) model. My goal is to hav 24 instances ahead forecast with the GARCH model. Although I am using a time series object while forecasting,I get the following error:

Error in is.constant(y) : (list) object cannot be coerced to type 'double'

Those are the commands that I am using:

library(forecast)
library(tseries)


trainer1 <- ts(trainer, frequency=24)
m1 <- garch(trainer1, order = c(1,1))
forecasts1 <- forecast(m1, h=24)

And the sample data that I am using is as follows:

124.30
98.99
64.00
64.00
123.99
123.99
34.97
123.99
139.91
140.00
164.30
178.99
140.00
169.95
161.18
139.94
161.31
124.00
115.01
124.00

Many thanks for your help :)


回答1:


The garch is not a function of forecast package. So, you cannot apply forecast function on m1 model. The garch function is available in tseries package. So, to use garch for prediction you have to use

library(forecast)
library(tseries)
trainer1 <- ts(df, frequency=24)
m1 <- garch(trainer1, order = c(1,1))
forecasts1 <- predict(m1, trainer1)

If you want to forecast you can use fGarch package like

library(fGarch)
fit <- garchFit(~ arma(0,1) + garch(1,1), data = trainer1, trace = FALSE)
predict(fit,n.ahead=24,plot=TRUE)

Data

df = structure(list(trainer = c(124.3, 98.99, 64, 64, 123.99, 123.99, 
34.97, 123.99, 139.91, 140, 164.3, 178.99, 140, 169.95, 161.18, 
139.94, 161.31, 124, 115.01, 124)), class = "data.frame", row.names = c(NA, 
-20L))


来源:https://stackoverflow.com/questions/62480098/time-series-forecasting-with-garch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!