# # funcs.R - A set of R functions for studying aggregation of # correlated risk porfolios # #Copyright (C) 2005 Fernando Henrique F. P. Rosa # # #This program is free software; you can redistribute it and/or #modify it under the terms of version 2 of the GNU General Public License #as published by the Free Software Foundation. A copy of this license should #be included in the file COPYING. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # disc.metodo.round <- structure(c(0.000473987103245853, 0.0416050327111922, 0.164080831467209, 0.237857591737151, 0.217607182758463, 0.153672065363593, 0.0920072871791147, 0.0491406283685871, 0.0241391989622163, 0.0111238468505793, 0.00487424011845172, 0.00205053290516322, 0.000834116178070943, 0.000329863091219518, 0.000127353872015123, 4.81622719928909e-05, 1.78888558766133e-05, 6.5401976485635e-06, 2.35787098945561e-06, 8.39517884765328e-07, 2.95582440745790e-07), .Names = c("0", "500", "1000", "1500", "2000", "2500", "3000", "3500", "4000", "4500", "5000", "5500", "6000", "6500", "7000", "7500", "8000", "8500", "9000", "9500", "10000")) gamma.discretizada <- function(x,f) { vals <- as.numeric(names(f)) resposta <- numeric(length(x)) for (i in seq(along=x)) { resposta[i] <- sum(f[vals <= x[i]]) } resposta } metodo.match <- function() { j <- 1:20 h <- 500 resposta <- numeric(length(j)+1) resposta[1] <- 1 - integrate(pgamma,0,h,lower.tail=FALSE,shape=5,rate=1/400)$value/h for (i in 2:length(j)) { resposta[i] <- (2*integrate(pgamma,0,h*j[i-1],lower.tail=FALSE,shape=5,rate=1/400)$value - integrate(pgamma,0,h*(j[i-1]-1),lower.tail=FALSE,shape=5,rate=1/400)$value - integrate(pgamma,0,h*(j[i-1]+1),lower.tail=FALSE,shape=5,rate=1/400)$value)/h } names(resposta) <- c(0,j*h) resposta }