EGARCH Model Simulations/Bootstrapping

Use this forum for posting example programs or short bits of sample code.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

EGARCH Model Simulations/Bootstrapping

Unread post by TomDoan »

These are a pair of almost identical programs which do forecasts of EGARCH models using random number simulation (Monte Carlo) and bootstrapping. Because of their structure, EGARCH models don't have a simple recursive calculation for out-of-sample forecasts, so you have to do some type of simulation. These both use the median of the "cloud" as the forecast and show a 90% confidence interval.

EGARCHSIMULATE.RPF
EGARCHBOOTSTRAP.RPF
garch.asc
Data file
(67.28 KiB) Downloaded 1464 times
shreya
Posts: 6
Joined: Wed Aug 06, 2014 3:43 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by shreya »

Hi!

i am trying to forecast VaR values for EGARCH and have run the following codes:
OPEN DATA "C:\Users\shreya\Desktop\WINRATS\FTSE\Ftse all share.xls"
DATA(FORMAT=XLS,ORG=COLUMNS) 1 2533 Date price lnreturns
GARCH(P=1,Q=1,EXP,ASYMMETRIC,distribution=GED,hseries=H) / LNRETURNS
compute c=%beta(2),a=%beta(3),b=%beta(4),d=%beta(5)
compute gstart=%regstart(),gend=%regend()
set stdu = %resids/sqrt(h)
compute ndraws=10000
compute nsteps=50
compute bstart=gend+1,bend=gend+nsteps
set h bstart bend = %na
dec series[vect] hdraws
gset hdraws bstart bend = %zeros(ndraws,1)
do draw=1,ndraws
boot entries bstart bend gstart gend
set stdu bstart bend = h=exp(c+b*log(h{1})+a*abs(stdu{1})+d*%max(stdu{1},0.0)),stdu(entries(t))
do t=bstart,bend
compute hdraws(t)(draw)=h(t)
end do t
end do draw
set lower bstart bend = %fractiles(hdraws(t),||.05||)(1)
set upper bstart bend = %fractiles(hdraws(t),||.95||)(1)
set median bstart bend = %fractiles(hdraws(t),||.50||)(1)
graph(header="Bootstrapped Forecasts for EGARCH model") 4
# h 1800 1867
# median 1868 1868+nsteps-1
# lower 1868 1868+nsteps-1 3
# upper 1868 1868+nsteps-1 3
PRINT / h

however, my data is of log returns and there are only 2533 observations but the forecasts comes out to be 2583 observations. Please tell me if the codes are correct and a solution to the aforementioned problem.

thanks!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by TomDoan »

I'm not sure what you think is a problem. You have 2533 observations and ask for 50 forecast steps. Isn't that 2583? Obviously, the graphs at the end are illustrations for the original data set.
shreya
Posts: 6
Joined: Wed Aug 06, 2014 3:43 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by shreya »

hi!

thanks a lot, i missed that point i was expecting a one-day forecast.

further to that, i am trying to do back testing/stress testing of value at risk using kupiec's test and christopher's test. can you help me with the coding please.

it would be great help.

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

Re: EGARCH Model Simulations/Bootstrapping

Unread post by TomDoan »

If you just need the one-step-ahead errors and variances, those don't need anything special---just the HSERIES option for the variances and %RESIDS for the residuals.

Kupiec's test is a summary of how well a particular VaR calculation worked. What measure of VaR are you planning to use?
shreya
Posts: 6
Joined: Wed Aug 06, 2014 3:43 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by shreya »

hi!

I ONLY CHANGED THE NSTEPS TO 1 IN THE ABOVE CODING, IS THAT THE RIGHT WAY TO FORECAST?

I am doing a project and got stuck at the major step. As i mentioned before I have been trying to estimate Value at risk for garch, egarch, gjr garch. I have got the forecast for volatility, however i am facing problems in the next step for calculating Value at risk for all 2533 observations.

I realized my idea of calculating Value at risk is might not right and needs proper coding. I request you to please check my codes given below.
Also, if possible could you please send me the codes for one-day ahead VaR for student t and GED AT 5% and 1% confidence interval, as i am not aware of them.

it would be great help.

i am posting my codes for forecasting the garch model and calculating VaR

GARCH(P=1,Q=1,HSERIES=H,RESIDS=U) / LNRETURNS
SET UU=U**2
COM VC=%BETA(2),VB=%BETA(4),VA=%BETA(3)
FRML HEQ H = VC+VB*H{1}+VA*UU{1}
FRML UEQ UU = H
GROUP GARCHMOD HEQ>>H UEQ>>UU
FORECAST(MODEL=GARCHMOD,FROM=1,TO=2533)
PRINT / H
dofor i = 1 to 2533
disp "5% VaR on ftse" %invnormal(.95)*sqrt(h(i))
disp "1% VaR on ftse" %invnormal(.99)*sqrt(h(i))
end dofor
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by TomDoan »

No. That's for multiple step forecasts. See http://www.estima.com/textbooks/tsay_3/tsayp334.rpf for an example of VaR calculations using one-step ahead GARCH model forecasts. As I said, the one-step in-sample forecasts of the variance (for any type of GARCH model) are computed as part of the estimation process and you can get them with the HSERIES option on GARCH.
shreya
Posts: 6
Joined: Wed Aug 06, 2014 3:43 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by shreya »

i need to calculate one step ahead out-of-sample forecast FOR GARCH. Also i need one-step ahead VaR for all 2533 observations that is from 1 to 2533.

i saw the link you recommended, could you explain me the meaning of these two codes in that link:-

compute r9191=%beta(1)+%beta(2)*ibmlog(9189)
compute h9191=%beta(3)+%beta(4)*res(9190)^2+%beta(5)*h(9190)

what is r? since residuals is named as res in the garch code

in my coding as written in previous post isnt the following same as above

COM VC=%BETA(2),VB=%BETA(4),VA=%BETA(3)
FRML HEQ H = VC+VB*H{1}+VA*UU{1}

here U is my residuals and uu = u**2.

ALSO, WHATS THE DIFFERENCE BETWEEN
disp "5% VaR on 10000000" -10000000*(r9191+%invnormal(.05)*sqrt(h9191))
AND
disp "5% VaR on 10,000,000" %invnormal(.95)*sqrt(h(9191))*10000000
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by TomDoan »

shreya wrote:i need to calculate one step ahead out-of-sample forecast FOR GARCH. Also i need one-step ahead VaR for all 2533 observations that is from 1 to 2533.

i saw the link you recommended, could you explain me the meaning of these two codes in that link:-

compute r9191=%beta(1)+%beta(2)*ibmlog(9189)
compute h9191=%beta(3)+%beta(4)*res(9190)^2+%beta(5)*h(9190)

what is r? since residuals is named as res in the garch code

in my coding as written in previous post isnt the following same as above

COM VC=%BETA(2),VB=%BETA(4),VA=%BETA(3)
FRML HEQ H = VC+VB*H{1}+VA*UU{1}

here U is my residuals and uu = u**2.

ALSO, WHATS THE DIFFERENCE BETWEEN
disp "5% VaR on 10000000" -10000000*(r9191+%invnormal(.05)*sqrt(h9191))
AND
disp "5% VaR on 10,000,000" %invnormal(.95)*sqrt(h(9191))*10000000
TSAYP330 uses an IGARCH(1,1) model with no mean, which is basically the RiskMetrics model for doing VaR. Because of the nature of the GARCH model, the forecast mean is 0, which simplifies the calculation. Most of the other Tsay VaR examples have a non-trivial mean model. Since the mean shifts the distribution, that has to be taken into account in computing the VaR. The first of those last two have a non-zero mean (r9191) and the second doesn't.

Kupiec's test has to be done "in-sample" since you have to evaluate how well the VaR calculation actually performed. Could you be more specific about how you plan to compute the VaR?
shreya
Posts: 6
Joined: Wed Aug 06, 2014 3:43 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by shreya »

Hi tom!

Thanks a lot for explaining.

I learned three methods of calculating VaR parametric approach, historical simulation and monte carlo simulation.
I plan to compute by using parametric approach with an assumption of zero mean.

VaR = c(q)*sd, where c(q) is critical value of assumed distribution and sd is standard deviation.

Also i need one day ahead VaR values.

Further, i need to do backtesting with Kupiecs test and christopher's test.
shreya
Posts: 6
Joined: Wed Aug 06, 2014 3:43 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by shreya »

hi tom

I was trying to forecast EGARCH model for one step ahead Value at risk. I think my codes are not producing the right results. Could you please send me the codes for one-step ahead forecasting.

it would be great help!

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

Re: EGARCH Model Simulations/Bootstrapping

Unread post by TomDoan »

shreya wrote:Further, i need to do backtesting with Kupiecs test and christopher's test.
See http://www.estima.com/forum/viewtopic.php?f=8&t=2201
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: EGARCH Model Simulations/Bootstrapping

Unread post by TomDoan »

shreya wrote:hi tom

I was trying to forecast EGARCH model for one step ahead Value at risk. I think my codes are not producing the right results. Could you please send me the codes for one-step ahead forecasting.

it would be great help!

thanks
With this model,

GARCH(P=1,Q=1,EXP,ASYMMETRIC,distribution=GED,hseries=H) / LNRETURNS

the VAR limit on the residual for the final data point in the estimation period can be computed by

compute VaRThresh=%invged(alpha,%beta(6))*sqrt(h(%regend()))

where alpha is the desired VaR percentage. Compare %resids(%regend()) with that. If the residual is smaller (more negative), then you have a hit, if not, you don't. You don't have to do the one-step forecast since that's done internally as part of the function evaluation.


Last bumped by TomDoan on Sun Aug 27, 2023 10:01 am.
Post Reply