From 6eac91bf7bcf3515e661d74b49e8179938bd1488 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 7 May 2014 10:50:13 -0400 Subject: add GHquad function, get rid of statmod dependency --- R/tranche_functions.R | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'R/tranche_functions.R') diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 2e7f0f3..5fa954a 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -1,5 +1,3 @@ -library(statmod) - ## todo: ## -investigate other ways to interpolate the random severities on the grid ## I'm thinking that at eah severity that we add to the distribution, round it down @@ -11,22 +9,16 @@ library(statmod) ## recovery with 0.1-1 support, so it's not clear that there is a big gain. ## - do the correlation adjustments when computing the deltas since it seems to be ## the market standard -hostname <- system("hostname", intern=TRUE) - -checkSymbol <- function(name){ - if(!is.loaded(name)){ - if(.Platform$OS.type == "unix"){ - root.dir <- "/home/share/CorpCDOs" - dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", - hostname, - .Platform$dynlib.ext))) - }else{ - root.dir <- "//WDSENTINEL/share/CorpCDOs" - dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", - .Platform$dynlib.ext))) - } - } + +GHquad <- function(n){ + n <- as.integer(n) + Z <- double(n) + w <- double(n) + result <- .C("GHquad", n, Z=Z, w=w) + result[[1]] <- NULL + return(result) } + lossdistrib <- function(p){ ## basic recursive algorithm of Andersen, Sidenius and Basu n <- length(p) @@ -630,9 +622,9 @@ tranche.pvvec <- function(K, L, R, cs){ BClossdist <- function(defaultprob, issuerweights, recov, rho, Z, w, N=length(recov)+1, defaultflag=FALSE, n.int=500){ if(missing(Z)){ - quadrature <- gauss.quad.prob(n.int, "normal") - Z <- quadrature$nodes - w <- quadrature$weights + quadrature <- GHquad(n.int) + Z <- quadrature$Z + w <- quadrature$w } ## do not use if weights are not gaussian, results would be incorrect ## since shockseverity is invalid in that case (need to use stochasticrecov) -- cgit v1.2.3-70-g09d2