Question on cgarchsim with external regressors

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Question on cgarchsim with external regressors

Rmetrics mailing list
Hi everyone,
I want to use external regressors in the univariate GARCH mean specification in a Copula-GARCH Model (But I get the same problems with DCC-GARCH).
(From the rmgarch Vignette p. 28) To provide a list (equal to the number of asset) of matrices of simulated external regressorin-mean data with row length equal to n.sim + n.start I first simulate data for the stocks "AXP", "BA" and "BAC" as external regressors (just as an example).
However, the use of the data only works in the univariate case within the univariate mean specification, not in the multivariate case.
Unfortunately I can not correctly specify mexsimdata for the multivariate case. I always get the following error message:
"Error in .simregressors(model, mexsimdata, vexsimdata, N, n, m.sim, m) :
ugarchsim-->error: mexsimdata should be a list of length m.sim"
But length(k) (k is my specification for mexsimdata, see below) is 100 and is therefore equal to the length of m.sim, since n.start=0.
I have tried other specifications, but I do not know exactly what is missing or what I am doing wrong.
The same error message also appears when using dccspec, dccfit and dccsim for the DCC-GARCH model instead of the copula-DCC.
The use of external regressors for the variance equation also causes the same error message, only then for vexsimdata.
Do I try to use the package in a way it is not intended for?

 Thanks for your help in advance,Daniel


See below a reproducible example

library(rugarch)
library(rmgarch)
data(dji30ret)
# uspec for external regressors
uspec.external <- ugarchspec(mean.model = list(armaOrder = c(1,0), include.mean = TRUE, archm=FALSE), variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)), distribution.model = "std")    
# I use observations up to 2005-02-11 (observations 1 to 4521) for fitting.
Ufit.AXP<- ugarchfit(uspec.external, data=dji30ret[,2], out.sample = 1000, solver = "hybrid", solver.control = list())
Ufit.BA<- ugarchfit(uspec.external, data=dji30ret[,3], out.sample = 1000, solver = "hybrid", solver.control = list())
Ufit.BAC<- ugarchfit(uspec.external, data=dji30ret[,4], out.sample = 1000, solver = "hybrid", solver.control = list())
# Simulation one ahead (observation 2005-02-14)
Usim.AXP<- ugarchsim(Ufit.AXP,n.start=0, n.sim = 1, m.sim = 100, startMethod = "sample", rseed = 1:100)
Usim.BA<- ugarchsim(Ufit.BA,n.start=0, n.sim = 1, m.sim = 100, startMethod = "sample", rseed = 1:100)
Usim.BAC<- ugarchsim(Ufit.BAC,n.start=0, n.sim = 1, m.sim = 100, startMethod = "sample", rseed = 1:100)
#
# Creating a list for mexsimdata for n=3
# Create Array
j<- array(NA,c(1,3,100))
    for(i in 1:100){
        j[,1,i]<-Usim.AXP@simulation$seriesSim[1,i]
        j[,2,i]<-Usim.BA@simulation$seriesSim[1,i]
        j[,3,i]<-Usim.BAC@simulation$seriesSim[1,i]
}
# Convert three dimensional Array to list
split.along.dim <- function(a, n)
  setNames(lapply(split(a, arrayInd(seq_along(a), dim(a))[, n]),
                  array, dim = dim(a)[-n], dimnames(a)[-n]),
           dimnames(a)[[n]])
#
k<-split.along.dim(j, n = 3)
#
# In the univariate case, it works:
# uspec for "AA" with external regressors
uspec = ugarchspec(mean.model = list(armaOrder = c(1,0), include.mean = TRUE, archm=FALSE,external.regressors=as.matrix(cbind(dji30ret[,2],dji30ret[,3],dji30ret[,4]))), variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)), distribution.model = "std")
Ufit <- ugarchfit(uspec, data=dji30ret[,1], out.sample = 1000, solver = "hybrid", solver.control = list())
Usim <- ugarchsim(Ufit,n.sim=1, n.start=0, m.sim=100, mexsimdata = k, startMethod="sample", rseed = 1:100)
#
# In the multivariate case, it does not work to include the external regressors in the univariate mean specification for the stocks "AA","C","CAT","CVX":
cl=makeCluster(8)
Cspec = cgarchspec(uspec=multispec( replicate(4,uspec)), VAR = FALSE, dccOrder = c(1, 1), asymmetric = FALSE, distribution.model = list(copula = "mvt", time.varying = TRUE, transformation = "parametric"))
Cfit<-cgarchfit(Cspec,data=dji30ret[,c(1,5:7)],out.sample= 1000,fit.control = list(eval.se = FALSE, stationarity = TRUE, scale = FALSE), solver = c("hybrid","gosolnp"), solver.control = list(),cluster=cl)
Csim<-cgarchsim(Cfit, n.sim = 1, n.start=0, m.sim = 100, startMethod = "sample",mexsimdata = k,rseed=1:100, cluster=cl)
#



        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.