# [R-SIG-Finance] rugarch and copulas

alexios ghalanos alexios at 4dscape.com
Wed Nov 21 10:50:36 CET 2012

```This is not really a reproducible example...nevertheless, I am guessing
you are trying to generate the final point of the path at
simulation_time "horizon".
What you are forgetting is that the values in "simulation\$seriesSim" are
returns, so doing "exp(diffinv(test))[2]" on the last value (horizon) is
meaningless. What you want (probably) is:

... at simulation\$seriesSim[1:horizon,1]
one_simul[,i] <- tail(exp(diffinv(test)), 1)

-Alexios

On 21/11/2012 09:27, ludovic.theate wrote:
> Alexios,
>
> Sorry but I've got a last problem.
>
> I firstly simulated independant trajectories of my processes, and I find
> acceptable results.
>
> Then I tried to simulate correlated trajectories using the following
> function (as we discussed last week) :
>
> ##########################
> # Sim_Cop_Garch Function #
> ##########################
>
>
> sim_cop_garch <- function(mfit,cop,nsim,horizon){
> ncur = length(mfit)
>
> result <- NULL
> for(j in 1:nsim){
>
> # Simulation of nsim random values of the copulas: these are uniform
> #uni_res <- rCopula(horizon,cop)  # FIRST TRY
> uni_res <- matrix(runif(horizon*ncur),ncol=ncur,nrow=horizon)  # SECOND TRY
>
> # Inverse-transform : uniform values are transformed into appropriate values
> (e.g. norm, sstd,...)
> innov = matrix(NA, ncol = ncur, nrow = horizon)
> for(i in 1:ncur){
> 	gdist = mfit[[i]]@model\$modeldesc\$distribution
> 	lambda = ifelse(mfit[[i]]@model\$modelinc[18]>0,
> mfit[[i]]@fit\$ipars["ghlambda",1], 0)
> 	skew = ifelse(mfit[[i]]@model\$modelinc[16]>0,
> mfit[[i]]@fit\$ipars["skew",1],  0)
> 	shape = ifelse(mfit[[i]]@model\$modelinc[17]>0,
> mfit[[i]]@fit\$ipars["shape",1],  0)
> 	innov[,i] = qdist(gdist,uni_res[,i] , mu = 0, sigma = 1, lambda = lambda,
> skew = skew, shape = shape)}
>
> # Simulation of the ARIMA-GARCH model using the previously generated
> innovations
>
> one_simul <- matrix(NA,ncol=ncur,nrow=1)
> for(i in 1:ncur){
>
> test <- ugarchsim(mfit[[i]],n.sim=horizon,m.sim=1,
> custom.dist=list(name="sample",distfit=matrix(innov[,i],ncol=1,nrow=horizon)))@simulation\$seriesSim[horizon,1]
>
> one_simul[,i] <- exp(diffinv(test))[2] }
>
> result <- rbind(result,one_simul)
> }
> return(result)
> }
>
>
> The results I got for a Gaussian copula were clearly incorrect. So I
> modified the function to skip the copula-generated uniform random numbers
> (with the "first try" comment ) and I used the runif method instead. (with
> the "second try" comment)  Even when I do this, I find impossible results,
> so the problem doesn't come from the copula.
>
> I think I have maybe misunderstood the behavior of the custom.dist option in
> the ugarchsim method. Could you please have a look and tell me if you see
> something wrong ? Thanks a lot.
>
> Kind regards,
>
> Ludovic
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/rugarch-and-copulas-tp4647300p4650268.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> R-SIG-Finance at r-project.org 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.
>

```