rmodelingtradingvolatility

Error in as.vector(data) : no method for coercing this S4 class to a vector in R


I am trying to run volatility from GARCH model:

Used libraries:

source("TimeSeriesFunctions.R")
library(PerformanceAnalytics)
library(fGarch)
library(MonteCarlo)
library(Bootstrap)
library(xts)
library(quantmod)
library(dynlm)

GARCH1 = garchFit(~ garch(1,1), data=SP500returns, cond.dist = "norm", include.mean = TRUE)

sigmas = volatility(GARCH1, type = "sigma")

But , I got this error "Error in as.vector(data) : no method for coercing this S4 class to a vector" whenever I try, with different scripts as well, and the same code works for other people. I got this error as well even when I try sigma().

SP500 are the calculated returns, data taken from yahoo.


Solution

  • Had a similar issue. As mentioned, the quantmod library breaks the fgarch library.

    I loaded fgarch. I did not load quantmod. Whenever I wanted a function from quandmod I did quantmod::function().

    Example:

    library(fGarch)
    quantmod::getSymbols(...)
    

    Hopefully, this helps