* * Example of bootstrapping for MV GARCH models. This uses the same * data set as the GARCHMV.RPF example. * open data g10xrate.xls data(format=xls,org=columns) 1 6237 usxjpn usxfra usxsui * set xjpn = 100.0*log(usxjpn/usxjpn{1}) set xfra = 100.0*log(usxfra/usxfra{1}) set xsui = 100.0*log(usxsui/usxsui{1}) *********************************************************************** *********************************************************************** * * Multivariate GARCH model with DVECH. This same basic idea applies * to any of the models supported by @MVGARCHTOVECH. You have to * save the residuals (most conveniently done using RVECTORS since * we need to keep the time periods together) and the H matrices. * The standardized residuals are needed to provide the shocks for * the parametric bootstrap. * garch(p=1,q=1,pmethod=simplex,piters=10,\$ rvectors=rv,hmatrices=h,stdu=rvstd) / xjpn xfra xsui compute gstart=%regstart(),gend=%regend() * @MVGARCHtoVECH(mv=standard) * * Create the series of outer products of the residuals * dec series[symm] uu gset uu gstart gend = %outerxx(rv) * * Create the formula for updating the GARCH variance * dec frml[symm] hf frml hf = %vectosymm(%%vech_c+%%vech_b*%vec(h{1})+%%vech_a*%vec(uu{1}),%nvar) * * Bootstrap model for 10 periods out-of-sample. 10000 repetitions * compute span=10 compute ndraws=10000 compute bstart=gend+1,bend=gend+span * * Extend UU and H out-of-sample. (Values don't really matter at this * point). * gset uu bstart bend = uu{1} gset h bstart bend = h{1} * dec series[vect] portfolio gset portfolio bstart bend = %unitv(%nvar,1) * set returns 1 ndraws = %na * compute [vector] ones=%fill(%nvar,1,1.0) * do draw=1,ndraws boot entries bstart bend gstart gend * * Update the variance, post-multiply the shuffled standardized * residuals by a square root of the variance, save the outer * product and return the re-flated residuals. * gset rv bstart bend = h=hf,uboot=%decomp(h)*rvstd(entries(t)),uu=%outerxx(uboot),uboot * * Compute cumulative return on minimum variance portfolio. (This * assumes zero mean returns). * gset portfolio bstart bend = hinv=inv(h),hinv*ones/%qform(hinv,ones) sstats bstart bend %dot(portfolio,rv)>>returns(draw) end do draw * * Get quantiles on the performance of the portfolio * stats(fractiles) returns 1 ndraws *********************************************************************** *********************************************************************** * * MV GARCH with DCC * garch(p=1,q=1,mv=dcc,rvectors=rv,hmatrices=h) / xjpn xfra xsui compute gstart=%regstart(),gend=%regend() * * Transform residuals into standardized form. For a DCC model, * there are two types of standardizations necessary - one set * transforms the residuals down to fully uncorrelated with unit * variances (RVSTD) and one which merely standardizes each variance * but leaves correlations intact (RVSTDC). Also save the vectors of * variances and squared residuals. * dec series[vect] rvstd rvstdc dec series[vect] hv uuv gset rvstd gstart gend = %solve(%decomp(h(t)),rv(t)) gset rvstdc gstart gend = rv(t)./%xdiag(h(t)) gset hv gstart gend = %xdiag(h(t)) gset uuv gstart gend = rv(t).*rv(t) * * Set up the individual variance recursions * dec vect %%g_c(%nvar) %%g_a(%nvar) %%g_b(%nvar) * * Pull out the DCC recursion coefficients * compute %%dcc_a=%beta(%nreg-1),%%dcc_b=%beta(%nreg) ewise %%g_c(i)=%beta(%nregmean+0*%nvar+i) ewise %%g_a(i)=%beta(%nregmean+1*%nvar+i) ewise %%g_b(i)=%beta(%nregmean+2*%nvar+i) * dec frml[vect] hvf frml hvf = %%g_c+%%g_b.*hv{1}+%%g_a.*uuv{1} * * The "constant" term in the DCC recursion is based upon the * unconditional correlation matrix of the data. * vcv(center) # xjpn xfra xsui compute qbar=%cvtocorr(%sigma) * * Set up the DCC recursion * dec series[symm] q dec frml[symm] qf frml qf = (1-%%dcc_a-%%dcc_b)*qbar+%%dcc_b*q{1}+%%dcc_a*%outerxx(rvstdc{1}) * * The Q sequence can't be backed out of the information available from * GARCH. This re-generates it. * gset q gstart gstart = qbar gset q gstart+1 gend = qf(t) * * Bootstrap model for 10 periods out-of-sample. 10000 repetitions * compute span=10 compute ndraws=10000 compute bstart=gend+1,bend=gend+span * * Extend various objects out-of-sample. (Values don't really matter at * this point). * gset uuv bstart bend = uuv{1} gset hv bstart bend = hv{1} gset h bstart bend = h{1} gset q bstart bend = q{1} gset rvstd bstart bend = rvstd{1} gset rvstdc bstart bend = rvstdc{1} * dec series[vect] portfolio gset portfolio bstart bend = %unitv(%nvar,1) * set returns 1 ndraws = %na * compute [vector] ones=%fill(%nvar,1,1.0) * do draw=1,ndraws boot entries bstart bend gstart gend * * Do the DCC recursion and the recursion for the univariate variances, * convert the pair into the covariance matrix, post-multiply the * shuffled standardized residuals by a square root of the variance, * save the squares for the next GARCH recusion, save the standardized * residuals for the next DCC recursion, and return the re-flated * residuals. * * To do the bootstrap, update Q(t) and HV(t). Convert Q to a * correlation matrix and create H(t) from the correlations and the * variances in HV. Use that to reflate the shuffled fully * standardized residuals. * gset rv bstart bend = q=qf,hv=hvf,h=%corrtocv(%cvtocorr(q),hv),\$ uboot=%decomp(h)*rvstd(entries(t)),uuv=uboot.*uboot,rvstdc=uboot./hv,uboot * * Compute cumulative return on minimum variance portfolio. (This * assumes zero mean returns). * gset portfolio bstart bend = hinv=inv(h),hinv*ones/%qform(hinv,ones) sstats bstart bend %dot(portfolio,rv)>>returns(draw) end do draw * * Get quantiles on the performance of the portfolio * stats(fractiles) returns 1 ndraws