Use of GARCH and TGARCH Model in Value-at-Risk estimation

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Aleksej
Posts: 5
Joined: Sun Jan 10, 2016 11:25 am

Use of GARCH and TGARCH Model in Value-at-Risk estimation

Postby Aleksej » Thu Jan 14, 2016 6:07 am

Hello everybody,
I need to do a rolling estimation of a GARCH(1,1) and TGARCH(1,1,1), outputting 1-day ahead forecast for the conditional variance and then calculate 1-day ahead forecast for the Value at Risk.
I have 1254 observations a need a rolling window of 500. Therefor the first estimated GARCH should be based on observation 1 through 500, outputting a forecasted conditional variance for observation 501. Hereafter a new estimation based on 2 through 501, forecasting a conditional variance for observation 503 etc etc.
For the Value at Risk without GARCH/TGARCH Model I use the following code:

Code: Select all

smpl 06/12/2007 26/11/2010 matrix Portfoliowert_oos=@convert(PORTFOLIO) smpl 06/12/2007 25/11/2010 matrix Portfoliowert_oos_1=@convert(PORTFOLIO) smpl 07/12/2007 26/11/2010 matrix Portfoliowert_oos_2=@convert(PORTFOLIO) matrix verlust=-1*(Portfoliowert_oos_2-Portfoliowert_oos_1) !window=500 !length=@obsrange matrix(!length-!window+1,1) movstd for !i=1 to !length-!window smpl @first+!i-1 @first+!i+!window-2 movstd(!i,1)=@stdev(portfolio_rendite) vector(!i) t t=@qnorm(0.01) vector(!i) s s=1 matrix(!length-!window,1) v_a_r v_a_r(!i,1)=Portfoliowert_oos(!i,1)*(s(!i)-exp(movstd(!i,1)*t(!i))) matrix(!length-!window,2) hh hh(!i,1)=v_a_r(!i,1) hh(!i,2)=verlust(!i,1) next
My first question is: how to make a matrix which includet only positiv parameter from matrix "verlust" (Matrix "verlust" included real losses over the period. Negative parameters in Matrix "verlust" mean that the value of the portfolio has increased the next day. This paramenter are not required for the later comparison.)

In the next step I want make just the same, but now I want to use the condition variance estimated with GARCH and later with TGARCH model.
For the estimation conditional variance GARCH(1,1) Model, I wrote following code, but it doesn't work

Code: Select all

!window=500 !length=@obsrange for !i=1 to !length-!window+1 smpl @first+!i-1 @first+!i+!window-2 equation arch!i.arch(1,1) portfolio_rendite arch!i.makegarch garchvar next
Can someone help me please.
Attachments
portfolio_2006_2010_1_first.WF1
(49.78 KiB) Downloaded 237 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby EViews Gareth » Thu Jan 14, 2016 8:55 am

For your first question, do you want to shrink the resulting matrix so that it only contains the positive values, or do you want to have it the same size and NA out any value that is negative?

For the second question, how doesn't it work?

Aleksej
Posts: 5
Joined: Sun Jan 10, 2016 11:25 am

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby Aleksej » Thu Jan 14, 2016 9:39 am

Hello Gareth.
first question: I want to have the same size, but instead of negative value should be 0 or NA. Because I want to put the resalt in to "hh" matrix, where the first column is the Value at Risk and the second column is the real losses.

second question: When I run the code 2, I get the first resalt of estimation only in 9/12/2008, but I have a rolling window of 500, so the first forecasted conditional variance var(t+1), which must be estimated using the data from 03/01/2006 until 07/12/2007 (500 observations), must be in 10/12/2007 (besause it was weekend between 07/12/2007 and 10/12/2007). Therefore I am not sure, makes EViews what I want or something different.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby EViews Gareth » Thu Jan 14, 2016 10:03 am

Code: Select all

matrix y = @emult(@egt(x,@zeros(@rows(x),@columns(x))),x)
Where X is the matrix containing the negative/positive numbers.


For the second part, try running your code just once (i.e. set the for loop from !i=1 to 1) and see if it does what you want for the first run through. The check if it does what you want the 2nd time through, etc..

Aleksej
Posts: 5
Joined: Sun Jan 10, 2016 11:25 am

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby Aleksej » Thu Jan 14, 2016 2:13 pm

Thank you very much Gareth, the code what you written is what I´m looking for!
For the second problem: I took different periods for looking what the EViews do by estimation of conditional variance. For example I took only first 500 observations (from 03/01/2006 until 07/12/2007) and calculate the conditional variance and also I wrote down the formula with parameter c(1), c(2) and c(3), then I took another period (from 04/01/2006 until 10/12/2007) also 500 observations and wrote down the same things etc etc.
Then I took my code and run this. I get 755 calculations. I look same of calculations and compare it with the data which I wrote. All calculations are correct. The problem ist that EViews overwrites the results of previous calculations in matrix "garchvar". What I want is to put the last resalt from estimation number one (arch1) to the matrix "garchvar" in the row 06/12/2007, and the last resalt from estimation number two (arch2) to the matrix "garchvar" in the row 07/12/2007 but without overwriting the row 06/12/2007. But I have no idea how to do that.
If I take loop !i=1 to 1, then I get resalts from 02/01/2006 until 06/12/2007
If I take loop !i=1 to 2, then I get resalts from 03/01/2006 until 07/12/2007, the value in row 07/12/2007 is forecast conditional variance for 07/12/2007 (this how I understand this), or is it just conditional variance which was estimated from my observation and I should make the forecast using:
convar(10/12/2007)=c(1)+c(2)*resid(07/12/2007)+c(3)*convar(07/12/2007) (remember, 07/12/2007 to 10/12/2007 ist just one step, because weekend).
But how can I do this?
Attachments
conditional varianz.jpg
conditional varianz.jpg (109.22 KiB) Viewed 7212 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby EViews Gareth » Thu Jan 14, 2016 2:16 pm

Create a new series to hold the results.
Each time through the loop set the sample to the single observation you want to save, then set your new series equal to garchvar.

Aleksej
Posts: 5
Joined: Sun Jan 10, 2016 11:25 am

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby Aleksej » Thu Jan 14, 2016 2:30 pm

Gareth thank you for your quick answers, but I'm new in EViews. Accordingly, I have absolutely no idea how to do that. Can you help me or where can I look up how to do that?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby EViews Gareth » Thu Jan 14, 2016 4:11 pm

Use:

Code: Select all

series myseries
before your loop, then after you have generated garchvar, set the sample to be the observation you want, and do:

Code: Select all

myseries = garchvar

Aleksej
Posts: 5
Joined: Sun Jan 10, 2016 11:25 am

Re: Use of GARCH and TGARCH Model in Value-at-Risk estimatio

Postby Aleksej » Thu Jan 14, 2016 7:08 pm

Gareth, thank you for your help.
I change my code, but it still don´t work.
For example I try it with this code:

Code: Select all

!window=500 !length=@obsrange series value !x1=c(1) !x2=c(2) !x3=c(3) for !k=1 to !length-!window+1 smpl @first+!k-1 @first+!k+!window-2 equation arch!k.arch(1,1) portfolio_rendite arch!k.makegarch garch!kvar series rendite!ksq=portfolio_rendite^2 series fore!kvar=!x1+!x2*rendite!ksq(!k)+!x3*garch!kvar(!k) value=fore!kvar next
It doesn´t work. Eviews put the right estimation for forecaste variance in series "fore!kvar", but only in the row 6/12/2007 and this for all the "fore!kvar", so the "fore499var" ist the last wich have the value in row 6/12/2007, all another "fore!kvar" have just only NA.
You wrote "then after you have generated garchvar, set the sample to be the observation you want, and do..." I try to put different parameter, but it also doesn't worked.

Then I try this code:

Code: Select all

!window=500 !length=@obsrange !x1=c(1) !x2=c(2) !x3=c(3) for !k=1 to !length-!window+1 smpl @first+!k-1 @first+!k+!window-2 equation arch!k.arch(1,1) portfolio_rendite arch!k.makegarch garch!kvar series rendite!ksq=portfolio_rendite^2 matrix(!length-!window+1,1) ht_norm_for ht_norm_for(!k, 1)=!x1+!x2*rendite!ksq(!k)+!x3*garch!kvar(!k) next
But the value in matrix "ht_norm_for" is rong. Vor exaple the first value is 6,95e-05, but it should be about 0,000195.
Where I make a mistake?
Is it possible to look how Eviews estimate the value in matrix "ht_norm_for"?
Attachments
portfolio_2006_2010_2.wf1
(39.47 KiB) Downloaded 226 times


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests