/*############################################################################## # # # VaR by Breno de Andrade Pinheiro Néri # # # # brenoneri@gmail.com www.fgv.br/aluno/bneri # # # # August, 2005 - Version 7 # # # ################################################################################ # # # This code estimates 1-day-ahead-forecast VaR time series using three # # methodologies, namely: # # 1- RiskMetrics model developed by J.P. Morgan, 1996; # # 2- GARCH(1, 1) with Gaussian errors; # # 3- APARCH(1, 1) with Skewed Student-t errors. # # # # You enter a time series vector (vY) in a file called vY.mat, with the # # observations in one single column, and the code saves a matrix in a file # # called mVaR.mat, with the 3 VaR methodologies in the columns and the 1-day # # VaR forecast in the rows. # # # # Note that each forecasts are estimated based on the last 'cWin' observations.# # Hence, if rows(vY) < cWin, you will have an error. If you do not have enough # # observations, set up a lower temporal window size (cWin). # # Note also that rows(mVaR) = rows(vY) - cWin + 1. # # # # Due to the two constrained nonlinear optimization for each observation, this # # code is extremely computational intensive! # # # # Defaults: tau=.01 and cWin=250, due to regulatory obligation (1996 Amendment # # to Basle Capital Accord). # # # ################################################################################ # # # You may use this code only if you accept the conditions: # # (1) I am not liable for any problem caused by this code (i.e. you use it at # # your own risk); # # (2) You must give me credit in your papers where this code has been used. # # # ##############################################################################*/ #import static decl s_vE, s_obj; // GARCH11 garch(const vP) { decl vSigma2=s_vE[0]^2, i; for(i=0; i, vPg=init[:2], vPst=init, dPg, dPst; if(cT