aboutsummaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/tranche_functions.R55
1 files changed, 40 insertions, 15 deletions
diff --git a/R/tranche_functions.R b/R/tranche_functions.R
index c212a891..66afac89 100644
--- a/R/tranche_functions.R
+++ b/R/tranche_functions.R
@@ -11,6 +11,7 @@ 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=T)
lossdistrib <- function(p){
## basic recursive algorithm of Andersen, Sidenius and Basu
@@ -235,7 +236,8 @@ lossdist.prepay.joint <- function(dp, pp, w, S, N, defaultflag=FALSE){
lossdistC <- function(p, w, S, N, defaultflag=FALSE){
## C version of lossdistrib2, roughly 50 times faster
if(!is.loaded("lossdistrib")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname, .Platform$dynlib.ext)))
}
.C("lossdistrib", as.double(p), as.integer(length(p)),
as.double(w), as.double(S), as.integer(N), as.logical(defaultflag), q = double(N))$q
@@ -244,7 +246,8 @@ lossdistC <- function(p, w, S, N, defaultflag=FALSE){
lossdistCblas <- function(p, w, S, N, defaultflag=FALSE){
## C version of lossdistrib2, roughly 50 times faster
if(!is.loaded("lossdistrib_blas")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname, .Platform$dynlib.ext)))
}
.C("lossdistrib_blas", as.double(p), as.integer(length(p)),
as.double(w), as.double(S), as.integer(N), as.logical(defaultflag), q = double(N))$q
@@ -252,7 +255,8 @@ lossdistCblas <- function(p, w, S, N, defaultflag=FALSE){
lossdistCZ <- function(p, w, S, N, defaultflag=FALSE, rho, Z, wZ){
if(!is.loaded("lossdistrib_Z")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname, .Platform$dynlib.ext)))
}
.C("lossdistrib_Z", as.double(p), as.integer(length(p)),
as.double(w), as.double(S), as.integer(N), as.logical(defaultflag),
@@ -263,9 +267,10 @@ lossdistCZ <- function(p, w, S, N, defaultflag=FALSE, rho, Z, wZ){
lossdistC.truncated <- function(p, w, S, N, T=N){
## C version of lossdistrib2, roughly 50 times faster
if(!is.loaded("lossdistrib_truncated")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
.C("lossdistrib_truncated", as.double(p), as.integer(length(p)),
as.double(w), as.double(S), as.integer(N), as.integer(T), q = double(T))$q
}
@@ -273,7 +278,9 @@ lossdistC.truncated <- function(p, w, S, N, T=N){
recovdistC <- function(dp, pp, w, S, N){
## C version of recovdist
if(!is.loaded("recovdist")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
.C("recovdist", as.double(dp), as.double(pp), as.integer(length(dp)),
as.double(w), as.double(S), as.integer(N), q = double(N))$q
@@ -282,7 +289,9 @@ recovdistC <- function(dp, pp, w, S, N){
lossdistC.joint <- function(p, w, S, N, defaultflag=FALSE){
## C version of lossdistrib.joint, roughly 20 times faster
if(!is.loaded("lossdistrib_joint")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
.C("lossdistrib_joint", as.double(p), as.integer(length(p)), as.double(w),
as.double(S), as.integer(N), as.logical(defaultflag), q = matrix(0, N, N))$q
@@ -291,7 +300,9 @@ lossdistC.joint <- function(p, w, S, N, defaultflag=FALSE){
lossdistC.jointblas <- function(p, w, S, N, defaultflag=FALSE){
## C version of lossdistrib.joint, roughly 20 times faster
if(!is.loaded("lossdistrib_joint_blas")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
.C("lossdistrib_joint_blas", as.double(p), as.integer(length(p)), as.double(w),
as.double(S), as.integer(N), as.logical(defaultflag), q = matrix(0, N, N))$q
@@ -307,7 +318,9 @@ lossdistC.jointZ <- function(dp, w, S, N, defaultflag = FALSE, rho, Z, wZ){
## Z is a vector of length nZ
## w is a vector if length wZ
if(!is.loaded("lossdistrib_joint_Z")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
r <- .C("lossdistrib_joint_Z", as.double(dp), as.integer(length(dp)),
as.double(w), as.double(S), as.integer(N), as.logical(defaultflag), as.double(rho),
@@ -317,7 +330,9 @@ lossdistC.jointZ <- function(dp, w, S, N, defaultflag = FALSE, rho, Z, wZ){
lossdistC.prepay.joint <- function(dp, pp, w, S, N, defaultflag=FALSE){
## C version of lossdist.prepay.joint
if(!is.loaded("lossdistrib_prepay_joint")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
r <- .C("lossdistrib_prepay_joint", as.double(dp), as.double(pp), as.integer(length(dp)),
as.double(w), as.double(S), as.integer(N), as.logical(defaultflag), q=matrix(0, N, N))$q
@@ -334,7 +349,9 @@ lossdistC.prepay.jointZ <- function(dp, pp, w, S, N, defaultflag = FALSE, rho, Z
## Z is a vector of length nZ
## w is a vector if length wZ
if(!is.loaded("lossdistrib_prepay_joint_Z")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
r <- .C("lossdistrib_prepay_joint_Z", as.double(dp), as.double(pp), as.integer(length(dp)),
as.double(w), as.double(S), as.integer(N), as.logical(defaultflag), as.double(rho),
@@ -473,7 +490,9 @@ fit.prob <- function(Z, w, rho, p0){
fit.probC <- function(Z, w, rho, p0){
if(!is.loaded("fitprob")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
r <- .C("fitprob", as.double(Z), as.double(w), as.integer(length(Z)),
as.double(rho), as.double(p0), q = double(1))
@@ -493,7 +512,9 @@ stochasticrecov <- function(R, Rtilde, Z, w, rho, porig, pmod){
stochasticrecovC <- function(R, Rtilde, Z, w, rho, porig, pmod){
if(!is.loaded("stochasticrecov")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
r <- .C("stochasticrecov", as.double(R), as.double(Rtilde), as.double(Z),
as.double(w), as.integer(length(Z)), as.double(rho), as.double(porig),
@@ -653,7 +674,9 @@ BClossdist <- function(defaultprob, issuerweights, recov, rho, N=length(recov)+1
BClossdistC <- function(defaultprob, issuerweights, recov, rho, Z, w,
N=length(issuerweights)+1, defaultflag=FALSE){
if(!is.loaded("BClossdist")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
L <- matrix(0, N, dim(defaultprob)[2])
R <- matrix(0, N, dim(defaultprob)[2])
@@ -752,7 +775,9 @@ MFupdate.probC <- function(Z, w, rho, defaultprob){
## distribution so that the pv of the cds stays the same.
p <- matrix(0, nrow(defaultprob), ncol(defaultprob))
if(!is.loaded("fitprob")){
- dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib", .Platform$dynlib.ext)))
+ dyn.load(file.path(root.dir, "code", "R", paste0("lossdistrib",
+ hostname,
+ .Platform$dynlib.ext)))
}
for(i in 1:nrow(defaultprob)){
for(j in 1:ncol(defaultprob)){