[R-SIG-Finance] Question rmgarch package
daniel melendez
da_melendez at yahoo.com
Thu Jun 25 22:27:00 CEST 2015
Hello All - I am trying to complete a simulation based off of given information from a gogarchfit object but I seem to be obtaining really low VaR numbers. Can anyone help explain this? Also I saw on a previous post from the r-sig-finance mailing list that the standardized residuals can be obtain by taking the square root of the covariance matrix, however, I seem to be getting rather large numbers. Can anyone help explain this too? Any help would greatly appreciated. The code snippets are below: # specs for GO-GARCH model
#----------------------------------------------------------------------------
spec = gogarchspec(mean.model = list(model = 'constant'),
variance.model = list(model = 'eGARCH',
garchOrder = c(1, 1), variance.targeting = TRUE),
distribution = 'manig', ica = 'fastica',
ica.fix = list(A = est_mixing_matrix, K = whitening_matrix,
W = est_unmixing_matrix, U = est_rotation_matrix,
Kinv = dewhitening_matrix, Y = est_indep_components_matrix)) # GO-GARCH Fit
#----------------------------------------------------------------------------
cl <- makePSOCKcluster(3)
mod2 = gogarchfit(spec = spec, data = garchSeries, gfun = 'tanh', cluster = cl,
solver = "hybrid", firstEig = 1, lastEig = 4,
solver.control = list(trace = 1),
maxiter1 = 40000, epsilon = 1e-08, rseed = 972,
fit.control = list(stationarity = 1))
stopCluster(cl) # Simulation Generation
# --------------------------------------------------------------------------------
cl <- makePSOCKcluster(3)
sim1 <- gogarchsim(mod2, n.sim = 50, n.start = 0,
m.sim = 5000,
rseed = 214, cluster = cl)
stopCluster(cl) cf = convolution(sim1, weights = matrix(rep(1/10, 10), ncol = 10, nrow = 50))
VaR = matrix(NA, ncol = 2, nrow = 50)
colnames(VaR) = c('qfft[0.9999]', 'qfft[0.0001]')
for (i in 1:50){
qfx = qfft(cf, index = i)
VaR[i, 1] = qfx(0.9999)
VaR[i, 2] = qfx(0.0001)
}
matplot(VaR, type = 'l') #----------------------------------------------------------------------# Calculate the standardized residuals for the model
# ---------------------------------------------------------------------
residualsModel <- residuals(mod2)
cov.sq <- rcov(mod2)
sq.cov <- array(NA, dim = c(dim(cov.sq)[1],
dim(cov.sq)[2],
dim(cov.sq)[3]))
sq.cov.mat <- function (x){
tmp = svd(x)
sqrtx = tmp$u %*% sqrt(diag(tmp$d)) %*% t(tmp$u)
return(sqrtx)
}
for(i in 1:dim(cov.sq)[3]){
sq.cov[,,i] <- solve(sq.cov.mat(cov.sq[,,i]))
}
stand.resid <- matrix(NA, ncol = ncol(residualsModel), nrow = nrow(residualsModel))
for(i in 1:dim(sq.cov)[3]){
stand.resid[i,] <- t(sq.cov[,,i] %*% as.numeric(residualsModel[i,]))
} Regards
Daniel Melendez
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list