通过引用dynamic copula using rmgarch package (ignore the previous question, don't know how to delete it),我尝试将其修改为aDCC
,DCC
甚至是Fractional Integrated univariate-GARCH
并运行编码,当我尝试进行编码时,它可以工作更改数据,错误提示如下所示。有人把我遮住了灯吗?
> dim(HiLo.base)
[1] 1476 2
> library(rugarch)
> library(rmgarch)
> library(forecast)
> library(plyr)
> library(dplyr)
>
> Dat = HiLo.base[,, drop = FALSE]
> armaorder <- llply(Dat, function(x) {
+ arimaorder(auto.arima(x))})
>
> model <- llply(armaorder, function(x) {
+ ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(1,1), variance.targeting=FALSE),
+ mean.model=list(armaOrder=c(x[1],x[3]), include.mean=F, archm=F,
+ archpow=1, arfima = TRUE),
+ fixed.pars = list(arfima = x[2]), distribution.model="norm")
+ })
> spec = cgarchspec(uspec = multispec(model), VAR = FALSE, robust = FALSE,
+ lag.criterion = "AIC", external.regressors = NULL,
+ dccOrder = c(1,1), asymmetric = TRUE,
+ distribution.model = list(copula = "mvt", method = "ML",
+ time.varying = TRUE,
+ transformation = "spd"))
> fit = cgarchfit(spec, data = Dat, out.sample = 570, cluster = NULL,
+ spd.control = list(lower = 0.1, upper = 0.9, type = "mle", kernel = "normal"),
+ fit.control = list(eval.se=FALSE))
> T = dim(Dat)[1]-570
> simMu = simS = filtMu = filtS = matrix(NA, ncol = 2, nrow = 570)
> simCor = simC = filtC = filtCor = array(NA, dim = c(2,2,570))
> colSd = function(x) apply(x, 2, "sd")
> specx = spec
> for(i in 1:2) specx@umodel$fixed.pars[[i]] = as.list(fit@model$mpars[fit@model$midx[,i]==1,i])
> setfixed(specx)<-as.list(fit@model$mpars[fit@model$midx[,3]==1,3])
>
> simulatedreturns <- array(dim=c(570,2,5000))
> for(i in 1:570){
+ if(i==1){
+ presigma = matrix(tail(sigma(fit), 1), ncol = 2)
+ prereturns = matrix(unlist(Dat[T, ]), ncol = 2, nrow = 1)
+ preresiduals = matrix(tail(residuals(fit),1), ncol = 2, nrow = 1)
+ preR = rcor(fit)[,,1]
+ diag(preR) = 1
+ preQ = fit@mfit$Qt[[length(fit@mfit$Qt)]]
+ preZ = tail(fit@mfit$Z, 1)
+ tmp = cgarchfilter(specx, Dat[2:(T+1), ], filter.control = list(n.old = T))
+ filtMu[i,] = tail(fitted(tmp), 1)
+ filtS[i,] = tail(sigma(tmp), 1)
+ filtC[,,i] = rcov(tmp)[,,1]
+ filtCor[,,i] = rcor(tmp)[,,1]
+ } else{
+ presigma = matrix(tail(sigma(tmp), 1), ncol = 2)
+ prereturns = matrix(unlist(Dat[(T+i-1), ]), ncol = 2, nrow = 1)
+ preresiduals = matrix(tail(residuals(tmp),1), ncol = 2, nrow = 1)
+ preR = rcor(tmp)[,,1]
+ diag(preR) = 1
+ preQ = tmp@mfilter$Qt[[length(tmp@mfilter$Qt)]]
+ preZ = tail(tmp@mfilter$Z, 1)
+
+ tmp = cgarchfilter(specx, Dat[(i+1):(T+i), ], filter.control = list(n.old = T))
+ filtMu[i,] = tail(fitted(tmp), 1)
+ filtS[i,] = tail(sigma(tmp), 1)
+ filtC[,,i] = rcov(tmp)[,,1]
+ filtCor[,,i] = rcor(tmp)[,,1]
+ }
+ sim = cgarchsim(fit, n.sim = 1, m.sim = 5000, startMethod = "sample",
+ preR = preR, preQ = preQ, preZ = preZ,
+ prereturns = prereturns, presigma = presigma,
+ preresiduals = preresiduals, cluster = NULL)
+ simx = t(sapply(sim@msim$simX, FUN = function(x) x[1,]))
+ simMu[i,] = colMeans(simx)
+ simC[,,i] = sim@msim$simH[[1]][,,1]
+ simCor[,,i] = sim@msim$simR[[1]][,,1]
+ simS[i,] = sqrt(diag(simC[,,i]))
+ simulatedreturns[i,,]=simx
+ }
Error in .custzdist(custom.dist, zmatrix, m.sim, n) : row dimension
of custom innovations
matrix must be equal to n.sim+n.start
In addition: Warning messages:
1: In .gpdpwmFit(x, u) :
Asymptotic Standard Errors not available for PWM when xi>0.5.
2: In .gjrgarchpath2(spec = spec, n.sim = n.sim, n.start = n.start, :
ugarchpath-->warning: n.start>=MA order for arfima model...automatically setting.
已替换为我的另一篇帖子Copula-DCC-GARCH : rmgarch::cgarchsim() and rmgarch::varxforecast(),但此帖子在VAR=FALSE
(矢量自回归)模型中很深。
当我将数据集更改为Dat = HiLoCl.base[,, drop = FALSE]
时,它是3列而不是2列,则下面的错误显示:
> traceback({
+ fit = cgarchfit(spec, data = Dat, out.sample = out, cluster = NULL,
+ spd.control = list(lower = 0.1, upper = 0.9, type = "mle",
+ kernel = "normal"),
+ fit.control = list(eval.se=FALSE))
+ })
Error in x[[i]] : this S4 class is not subsettable
In addition: Warning messages:
1: In sqrt(ans$h) : NaNs produced
2: In sqrt(diag(varcov)) : NaNs produced
3: In retval[sort.list(q)] <- val :
number of items to replace is not a multiple of replacement length
4: In sqrt(ans$h) : NaNs produced
5: In sqrt(diag(varcov)) : NaNs produced
6: In retval[sort.list(q)] <- val :
number of items to replace is not a multiple of replacement length