简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM