我收到此错误消息:
Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
'data' must be of a vector type, was 'NULL'
当我尝试运行此行时出现错误消息:
dcc.fit = dccfit(spec1,data = r_t1,fit.control = list(scale = TRUE))
但是,当我在下面运行该行时,它可以正常工作:
dcc.fit1 = dccfit(spec2, data = r_t1, fit.control=list(scale=TRUE), solver = "nlminb")
如果向量r_t1有问题,上面的代码行也不应该工作,所以这很奇怪。有谁知道如何解决这个问题? Multivariate3是我导入R的excel文件。
Multivariate3 excel file attached here
> head(spec2)
Error in x[seq_len(n)] : object of type 'S4' is not subsettable
我的整个代码在这里展示:
install.packages('rmgarch', dependencies = TRUE)
library("rmgarch")
library("parallel")
library("quantmod")
Dat<-data.frame(Multivariate3$Bitcoin,Multivariate3$SP500,Multivariate3$DAX,Multivariate3$KS11,Multivariate3$VGLT,Multivariate3$Euro,Multivariate3$Franc,Multivariate3$Yen,Multivariate3$Oil,Multivariate3$Gold)
#Returns
retBTC<-diff(log(Multivariate3$Bitcoin))
retSP<-diff(log(Multivariate3$SP500))
retDAX<-diff(log(Multivariate3$DAX))
retKS11<-diff(log(Multivariate3$KS11))
retVGLT<-diff(log(Multivariate3$VGLT))
retEUR<-diff(log(Multivariate3$Euro))
retCFH<-diff(log(Multivariate3$Franc))
retYEN<-diff(log(Multivariate3$Yen))
retOil<-diff(log(Multivariate3$Oil))
retGLD<-diff(log(Multivariate3$Gold))
# univariate normal GARCH(1,1) for each series
####UNRESTRICTED MODEL#####
xspec = ugarchspec(mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1,1), model = 'sGARCH'), distribution.model = 'std')
####RESTRICTED MODEL#####
xspec1 = ugarchspec(mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1,1), model = 'sGARCH'), distribution.model = 'std',fixed.pars=list(alpha1 = 0, beta1 = 0))
#################################
uspec = multispec(replicate(10, xspec))
uspecx = multispec(replicate(10, xspec1))
spec1 = dccspec(uspec = uspec, dccOrder = c(1, 1), distribution = 'mvnorm')
spec2 = dccspec(uspec = uspecx, dccOrder = c(1, 1), distribution = 'mvnorm')
#return vector
r_t1=cbind(retBTC,retSP,retDAX,retKS11,retVGLT,retEUR,retCFH,retYEN,retOil,retGLD)
####URESTRICTED MODEL#####
dcc.fit = dccfit(spec1, data = r_t1, fit.control=list(scale=TRUE))
####RESTRICTED MODEL#####
dcc.fit1 = dccfit(spec2, data = r_t1, fit.control=list(scale=TRUE), solver = "nlminb")