Search code examples
rtime-seriesforecasting

Time Series Forecasting with GARCH


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


Solution

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

    enter image description here

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