Page 1 of 1

Calculating Value-at-Risk

Posted: Wed Jan 22, 2014 10:57 am
by aroon
Greetings
My name’s Arun, I’m from Thailand. I’m in my senior year studying Economics at Chulalongkorn University

Now I’m doing my dissertation about comparing the effectiveness of calculating Value-at-Risk between varied methods (models). One of them is a semi-parametric method (called “Filtered Historical Simulation (FHS)”) which is the combination of parametric method from GARCH-type models (I use GJR-GRACH this time) and non-parametric method from simulations.

I have to write code in E-views programming which I have gathered from many sources. Then, I used the FHS method with rolling estimate and also calculated a 1-day Value-at-Risk (using @quantile command) with 99% confidence interval in every window (250 days in each window). Then, I received error messages.
“ -47 is not a valid index for vector-series-coefficient TGARCH1ERR in “RT_BOOT_FOR(1,1)= TGARCH1ERR(U(1,1))*@SQRT(HT_BOOT_FOR(1,1))”. “

Another Error message is ...
“(3,1) is not valid index for matrix HT_NORM_FOR in “HT_NORM_FOR(2+1,1=3.510…E-06+0.02177…*RT_BOOT_FOR(2,1)^2+0.97706…*HT_BOOT_FOR(2,1) -0.0374…*RT_BOOT_FOR(2,1)*(RT_BOOT_FOR(2,1) - @ABS(RT_BOOT_FOR(2,1)))/2”. ”

Every time I run the program, these error messages appear and the number (-47) changes to other negative integral numbers as then same problem as the number in parenthesis.

Here is my code. It would be very grateful for any help.

Code: Select all

!window = 250 'set window workfile !length = @obsrange ' get size of workfile series value2 ' declare series to store results scalar nperiods=1 scalar nsim=5000 scalar T =250 ' compute stats for each window for !k = 1 to !length-!window+1 smpl @first+!k-1 @first+!k+!window-2 equation tgarch!k.arch(1,1,thrsh=1) ds50 'save the conditional GARCH variance tgarch!k.makegarch tgarch!kvar 'compute th corresponding vol series tgarch!kvol=@sqrt(tgarch!kvar) 'compute the standardize residuals series tgarch!kerr=ds50/tgarch!kvol !x1=c(1) !x2=c(2) !x3=c(3) !x4=c(4) matrix u=@round((T-1)*@mnrnd(nperiods, nsim))+1 matrix(nperiods+1, nsim) ht_boot_for=tgarch!kvar(T) matrix(nperiods, nsim) rt_boot_for vector(nsim) ret_cum_boot=0 for !j=1 to nsim for !i=1 to nperiods rt_boot_for(!i, !j)=tgarch!kerr(u(!i, !j))*@sqrt(ht_boot_for(!i, !j)) ht_norm_for(!i+1, !j)=!x1+!x2*rt_boot_for(!i, !j)^2+!x4*ht_boot_for(!i, !j)+!x3*rt_boot_for(!i, !j)*(rt_boot_for(!i, !j)-@abs(rt_boot_for(!i, !j)))/2 ret_cum_boot(!j)=ret_cum_boot(!j)+rt_boot_for(!i, !j) next next !var2 = @quantile(ret_cum_boot,0.01) ' reset to one observation sample smpl @first+!k-1 @first+!k-1 ' and assign to series value2 = !var2 next smpl @all

Re: Calculating Value-at-Risk

Posted: Wed Jan 22, 2014 11:10 am
by EViews Gareth
I'm not sure what you're trying to do with the line:

Code: Select all

RT_BOOT_FOR(1,1)= TGARCH1ERR(U(1,1))
But the problem is that you're referencing the U(1,1)th element of the matrix TGARCH1ERR. It looks as though you're generating U from a multivariate normal random number generator, so it can, of course, be a negative number. You can't have a negative element of a matrix.

Re: Calculating Value-at-Risk

Posted: Fri Jan 24, 2014 1:09 am
by aroon
Thanks, Gareth

Now, I have known that what it wrong is the command “@mrnd” which is normal distribution and I have to change to “@mrnd” which is uniform random number, so all number in matrix would be positive.

And I’m sorry that I made mistake for the first code. The matrix “ht_norm_for” will now defined. Actually the "code below" was comes first and these 2 codes (on my first post and this time) are almost the same unless my first time posted use the bootstrapped error. And all of these codes (except the rolling window process) I’m copy from this link. http://faculty.chicagobooth.edu/jeffrey ... eview7.pdf

Code: Select all

[code] !window = 250 'set window workfile !length = @obsrange ' get size of workfile series value ' declare series to store results scalar nperiods=1 scalar nsim=5000 scalar T =250 !x1=c(1) !x2=c(2) !x3=c(3) !x4=c(4) ' compute stats for each window for !k = 1 to !length-!window+1 smpl @first+!k-1 @first+!k+!window-2 equation tgarch!k.arch(1,1,thrsh=1) ds50 tgarch!k.makegarch tgarch!kvar 'save the conditional GARCH variance series tgarch!kvol=@sqrt(tgarch!kvar) 'compute th corresponding vol series tgarch!kerr=ds50/tgarch!kvol 'compute the standardize residuals 'graph errhist.displot tgarch11err matrix (nperiods+1, nsim) ht_norm_for=tgarch!kvar(T) matrix (nperiods, nsim) rt_norm_for matrix eps=@mnrnd(nperiods, nsim) vector (nsim) ret_cum_norm=0 for !j=1 to nsim for !i=1 to nperiods rt_norm_for(!i, !j)=eps(!i, !j)*((ht_norm_for(!i, !j)))^0.5 ht_norm_for(!i+1, !j)=!x1+!x2*rt_norm_for(!i, !j)^2+!x4*ht_norm_for(!i, !j)+!x3*rt_norm_for(!i, !j)*(rt_norm_for(!i, !j)-@abs(rt_norm_for(!i, !j)))/2 ret_cum_norm(!j)=ret_cum_norm(!j)+rt_norm_for(!i, !j) next next !var2 = @quantile(ret_cum_norm,0.01) ' reset to one observation sample smpl @first+!k-1 @first+!k-1 ' and assign to series value = !var2 next smpl @all
[/code]

For the code in this time I also have problem that the series “value” I’ve created to store value-at-risk from each windows have its values (numbers) only the first 250 observations (from all of 4,477 observations) and the Error message was “User break in “EQUATION TGARCH!K.ARCH(1,1 THRSH=1) DS50”.”

And for the line:

Code: Select all

RT_BOOT_FOR(1,1)= TGARCH1ERR(U(1,1))

I’m still not sure what it actually means because I’m just copy from that website. What Should I do?. (By the way, sorry for my poor English and hope you will understand me.)