setwd("D:/Export/WiSe 2016/Angewandte Stochastik 2/Übungsblätter/Blatt 7/Lösung/") ################Aufgabe 1####################### ################################################ #################(a)############################ ################################################ paretoDens=function(a, b, x){ if (x < a){ return(0) } else { return(b*(a^b)/(x^(b+1))) } } paretoInv=function(a, b, y){ if (y >= 1 || y < 0){ return(NaN) } else { return(a/((1-y)^(1/b))) } } paretoSample=function(a, b, n){ return(paretoInv(a, b, runif(n))) } ML_est=function(sample){ a=min(sample) n=length(sample) b=-n/(n*log(a)-sum(log(sample))) return(c(a,b)) } #################(b)############################ ################################################ empVaR=c() ML_VaR=c() for (i in 1:10000){ S=paretoSample(1, 3, 50) empVaR=c(empVaR, quantile(S, 0.995)) ab=ML_est(S) ML_VaR=c(ML_VaR, paretoInv(ab[1], ab[2], 0.995)) } mybreaks=seq(0, max(empVaR)+2, 2) hist(empVaR, breaks=mybreaks) mybreaks=seq(0, max(ML_VaR)+2, 2) hist(ML_VaR, breaks=mybreaks) hist(empVaR-ML_VaR)