Bias.MSE <- function(DGP=1:15, mets=7, res=2, p=10, replic=1000) { ################################################################################ # # # Bias.MSE Function by Breno de Andrade Pinheiro Néri # # # # brenoneri@gmail.com www.fgv.br/aluno/bneri # # # # October, 2005 - Version 1 # # # ################################################################################ # # # This code computes the Bias and the Mean Squared Error as in Robert Engle # # and Simone Manganelli, August 2001. Value-at-Risk Models in Finance. # # European Central Bank, Working Paper Series, Working Paper 75. Formulas 26 # # and 27, respectively. # # # # You enter the DGP range (DGP, observe that it is a vector), the number of # # methodologies generated in your Monte Carlo Simulations (mets), the desired # # test statistics (res), the true value of the parameter (p) and the number # # of replications generated in your MC Simulations (replic). # # # # You can choose among eleven test statistics generated by the code # # BackTest.R, setting up the res variable. Namely: # # 1: frequency of violations; # # 2: number of violations (default); # # 3: ---Not Available---; # # 4: Unconditional Coverage (Kupiec, 1995) Likelihood Ratio Test; # # 5: Independence (Christoffersen, 1997) Likelihood Ratio Test; # # 6: Conditional Coverage (Christoffersen, 1997) Likelihood Ratio Test; # # 7: Dynamic Quantile (Engle and Manganelli, 2002) Test Statistic; # # 8: Unconditional Coverage (Kupiec, 1995) P-Value; # # 9: Independence (Christoffersen, 1997) P-Value; # # 10: Conditional Coverage (Christoffersen, 1997) P-Value; # # 11: Dynamic Quantile (Engle and Manganelli, 2002) P-Value; # # 12: Magnitude Loss Function (Lopez, 1998). # # # # Defaults: DGP=1:15, mets=7, res=2, p=10, replic=1000. # # # ################################################################################ # # # 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. # # # ################################################################################ for(j in DGP) { x <- array(0, c(replic, mets)) for(i in 1:replic) { load(paste("MC_VaR", j, i, "R", sep=".")) x[i,] <- result[[res]]-p } for(met in 1:mets) { message("") message("VaR methodology ", met, " under DGP ", j, ":") message("Bias: ", mean(x[,met])) message("MSE: ", mean(x[,met]^2)) } message("") } }