Rolling One-Step DCC-GARCH-Copula Return Simulations in R
Summary
The document presents a question about generating rolling, one-step-ahead simulated returns from a fitted dynamic conditional correlation GARCH copula model in R. The intended procedure reserves an out-of-sample period, extends the data incrementally, and simulates multiple possible returns for each forecast date across several assets.
The reported fix is to set the simulation's startup length to zero when calling the package's simulation function. The answer suggests that this enables the loop to produce the requested forecast for each step rather than only the initial one-step simulation. The post provides no diagnostic output or further explanation of why the default startup behavior causes the issue, so the recommendation is specific to the described code and package setup.
Key ideas
- The example uses a DCC-GARCH copula to simulate one-step-ahead returns for multiple assets.
- A rolling out-of-sample procedure updates the information set as each observation becomes available.
- The answer recommends setting the simulation startup length to zero to obtain forecasts across the full loop.
- The post does not report validation results or explain the underlying package behavior, so the fix may depend on the stated setup.
Tags
Full text
# Forecasting conditional returns in DCC-GARCH-copula approach in R
# Forecasting conditional returns in DCC-GARCH-copula approach in R
anyone who could help me interpreting and modifying this code?
I have a dataset and want to reserve the last 100 returns for out-of-sample analysis. After specifying and fitting the garch-spd-copula, in the for loop I fix a condition for $i=1$ and another for $i=2,...,100$, and compute these first calculations (presigma, preR, preQ, ...). Now, I want R to do the 1-step ahead forecast simulated 1000 times (n.sim=1 and m.sim=1000 in `cgarchsim` command) while incrementally consider the "extended" dataset (consider T for forecasting T+1, consider T+1 for forecasting T+2, ...). I would like the end result to be a 100x3x1000 array (100: observations, 3: assets, 1000: simulations) of 1-step ahead forecasts.
```
install.packages("rmgarch")
library(rmgarch)
data(dji30retw)
Dat = dji30retw[, 1:3, drop = FALSE]
uspec17 = ugarchspec(mean.model = list(armaOrder = c(0,0)),
variance.model = list(garchOrder = c(1,1), model = "sGARCH", variance.targeting=FALSE),
distribution.model = "norm")
spec17 = cgarchspec(uspec = multispec( replicate(3, uspec17) ), asymmetric = FALSE,
distribution.model = list(copula = "mvnorm", method = "Kendall",
time.varying = TRUE, transformation = "spd"))
fit17 <- cgarchfit(spec17, Dat, out.sample=100, spd.control=list(upper=0.95, lower=0.05, type="mle", kernel="normal"),
cluster=NULL, fit.control=list(eval.se=FALSE))
T = dim(Dat)[1]-100
simMu = simS = filtMu = filtS = matrix(NA, ncol = 3, nrow = 100)
simCor = simC = filtC = filtCor = array(NA, dim = c(3,3,100))
colSd = function(x) apply(x, 2, "sd")
specx17 = spec17
for(i in 1:3) specx17@umodel$fixed.pars[[i]] = as.list(fit17@model$mpars[fit17@model$midx[,i]==1,i])
setfixed(specx17)<-as.list(fit17@model$mpars[fit17@model$midx[,4]==1,4])
for(i in 1:100){
if(i==1){
presigma = matrix(tail(sigma(fit17), 1), ncol = 3)
prereturns = matrix(unlist(Dat[T, ]), ncol = 3, nrow = 1)
preresiduals = matrix(tail(residuals(fit17),1), ncol = 3, nrow = 1)
preR = last(rcor(fit17))[,,1]
diag(preR) = 1
preQ = fit17@mfit$Qt[[length(fit17@mfit$Qt)]]
preZ = tail(fit17@mfit$Z, 1)
tmp = cgarchfilter(specx17, Dat[1:(T+1), ], filter.control = list(n.old = T))
filtMu[i,] = tail(fitted(tmp), 1)
filtS[i,] = tail(sigma(tmp), 1)
filtC[,,i] = last(rcov(tmp))[,,1]
filtCor[,,i] = last(rcor(tmp))[,,1]
}
else{
presigma = matrix(tail(sigma(tmp), 1), ncol = 3)
prereturns = matrix(unlist(Dat[(T+i-1), ]), ncol = 3, nrow = 1)
preresiduals = matrix(tail(residuals(tmp),1), ncol = 3, nrow = 1)
preR = last(rcor(tmp))[,,1]
diag(preR) = 1
preQ = tmp@mfilter$Qt[[length(tmp@mfilter$Qt)]]
preZ = tail(tmp@mfilter$Z, 1)
tmp = cgarchfilter(specx17, Dat[1:(T+i-1), ], filter.control = list(n.old = T))
filtMu[i,] = tail(fitted(tmp), 1)
filtS[i,] = tail(sigma(tmp), 1)
filtC[,,i] = last(rcov(tmp))[,,1]
filtCor[,,i] = last(rcor(tmp))[,,1]
}
sim17 = cgarchsim(fit17, n.sim = 1, m.sim = 1000, startMethod = "sample", preR = preR, preQ = preQ, preZ = preZ,
prereturns = prereturns, presigma = presigma, preresiduals = preresiduals, cluster = NULL)
simx = t(sapply(sim17@msim$simX, FUN = function(x) x[1,]))
simMu[i,] = colMeans(simx)
simC[,,i] = sim17@msim$simH[[1]][,,1]
simCor[,,i] = sim17@msim$simR[[1]][,,1]
simS[i,] = sqrt(diag(simC[,,i]))
}
```
However, if I run this, as conditional returns (`sim17@msim$simX`) I obtain three 1-step ahead forecasts simulated 1000 times, no trace of the remaining 99 values to be estimated. Any idea why, and how to modify the code in order to have 100 estimates?
## Answer by Priyanshi Gupta (score 1)
https://quant.stackexchange.com/a/43469
In the line:
```
sim17 = cgarchsim(fit17, n.sim = 1, m.sim = 1000, startMethod = "sample", preR = preR, preQ = preQ, preZ = preZ,
prereturns = prereturns, presigma = presigma, preresiduals = preresiduals, cluster = NULL)
```
, you should add `n.start=0`:
```
sim17 = cgarchsim(fit17, n.sim = 1, n.start=0, m.sim = 1000, startMethod = "sample", preR = preR, preQ = preQ, preZ = preZ,
prereturns = prereturns, presigma = presigma, preresiduals = preresiduals, cluster = NULL)
```
It should work fine then.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.