0

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.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
S_Star
  • 53
  • 5
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Dec 17 '19 at 22:03
  • You should edit your question to include the reproducible example; comments aren't great for code because it cannot be easily formatted. – MrFlick Dec 17 '19 at 22:24

2 Answers2

0

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

0

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

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103