[英]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:我正在尝试从 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.但是,每当我尝试使用不同的脚本时,我都会收到此错误“as.vector(data) 中的错误:没有方法将这个 S4 class 强制转换为向量”,并且相同的代码适用于其他人。 I got this error as well even when I try sigma().即使我尝试 sigma(),我也遇到了这个错误。
SP500 are the calculated returns, data taken from yahoo. SP500 是计算所得,数据取自雅虎。
The quantmod library breaks the fGarch library. quantmod 库打破了 fGarch 库。 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尝试重置您的 RStudio 并运行除 quantmod 之外的所有内容我不知道它为什么会这样做,但这是我找到的唯一解决方案
Had a similar issue.有类似的问题。 As mentioned, the quantmod library breaks the fgarch library.如前所述,quantmod 库破坏了 fgarch 库。
I loaded fgarch.我加载了 fgarch。 I did not load quantmod.我没有加载quantmod。 Whenever I wanted a function from quandmod I did quantmod::function()
.每当我想要来自 quandmod 的 function 时,我都会做quantmod::function()
。
Example:例子:
library(fGarch)
quantmod::getSymbols(...)
Hopefully, this helps希望这会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.