'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. Any help?

Thank you.



Solution 1:[1]

The quantmod library breaks the fGarch library. Try reseting your RStudio and running everything but quantmod I have no idea why it does this, but that has been the only solution I found

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Enya Julieta
Solution 2 Suraj Rao