简体   繁体   English

as.vector(data) 中的错误:没有将此 S4 class 强制为向量的方法

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

I am trying to run a O-garch model, the code seem to be right and on mac it works, but when it is run on windows it doesn not work giving me the following error message:我正在尝试运行 O-garch model,代码似乎是正确的并且在 mac 上它可以工作,但是当它在 windows 上运行时它不起作用给我以下错误消息:

Error in as.vector(data): no method for coercing this S4 class to a vector as.vector(data) 中的错误:没有将此 S4 class 强制为向量的方法

seems that there is a problem with the loop.似乎循环有问题。 Thanks in advance.提前致谢。

graphics.off()        # clean up graphic window

#install.packages("fGarch")

library(rmgarch)
library(tseries)
library(stats)
library(fGarch)
library(rugarch)
library(quantmod)

getSymbols(Symbols = c('PG','CVX','CSCO'),from="2005-01-01",  to="2020-04-17",
           env=parent.frame(),
           reload.Symbols = FALSE,
           verbose = FALSE,
           warnings = TRUE,
           src="yahoo",
           symbol.lookup = TRUE,
           auto.assign = getOption('getSymbols.auto.assign', TRUE))


Pt=cbind(PG$PG.Adjusted,CVX$CVX.Adjusted,CSCO$CSCO.Adjusted) 
rt = 100 * diff(log(Pt))
rt=na.omit(rt)
rm(CSCO,CVX,PG)
rt_ts=ts(rt)
n=nrow(rt_ts)
N=ncol(rt_ts)
#O-GARCH:
Sigma = cov(rt_ts);  # Covariance matrix
P = cor(rt_ts)       # correlation matrix

# spectral decomposition
SpectralDec = eigen(Sigma, symmetric=TRUE)  
V = SpectralDec$vectors                            # eigenvector matrix
V
lambda = SpectralDec$values                        # eigenvalues
lambda
Lambda = diag(lambda)                 # Eigenvalues on the diagonal
print(Sigma - V %*% Lambda %*% t(V), digits = 3)   # Sigma - V Lambda V' = 0  
print(V  %*%   t(V), digits = 3) # V'V = I  
print(t(V)  %*% V, digits = 3)   # VV' = I  


f = ts(as.matrix(rt_ts) %*% V);  
cov(f) # diagonal matrix with lambda on the diagonal

ht.f = matrix(0, n, N)
for (i in 1:N)
{
  fit = garchFit(~ garch(1,1), data =f[, i], trace = FALSE);
  summary(fit);
  ht = volatility(fit, type = "h");
  ht.f[, i] = ht;
} 
ht.f=ts(ht.f) ```

I had the exact same problem with the volatility line.我对波动线有完全相同的问题。 Apparently the fGarch library doesn't get along with the quantmod library.显然 fGarch 库与 quantmod 库不兼容。 Maybe try reseting RStidio and install all but quantmod library也许尝试重置 RStidio 并安装除 quantmod 库之外的所有库

That was the only way I got it to work这是我让它工作的唯一方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 as.vector(x) 中的错误:没有将此 S4 class 强制为向量的方法 - Error in as.vector(x) : no method for coercing this S4 class to a vector as.vector(data) 中的错误:无法将此 S4 class 强制转换为 R 中的向量 - Error in as.vector(data) : no method for coercing this S4 class to a vector in R 软件包CVXR:as.vector(data)中的错误:没有用于将此S4类强制转换为向量的方法 - Package CVXR: Error in as.vector(data): no method for coercing this S4 class to a vector as.vector中的APCluster错误(数据):没有用于将此S4类强制转换为向量的方法 - APCluster Error in as.vector(data): no method for coercing this S4 class to a vector CVXR:as.vector(数据)中的错误:没有方法将此 S4 class 强制转换为向量 - CVXR: Error in as.vector(data): no method for coercing this S4 class to a vector CVXR:solve() 的问题 - as.vector(data) 中的错误:无法将此 s4 class 强制转换为向量 - CVXR: Problem with solve() - Error in as.vector(data): no method for coercing this s4 class to a vector 没有将这个 S4 类强制为向量以使用 mclust 的方法 - no method for coercing this S4 class to a vector for utilization of mclust 在 SparkR 中运行相关性:没有将此 S4 类强制转换为向量的方法 - Running correlations in SparkR: no method for coercing this S4 class to a vector getMethod导致“ as.vector(…中的错误” - getMethod resulting in “Error in as.vector(…” As.vector不会将data.frame子集转换为vector - As.vector does not convert data.frame subset to vector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM