diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2014-05-07 10:50:13 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2014-05-07 10:50:13 -0400 |
| commit | 6eac91bf7bcf3515e661d74b49e8179938bd1488 (patch) | |
| tree | 76a7ff22c3d6f5be749c2efd9fb01138447c384b /R | |
| parent | 216fe79edf63926a28a4a435b78ebf03fc96b1d1 (diff) | |
| download | lossdistrib-6eac91bf7bcf3515e661d74b49e8179938bd1488.tar.gz | |
add GHquad function, get rid of statmod dependency
Diffstat (limited to 'R')
| -rw-r--r-- | R/tranche_functions.R | 30 |
1 files changed, 11 insertions, 19 deletions
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)
|
