garchmv.rpf

Discussions of ARCH, GARCH, and related models
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

garchmv.rpf

Unread post by ac_1 »

Hi Tom,


My aim is to generate multistep ahead 1% VaR and ES forecasts (and any appropriate analysis, using them or otherwise) for MV-GARCH models.

I've read https://estima.com/ecourse/samples/GARC ... hapter.pdf

Regarding GARCHMV.RPF https://estima.com/webhelp/topics/garchmvrpf.html

how do I generate them for
[1] DVECH model?
[2] DCC model, I've seen https://estima.com/webhelp/topics/garch ... strpf.html


To start [1] DVECH model

Code: Select all

*===============================
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})

*===============================
garch(p=1,q=1,pmethod=simplex,piters=10,$
   rvectors=rv,hmatrices=h,stdu=rvstd,vechmat=vechcomps) / xjpn xfra xsui

disp rv(%regend())
disp h(%regend())

*===============================
compute nfore=3
@mvgarchfore(steps=nfore) h rv

*===============================
compute t1 = %regend() + 1

disp 'Step 1 from @MVGARCHFore:'
disp h(t1)
disp 'vech: ' h(t1)(1,1) h(t1)(2,1) h(t1)(2,2) h(t1)(3,1) h(t1)(3,2) h(t1)(3,3)

*===============================
* Results
* --------

Step 1 from @MVGARCHFore:
      0.49810
      0.17470       0.45327
      0.28836       0.56119       0.80250

vech:        0.49810       0.17470       0.45327       0.28836       0.56119       0.80250

thanks,
Amarjit
TomDoan
Posts: 7777
Joined: Wed Nov 01, 2006 4:36 pm

Re: garchmv.rpf

Unread post by TomDoan »

VaR (and ES) to what?

The DVECH has an analytical formula for the extrapolated variance and, as with the univariate model, the extrapolated covariance matrix for the multiple step return is the sum of the covariance matrices you get for the intermediate horizons.
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

Re: garchmv.rpf

Unread post by ac_1 »

TomDoan wrote: Mon Oct 06, 2025 10:29 am VaR (and ES) to what?
VaR (and ES) for the portfolio. However, can they be calculauted for the single assets as-well from MV-GARCH?
TomDoan
Posts: 7777
Joined: Wed Nov 01, 2006 4:36 pm

Re: garchmv.rpf

Unread post by TomDoan »

Isn't a single asset a particular portfolio?
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

Re: garchmv.rpf

Unread post by ac_1 »

TomDoan wrote: Mon Oct 06, 2025 12:13 pm Isn't a single asset a particular portfolio?
Yes - with the weight=1 on that asset, 0 on the others. Computations for a single asset via MV-GARCH takes into account covariances.
TomDoan
Posts: 7777
Joined: Wed Nov 01, 2006 4:36 pm

Re: garchmv.rpf

Unread post by TomDoan »

Only in the trivial sense that a different model will give different results. The variance of a single asset portfolio depends only upon its particular diagonal element in the covariance matrix (i.e. its variance), not anything involving the other assets.
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

Re: garchmv.rpf

Unread post by ac_1 »

TomDoan wrote: Mon Oct 06, 2025 10:29 am The DVECH has an analytical formula for the extrapolated variance and, as with the univariate model, the extrapolated covariance matrix for the multiple step return is the sum of the covariance matrices you get for the intermediate horizons.
hmatrices=h is the fitted symmetric var/covar matrix, therefore 6 terms of interest.

Is DVECH method using the raw residuals or standardized residuals to generate the forecasts?

Code: Select all

garch(p=1,q=1,pmethod=simplex,piters=10,$
   rvectors=rv,hmatrices=h,stdu=rvstd,vechmat=vechcomps) / xjpn xfra xsui

* raw residuals
compute eps1 = rv(regend())(1)
compute eps2 = rv(regend())(2)
compute eps3 = rv(regend())(3)
There's a lot to this than just simply summing 6 elements of the extrapolated var/covar matrix (step 1 h already been forecast using @MVGARCHFore), calculating the cumulative portfolio variance using the 6 terms with chosen weights (and are they a user choice?), VaR and ES as per previous in the UV case but for the portfolio (inc. portfolio mean), to the multi-step ahead horizons :!:

I've also seen: https://estima.com/webhelp/topics/mvgar ... edure.html.
Maybe as a start extend tsay3p546.rpf to the 3 variables case DVECH model, generate 1 step ahead forecasts, thereafter multi-step's.
TomDoan
Posts: 7777
Joined: Wed Nov 01, 2006 4:36 pm

Re: garchmv.rpf

Unread post by TomDoan »

The formulas used in @MVGARCHFORE are covered on https://estima.com/webhelp/topics/garch ... ecast.html. It uses the raw residuals (for the first step; after that, the extrapolation uses the earlier forecasts). It can do any number of steps, not just one. And yes, you have to decide upon the portfolio.
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

Re: garchmv.rpf

Unread post by ac_1 »

TomDoan wrote: Tue Oct 07, 2025 8:05 am The formulas used in @MVGARCHFORE are covered on https://estima.com/webhelp/topics/garch ... ecast.html. It uses the raw residuals (for the first step; after that, the extrapolation uses the earlier forecasts). It can do any number of steps, not just one. And yes, you have to decide upon the portfolio.
An attempt to extend tsay3p546.rpf to the 3 variables case DVECH model, generate 1 step ahead forecasts.

I've coded VaR and ES as in UV:

comp VaR = -%beta(1) + (-%invnormal(.01)*sqrt(h))
comp ES = -%beta(1) + %density(%invnormal(.01))/(.01) * sqrt(h)

and TSay AFTS (2010) p.332: the m-instruments VaR formulae, but there is no ES formulae - I've used the 'same' as for VaR.

VaR on the portfolio appears to be a bit less than the sum of the individual VaR's (that makes sense to me w.r.t. MPT), similarly ES. CHF VaR and ES are highest as there is a large negative return approx. -5.1%.

Where are the weights in this example?

If correct I can attempt to extend to multi-steps. Please can you check.

Code: Select all

*===============================
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})


*===============================
* Univariate Models
* -----------------
*
* Create the three mean equations, and group them into a model
*
equation eq1 xjpn
# constant
equation eq2 xfra
# constant
equation eq3 xsui
# constant
group trimodel eq1 eq2 eq3

*
* Do the univariate GARCH models and forecast the variances. (You need
* to do the variance forecasts immediately after the GARCH instruction)
*
garch(equation=eq1,p=1,q=1,resids=a1,hseries=h1)
@garchfore(steps=1) h1 a1
garch(equation=eq2,p=1,q=1,resids=a2,hseries=h2)
@garchfore(steps=1) h2 a2
garch(equation=eq3,p=1,q=1,resids=a3,hseries=h3)
@garchfore(steps=1) h3 a3

*
* Forecast the means
*
forecast(model=trimodel,steps=1,results=rhat)
*
compute VaR1 = -rhat(1)(6238) + (-%invnormal(.01)*sqrt(h1(6238)))
compute VaR2 = -rhat(2)(6238) + (-%invnormal(.01)*sqrt(h2(6238)))
compute VaR3 = -rhat(3)(6238) + (-%invnormal(.01)*sqrt(h3(6238)))
compute ES1 =  -rhat(1)(6238) + %density(%invnormal(.01))/(.01) * sqrt(h1(6238))
compute ES2 =  -rhat(2)(6238) + %density(%invnormal(.01))/(.01) * sqrt(h2(6238))
compute ES3 =  -rhat(3)(6238) + %density(%invnormal(.01))/(.01) * sqrt(h3(6238))

vcv(print)
# a1 a2 a3

compute rho12  = %sigma(1,2) / sqrt(%sigma(1,1)*%sigma(2,2))
compute rho13  = %sigma(1,3) / sqrt(%sigma(1,1)*%sigma(3,3))
compute rho23  = %sigma(2,3) / sqrt(%sigma(2,2)*%sigma(3,3))
compute VaR123 = sqrt(VaR1^2 + VaR2^2 + VaR3^2 + 2*(rho12*VaR1*VaR2 + rho13*VaR1*VaR3 + rho23*VaR2*VaR3))
compute ES123 = sqrt(ES1^2  + ES2^2  + ES3^2  + 2*(rho12*ES1*ES2   + rho13*ES1*ES3   + rho23*ES2*ES3))
*
disp "Univariate Models"
disp "VaR on jpn "   +1*VaR1 "       " "ES on jpn "  +1*ES1
disp "VaR on fra "   +1*VaR2 "       " "ES on fra "  +1*ES2
disp "VaR on sui "   +1*VaR3 "       " "ES on sui "  +1*ES3
disp "VaR Overall"  +1*VaR123 "       "  "ES Overall" +1*ES123


*===============================
* Trivariate Model
* ----------------
*
* Create the three mean equations, and group them into a model
*
equation eq1 xjpn
# constant
equation eq2 xfra
# constant
equation eq3 xsui
# constant
group trimodel eq1 eq2 eq3

garch(model=trimodel,p=1,q=1,rvectors=rv,hmatrices=h) / xjpn xfra xsui

@mvgarchfore(steps=1) h rv
forecast(model=trimodel,steps=1,results=rhat)

compute VaR1 = -rhat(1)(6238) + (-%invnormal(.01)*sqrt(h(6238)(1,1)))
compute VaR2 = -rhat(2)(6238) + (-%invnormal(.01)*sqrt(h(6238)(2,2)))
compute VaR3 = -rhat(3)(6238) + (-%invnormal(.01)*sqrt(h(6238)(3,3)))
compute ES1 =  -rhat(1)(6238) + %density(%invnormal(.01))/(.01) * sqrt(h(6238)(1,1))
compute ES2 =  -rhat(2)(6238) + %density(%invnormal(.01))/(.01) * sqrt(h(6238)(2,2))
compute ES3 =  -rhat(3)(6238) + %density(%invnormal(.01))/(.01) * sqrt(h(6238)(3,3))

compute rho12 = h(6238)(1,2)/sqrt(h(6238)(1,1)*h(6238)(2,2))
compute rho13 = h(6238)(1,3)/sqrt(h(6238)(1,1)*h(6238)(3,3))
compute rho23 = h(6238)(2,3)/sqrt(h(6238)(2,2)*h(6238)(3,3))
compute VaR123 = sqrt(VaR1^2 + VaR2^2 + VaR3^2 + 2*(rho12*VaR1*VaR2 + rho13*VaR1*VaR3 + rho23*VaR2*VaR3))
compute ES123 = sqrt(ES1^2  + ES2^2  + ES3^2  + 2*(rho12*ES1*ES2   + rho13*ES1*ES3   + rho23*ES2*ES3))

disp "Trivariate Model"
disp "VaR on jpn "   +1*VaR1 "       " "ES on jpn "  +1*ES1
disp "VaR on fra "   +1*VaR2 "       " "ES on fra "  +1*ES2
disp "VaR on sui "   +1*VaR3 "       " "ES on sui "  +1*ES3
disp "VaR Overall"  +1*VaR123 "       "  "ES Overall" +1*ES123
TomDoan
Posts: 7777
Joined: Wed Nov 01, 2006 4:36 pm

Re: garchmv.rpf

Unread post by TomDoan »

The Tsay code is extremely clumsy. The model gives you a multivariate normal (or multivariate t) and a portfolio converts that into a univariate Normal (or t) as a weighted average of the elements. That is much more easily computed by using matrix calculations than by expanding the way Tsay does---I suspect he does that for illustrating how the correlation comes into play, but it isn't how anyone would do the calculation in practice.

The ES is just a derived statistic from the mean and variance/standard deviation of the Normal (or t).

The Tsay example is, by assumption, equally weighted---see the second sentence in 10.7.
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

Re: garchmv.rpf

Unread post by ac_1 »

TomDoan wrote: Wed Oct 08, 2025 8:14 am The Tsay code is extremely clumsy. The model gives you a multivariate normal (or multivariate t) and a portfolio converts that into a univariate Normal (or t) as a weighted average of the elements. That is much more easily computed by using matrix calculations than by expanding the way Tsay does---I suspect he does that for illustrating how the correlation comes into play, but it isn't how anyone would do the calculation in practice.

The ES is just a derived statistic from the mean and variance/standard deviation of the Normal (or t).

The Tsay example is, by assumption, equally weighted---see the second sentence in 10.7.
Are my calculations correct for 3 assets as applied to the g10xrate.xls data?

Further, how best to implement in RATS using matrices, transparent as possible, and easily extendable to multi-steps?
TomDoan
Posts: 7777
Joined: Wed Nov 01, 2006 4:36 pm

Re: garchmv.rpf

Unread post by TomDoan »

Obviously, the ES is completely wrong. And it looks like you are missing the means in the VaR calculation---the formula in 7.2.2 of Tsay applies only to multivariate Normals with mean 0.

The GARCH model generates a multivariate Normal distribution for the future returns. Given a set of portfolio weights, you convert that into a univariate Normal distribution. The VaR and ES are functions of the mean and standard deviation of that. See Appendix B (and Appendix A if you need it) to Chapter 8 in Tsay for the properties of a multivariate Normal.
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

Re: garchmv.rpf

Unread post by ac_1 »

TomDoan wrote: Wed Oct 08, 2025 12:30 pm Obviously, the ES is completely wrong. And it looks like you are missing the means in the VaR calculation---the formula in 7.2.2 of Tsay applies only to multivariate Normals with mean 0.

The GARCH model generates a multivariate Normal distribution for the future returns. Given a set of portfolio weights, you convert that into a univariate Normal distribution. The VaR and ES are functions of the mean and standard deviation of that. See Appendix B (and Appendix A if you need it) to Chapter 8 in Tsay for the properties of a multivariate Normal.
I'm sorry - I don't fully understand!

I've included an equally-weighted mean into VaR123.

compute VaR123 = - (1.0/3.0*(rhat(1)(6238) + rhat(2)(6238) + rhat(3)(6238))) $
+ sqrt(VaR1^2 + VaR2^2 + VaR3^2 + 2*(rho12*VaR1*VaR2 + rho13*VaR1*VaR3 + rho23*VaR2*VaR3))

But I don't think that's correct either!

Isn't this just portfolio theory?

Using each of the assets: weights, forecast means and forecast h's:
portfolio mean: p_mu = (weights * means)
portfolio variance: p_var = ( tr(weights) * h's * (weights))

And then VaR and ES in the usual way?
comp VaR123 = -p_mu + (-%invnormal(.01)*sqrt(p_var))
comp ES123 = -p_mu + (%density(%invnormal(.01))/(.01)*sqrt(p_var))
TomDoan
Posts: 7777
Joined: Wed Nov 01, 2006 4:36 pm

Re: garchmv.rpf

Unread post by TomDoan »

The formula in Tsay works in the one specific case and in no other and you can't tweak it to work in general. Yes, if the distribution of returns is MV Normal, those are the formulas.
ac_1
Posts: 467
Joined: Thu Apr 15, 2010 6:30 am

Re: garchmv.rpf

Unread post by ac_1 »

TomDoan wrote: Thu Oct 09, 2025 3:43 pm The formula in Tsay works in the one specific case and in no other and you can't tweak it to work in general. Yes, if the distribution of returns is MV Normal, those are the formulas.
MV-GARCH 1-step ahead VaR and ES is reasonably straightforward either using "long-hand" or matrices:

Code: Select all

compute [rect] p_w=%fill(1,3,1.0/3.0); *equally-weighted

make p_rhat
# rhat

comp p_mu = %scalar(p_w * tr(p_rhat))
comp p_var = %scalar(p_w * h(6238) * tr(p_w))
For MV-GARCH how do I generate multi-step ahead VaR and ES forecasts like in UV-GARCH https://estima.com/webhelp/topics/garch ... casts.html as I need to accumulate at each step ahead.

"By contrast, a Value at Risk (VaR) calculation is generally based upon the distribution of a holding period return for a certain number of periods. If the data are log period-to-period returns, then the log n-period returns will be the sum of the n consecutive period-to-period returns. The mean forecast of the n-period return will be the sum of the forecast period-to-period returns over n periods..."

I've seen https://estima.com/webhelp/topics/garch ... ecast.html

So, something like:

Code: Select all

forecast(model=trimodel,steps=10,results=rhat)
@mvgarchfore(steps=10) h rv
sstats %regend()+1 %regend()+10 h>>var10 rhat>>mean10
But I need formulae instructions for h and rhat ?

Although, I have managed to generate TOOS forecasts

Code: Select all

garch(model=trimodel,p=1,q=1,rvectors=rv,hmatrices=hh,method=BFGS) / xjpn xfra xsui
forecast(model=trimodel,steps=3,results=rhat)
@mvgarchfore(steps=3) hh rv

* cumulative forecasts var/cov matrix
comp hhcumsum1 = hh(6238); * the 1-step
comp hhcumsum2 = hh(6238) + hh(6239)
comp hhcumsum3 = hh(6238) + hh(6239) + hh(6240)
And using the hhcumsum's in the VaR and ES formulae.

However, would like to know a better way as in UV GARCH Forecasts.
Post Reply