summaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2017-04-27 12:39:24 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2017-04-27 13:10:26 -0400
commit25a3a7a3a6d22e0c5eb46ac920c666cda5fcbdc5 (patch)
tree349c749c167b1fe296a5003643dc002e17a4d358 /R
parent196f5f731611336721208eff52e980a404c0a701 (diff)
downloadlossdistrib-25a3a7a3a6d22e0c5eb46ac920c666cda5fcbdc5.tar.gz
register routines
Diffstat (limited to 'R')
-rw-r--r--R/distrib.R44
1 files changed, 22 insertions, 22 deletions
diff --git a/R/distrib.R b/R/distrib.R
index 26b62cc..f8d1c00 100644
--- a/R/distrib.R
+++ b/R/distrib.R
@@ -26,7 +26,7 @@ GHquad <- function(n){
n <- as.integer(n)
Z <- double(n)
w <- double(n)
- result <- .C("GHquad", n, Z=Z, w=w)
+ result <- .C("C_GHquad", n, Z=Z, w=w)
result[[1]] <- NULL
return(result)
}
@@ -316,34 +316,34 @@ 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
- .C("lossdistrib", as.double(p), as.integer(length(p)),
- as.double(w), as.double(S), as.integer(N), as.integer(N), as.logical(defaultflag), q = double(N))$q
+ .C("C_lossdistrib", as.double(p), as.integer(length(p)),
+ as.double(w), as.double(S), as.integer(N), as.integer(N),
+ as.logical(defaultflag), q = double(N))$q
}
lossdistCZ <- function(p, w, S, N, defaultflag=FALSE, rho, Z){
##S is of size (length(p), length(Z))
- stopifnot(length(rho)==length(p),
- length(rho)==length(w),
- nrow(S)==length(p),
- ncol(S)==length(Z))
- .C("lossdistrib_Z", as.double(p), as.integer(length(p)),
- as.double(w), as.double(S), as.integer(N), as.logical(defaultflag),
- as.double(rho), as.double(Z), as.integer(length(Z)),
- q = matrix(0, N, length(Z)))$q
+ stopifnot(length(rho) == length(p),
+ length(rho) == length(w),
+ nrow(S) == length(p),
+ ncol(S) == length(Z))
+ .C("C_lossdistrib_Z", as.double(p), as.integer(length(p)), as.double(w),
+ as.double(S), as.integer(N), as.logical(defaultflag), as.double(rho),
+ as.double(Z), as.integer(length(Z)), q = matrix(0, N, length(Z)))$q
}
lossdistC.truncated <- function(p, w, S, N, T=N, defaultflag=FALSE){
## truncated version of lossdistrib
## q[i] is 0 for i>=T
- .C("lossdistrib_truncated", as.double(p), as.integer(length(p)),
- as.double(w), as.double(S), as.integer(N), as.integer(T), as.logical(defaultflag),
- q = double(N))$q
+ .C("C_lossdistrib", as.double(p), as.integer(length(p)),
+ as.double(w), as.double(S), as.integer(N), as.integer(T),
+ as.logical(defaultflag), q = double(N))$q
}
exp.trunc <- function(p, w, S, N, K){
## computes E[(K-L)^+]
r <- 0
- .C("exp_trunc", as.double(p), as.integer(length(p)),
+ .C("C_exp_trunc", as.double(p), as.integer(length(p)),
as.double(w), as.double(S), as.integer(N), as.double(K), res = r)$res
}
@@ -360,13 +360,13 @@ rec.trunc <- function(p, w, S, N, K){
recovdistC <- function(dp, pp, w, S, N){
## C version of recovdist
- .C("recovdist", as.double(dp), as.double(pp), as.integer(length(dp)),
+ .C("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
}
lossdistC.prepay.joint <- function(dp, pp, w, S, N, defaultflag=FALSE){
## C version of lossdist.prepay.joint
- r <- .C("lossdistrib_joint", as.double(dp), as.double(pp), as.integer(length(dp)),
+ r <- .C("C_lossdistrib_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
return(r)
}
@@ -381,7 +381,7 @@ 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
- r <- .C("lossdistrib_joint_Z", as.double(dp), as.double(pp), as.integer(length(dp)),
+ r <- .C("C_lossdistrib_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),
as.double(Z), as.double(wZ), as.integer(length(Z)), output = matrix(0,N,N))
return(r$output)
@@ -521,7 +521,7 @@ fit.prob <- function(Z, w, rho, p0){
fit.probC <- function(Z, w, rho, p0){
stopifnot(length(Z)==length(w))
- r <- .C("fitprob", as.double(Z), as.double(w), as.integer(length(Z)),
+ r <- .C("C_fitprob", as.double(Z), as.double(w), as.integer(length(Z)),
as.double(rho), as.double(p0), q = double(1))
return(r$q)
}
@@ -538,7 +538,7 @@ stochasticrecov <- function(R, Rtilde, Z, w, rho, porig, pmod){
}
stochasticrecovC <- function(R, Rtilde, Z, w, rho, porig, pmod){
- r <- .C("stochasticrecov", as.double(R), as.double(Rtilde), as.double(Z),
+ r <- .C("C_stochasticrecov", as.double(R), as.double(Rtilde), as.double(Z),
as.double(w), as.integer(length(Z)), as.double(rho), as.double(porig),
as.double(pmod), q = double(length(Z)))
return(r$q)
@@ -586,7 +586,7 @@ BClossdistC <- function(defaultprob, issuerweights, recov, rho, Z, w,
L <- matrix(0, N, ncol(defaultprob))
R <- matrix(0, N, ncol(defaultprob))
rho <- rep(rho, length(issuerweights))
- r <- .C("BCloss_recov_dist", defaultprob, as.integer(nrow(defaultprob)),
+ r <- .C("C_BCloss_recov_dist", defaultprob, as.integer(nrow(defaultprob)),
as.integer(ncol(defaultprob)), as.double(issuerweights),
as.double(recov), as.double(Z), as.double(w), as.integer(length(Z)),
as.double(rho), as.integer(N), as.logical(defaultflag), L=L, R=R)
@@ -601,7 +601,7 @@ BCER <- function(defaultprob, issuerweights, recov, K, rho, Z, w,
rho <- rep(rho, length(issuerweights))
ELt <- numeric(ncol(defaultprob))
ERt <- numeric(ncol(defaultprob))
- r <- .C("BCloss_recov_trunc", defaultprob, as.integer(nrow(defaultprob)),
+ r <- .C("C_BCloss_recov_trunc", defaultprob, as.integer(nrow(defaultprob)),
as.integer(ncol(defaultprob)),
as.double(issuerweights), as.double(recov), as.double(Z), as.double(w),
as.integer(length(Z)), as.double(rho), as.integer(N), as.double(K),