VaR <- function(y, tau=.01, win=250) { ################################################################################ # # # VaR Function by Breno de Andrade Pinheiro Néri # # # # brenoneri@gmail.com www.fgv.br/aluno/bneri # # # # September, 2005 - Version 13 # # # ################################################################################ # # # This code is a Monte Carlo simulation to compare seven different # # methodologies for estimating 1-day-ahead-forecast VaR time series, namely: # # 1- RiskMetrics model developed by J.P. Morgan, 1996; # # 2- GARCH(1, 1) with normal errors; # # 3- APARCH(1, 1) with skewed-t errors; # # 4- ARCH(1) Quantile VaR, developed by Wu and Xiao, 2002; # # 5- ARCH(0) Quantile VaR; # # 6- QAR(1)-VaR (Quantile AutoRegressive VaR), introduced by me and my thesis # # advisor, Luiz Renato Lima (see Lima and Neri, 2005); # # 7- QAR(0)-VaR. # # # # You enter a time series (y), a quantile (tau) and a temporal window size # # (win) and the code returns a matrix VaR series, one column for each # # methodology. # # # # Note that each forecasts are estimated based on the last 'win' observations. # # Hence, if length(y) < win, you will have an error. If you do not have enough # # observations, set up a lower temporal window size (win). # # Note also that length(VaR) = length(y) - win + 1. # # # # Due to the two constrained nonlinear optimization for each observation, this # # code is extremely computational intensive! # # # # Defaults: tau=.01 and win=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. # # # ################################################################################ # Initializing t <- length(y) if(t