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