*VaR and Expected Shortfall: Shazam program to compute VaR and ES based on Extreme Value Theory. *VaR stand for Value-at-Risk and ES stand for Expected Shortfall. *Reference: Onour I.(2010): J. of Money, Investment, and Banking, issue 13,pp.27-34. *Assume the sample size =1000 sample 1 1000 read x genr x1=log(x) genr x2=x1-lag(x1) sample 2 $N gen1 n1=$N *adverse shocks represented by negative returns if(x2.LT.0)x3=x2 *To accommodate GPD density function take the absolute values of the loss values. genr xa=abs(x3) *to determine threshold value of xa: stat xa/mean=u if(xa.GT.u)x4=xa skipif(x4.LT.u) skipif(x4.EQ.u) sample 2 $N gen1 n2=$N *estimate GPD parameters based on extreme values NL 1/ncoef=2 logdens piter=100 genrvar eq 1-(1+beta1*x4/beta2)**(-1/beta1) coef beta1 0.64 beta2 0.167 end *compute static VaR values: *set threshold gen1 v=u-(beta2/beta1)+(beta2/beta1)*((n1/n2)*(0.05))**(-beta1) *compute Expected Shortfall: gen1 es=(v/(1-beta1))+(beta2-beta1*u)/(1-beta1) sample 5 n2 *Back testing:percentage of actual losses exceeding estimated VaR if(x4.GT.v)x5=1 gen1 x6=sum(x5,n2) sample 5 n1 if(xa.GT.0)x7=1 skipif(xa.EQ.0) gen1 x8=sum(x7,n1) gen1 xb=x6/x8 print v es xb stop