Histogram <- function(met=1, DGP=1, mets=7, res=2, replic=1000, classes=40) { ################################################################################ # # # Histogram Function by Breno de Andrade Pinheiro Néri # # # # brenoneri@gmail.com www.fgv.br/aluno/bneri # # # # October, 2005 - Version 1 # # # ################################################################################ # # # This code plots histograms to help you to analyze the results of the Monte # # Carlo Simulations generated by MC_VaR.R or MC_VaRox.R. # # # # You enter the VaR methodology (met), the DGP (DGP), the number of # # methodologies generated in your Monte Carlo Simulations (mets), the desired # # test statistics (res), the number # # of replications generated in your MC Simulations (replic) and the number of # # subdivisions that you want in your histogram (classes). # # # # 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: met=1, DGP=1, mets=7, res=2, replic=1000, classes=40. # # # ################################################################################ # # # 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. # # # ################################################################################ x <- array(0, c(replic, mets)) for(i in 1:replic) { load(paste("MC_VaR", DGP, i, "R", sep=".")) x[i,] <- result[[res]] } hist(x[,met], classes, main=paste("Histogram for the VaR methodology", met, "under DGP", DGP, sep=" "), xlab="Test Statistics") }