RATS 10.1
RATS 10.1

GARCHBOOT.RPF is an example of parametric bootstrapping of a GARCH model (for out-of-sample simulation of returns). It does a Value at Risk (VaR) calculation for the dollar/yen exchange rate using a bootstrapped GARCH(1,1) model to generate the simulated returns. See, for instance, Tsay(2010) for more on calculation of VaR.

 

EGARCHBOOTSTRAP.RPF demonstrates bootstrapping of EGARCH models while GARCHMVBOOTSTRAP.RPF shows bootstrapping with a multivariate GARCH model.


You can’t simply take bootstrap draws of the residuals from a GARCH process because of the serial dependence of the variance process. Instead, the estimated residuals are standardized by dividing by the square root of their estimated variance, and the GARCH process is simulated out of sample with the bootstrapped standardized residuals scaled up by the simulated variance. This is a form of parametric bootstrap.

 

The raw data are 100 x US$/Japanese yen (or US cents/yen). In converting to returns, for GARCH modeling, it's generally best to multiply by 100 to give the data a more easily managed scale.

 

all 6237

open data g10xrate.xls

data(format=xls,org=columns) / usxjpn

*

* Convert to percent daily returns

*

set x = 100.0*log(usxjpn/usxjpn{1})

 

This estimates a basic GARCH(1,1) model, saving both the residuals (into U) and variances (into H):

 

garch(p=1,q=1,resids=u,hseries=h) / x

 

This creates a forecasting formula from the results of the GARCH estimation. GSTART and GEND are the regression range, which we need for drawing standardized residuals. B0 is the mean of the returns (as estimated by the GARCH model), which will be added in to the simulated zero-mean returns to get the estimate of a period-to-period return. If you want to assume zero mean returns, add the NOMEAN instruction to the GARCH above, and change the line to compute b0=0.
 

compute gstart=%regstart(),gend=%regend()

compute b0=%beta(1)

compute chat=%beta(%nregmean+1),ahat=%beta(%nregmean+2),bhat=%beta(%nregmean+3)

frml hf = chat+bhat*h{1}+ahat*u{1}^2

 

This creates a standardized version of the historical residuals. These we can use in the bootstrap, since they've had the dependence on the time-varying variance removed.

 

set ustd gstart gend = u/sqrt(h)
 

SPAN is the number of periods over which returns are to be computed. NDRAWS is the number of bootstrapping draws.

 

compute span=10

compute ndraws=10000

 

This extend the H series out beyond the end of the data (values aren’t important—this is just to get the extra space).

 

set h gend+1 gend+span = h(gend)

 

We are going to generate NDRAWS sets of SPAN (here 10) step out-of-sample returns, creating a VECTOR of the results. Those are what we will analyze for estimating the VaR. The pseudo-code for the calculation of the draws is:

 

dec vect returns(ndraws)

do draw=1,ndraws

   ...(1) randomly draw standardized u's

   ...(2) sequentially generate h from the data and simulated data, while

   ...(3) generating u by rescaling the standardized u by the simulated standard deviation.

   ...(4) add up the period by period returns to get the simulated multi-period returns

end do draw

 

The BOOT instruction is used in handling the step (1) inside the loop. This draws random entry numbers from GSTART to GEND, creating the SERIES of INTEGERS named ENTRIES over the simulation range from GEND+1 to GEND+SPAN. USTDDRAW is then the bootstrapped standardized residuals. (Note that if, instead of bootstrapping, you wanted random number simulations, you would just replace the right side of SET USTDDRAW with %RAN(1.0)).

 

   boot entries gend+1 gend+span gstart gend

   set ustdDraw gend+1 gend+span = ustd(entries)
 

These combines steps (2) and (3) to simulate the GARCH model out of sample, first computing a new value for H (which depends only upon past values of U and H), then scaling up the draw for the standardized residuals by the square root of the just computed H.

  

   set u        gend+1 gend+span = (h(t)=hf(t)),ustdDraw(t)*sqrt(h(t))
 

This uses SSTATS to compute the cumulative return over the span. As written, this allows for the continuation of the sample mean return.

  

sstats gend+1 gend+span b0+u>>returns(draw)

 

That completes the loop. When we are done with that we have a VECTOR of size NDRAWS with the simulated SPAN period returns. The extreme left tails are used to determine the Value at Risk. By convention, that is reported as a positive number, so the values of the quantiles are sign-flipped. This also computes the Expected Shortfall (ES) which is the expected value of returns conditional on the loss being below the corresponding VaR threshold. Similarly, that is conventionally positive. That's done using SSTATS running over the elements of the VECTOR. Because a VECTOR doesn't have an "entry" coding, the (T)'s are necessary in the SSTATS expression.

 

compute [vect] pvals=||.01,.05,.10||

compute [vect] VaR=%fractiles(returns,pvals)

report(action=define,hlabels=||"P","VaR/100 Yen","ES/100 Yen"||)

do i=1,3

   sstats(mean) 1 ndraws %if(returns(t)<VaR(i),returns(t),%na)>>es

   report(atrow=i,atcol=1) pvals(i) -VaR(i) -es

end do i

report(action=format,picture="*.###")

report(action=show)

Full Program

 

all 6237
open data g10xrate.xls
data(format=xls,org=columns) / usxjpn
*
* Convert to percent daily returns
*
set x = 100.0*log(usxjpn/usxjpn{1})
*
* Estimate the GARCH(1,1) model.
*
garch(p=1,q=1,resids=u,hseries=h) / x
*
* Generate a forecasting formula from the results of the GARCH
* estimation. gstart and gend are the regression range, which we need
* for drawing standardized residuals.
*
compute gstart=%regstart(),gend=%regend()
compute b0=%beta(1)
compute chat=%beta(%nregmean+1),ahat=%beta(%nregmean+2),bhat=%beta(%nregmean+3)
frml hf = chat+bhat*h{1}+ahat*u{1}^2
*
* Standardize the historical residuals
*
set ustd gstart gend = u/sqrt(h)
*
* span is the number of periods over which returns are to be computed.
* ndraws is the number of bootstrapping draws
*
compute span=10
compute ndraws=10000
*
* Extend out the h series (values aren't important--this is just to get
* the extra space).
*
set h gend+1 gend+span = h(gend)
*
dec vect returns(ndraws)
do draw=1,ndraws
   *
   * This draws standardized u's from the ustandard series
   *
   boot entries gend+1 gend+span gstart gend
   *
   * Simulate the GARCH model out of sample, scaling up the standardized
   * residuals by the square root of the current h.
   *
   set ustdDraw gend+1 gend+span = ustd(entries)
   set u        gend+1 gend+span = (h(t)=hf(t)),ustdDraw(t)*sqrt(h(t))
   *
   * Figure out the cumulative return over the span. As written, this
   * allows for the continuation of the sample mean return. If you want
   * to look at zero mean returns, take the b0 out.
   *
   sstats gend+1 gend+span b0+u>>returns(draw)
end do draw
*
* Compute desired quantiles of the returns. These will all be negative;
* VaR however, is quoted as a positive number, so the sign gets flipped.
* Because of the use of 100* in computing the returns, these will be
* returns to 100 yen.
*
* This also computes the Expected Shortfall (ES), which is the
* conditional mean given that the return is at or below the VaR
* threshold. Again, this is conventionally quoted as positive.
*
compute [vect] pvals=||.01,.05,.10||
compute [vect] VaR=%fractiles(returns,pvals)
report(action=define,hlabels=||"P","VaR/100 Yen","ES/100 Yen"||)
do i=1,3
   sstats(mean) 1 ndraws %if(returns(t)<VaR(i),returns(t),%na)>>es
   report(atrow=i,atcol=1) pvals(i) -VaR(i) -es
end do i
report(action=format,picture="*.###")
report(action=show)

Output

The Value-at-Risk (VaR) and ES calculations depend upon random numbers and so will not be exactly reproducible.

 

GARCH Model - Estimation by BFGS

Convergence in    21 Iterations. Final criterion was  0.0000073 <=  0.0000100
 

Dependent Variable X

Usable Observations                      6236

Log Likelihood                     -5395.4384

 

    Variable                        Coeff      Std Error      T-Stat      Signif

************************************************************************************

1.  Mean(X)                      0.0001874860 0.0064882559      0.02890  0.97694737

2.  C                            0.0074286000 0.0011069614      6.71080  0.00000000

3.  A                            0.1762880839 0.0118295334     14.90237  0.00000000

4.  B                            0.8372689759 0.0095560817     87.61635  0.00000000

 

  P   VaR/100 Yen ES/100 Yen

0.010       5.615      8.004

0.050       3.259      4.886

0.100       2.354      3.817


 


Copyright © 2024 Thomas A. Doan