I would like to ask this, so I have the following code for univariate VAR, with GARCH. I'm trying to edit it calculate VAR for a portfolio (consist of 10 assets).
I can assign weights and just do a univariate Garch for the portfolio, but I think it's better to perform multivariate.
I hope you could give me some suggestion, really appreciate it.
Code: Select all
rndseed 1764
!nreps= 10000
!horizon = 10
!alpha = 5 '(in percent)
smpl @all
series r_t = dlog(general_motors)
smpl 1 5119
equation eq1.arch(m=100,c=1E-5) r_t c 'runs a GARCH(1,1)
eq1.makegarch h_t 'generate portofio variances (same as proc > Make GARCH variance series)
series varepsilon_t = r_t - @coefs(1) 'calc the standard errors (could just get resids)
series z_t = varepsilon_t/(h_t^0.5) 'calc the standardised residuals
expand 1 !nreps
smpl @all
series aggret
series bstrapz
!hend = !horizon + 5119
smpl 5120 !hend
eq1.forecast(f=na) r_tf varepsilon_tf h_tf ' forecast the portfolio mean, s.e. and variance
for !z=1 to !nreps 'looping over reps
for !i = 1 to !horizon 'looping over the horizon
bstrapz(5120+!i) = z_t(1 + @round(@rnd*5119)) 'bootstrapping a random std. resid.
next
r_tf = @coefs(1) + bstrapz*(h_tf^0.5)
aggret(!z) = @sum(r_tf)
next
smpl @all
sort aggret 'sorting in this way will jumble up all other series - must do last (or just comment out and go manual)
scalar _{!horizon}d_{!alpha}pc_var_ret = aggret((!alpha/100)*!nreps)
