aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/lossdistrib.c13
-rw-r--r--R/tranche_functions.R12
2 files changed, 18 insertions, 7 deletions
diff --git a/R/lossdistrib.c b/R/lossdistrib.c
index c336d254..8f4f0ccf 100644
--- a/R/lossdistrib.c
+++ b/R/lossdistrib.c
@@ -392,8 +392,8 @@ void lossdistrib_prepay_joint_Z(double *dp, double *pp, int *ndp, double *w,
double *S, int *N, int *defaultflag, double *rho,
double *Z, double *wZ, int *nZ, double *q) {
int i, j;
- double* dpshocked = malloc(sizeof(double) * *ndp);
- double* ppshocked = malloc(sizeof(double) * *ndp);
+ double* dpshocked = malloc(sizeof(double) * (*ndp) * (*nZ));
+ double* ppshocked = malloc(sizeof(double) * (*ndp) * (*nZ));
int N2 = (*N) * (*N);
double* qmat = malloc(sizeof(double) * N2 * (*nZ));
@@ -401,13 +401,14 @@ void lossdistrib_prepay_joint_Z(double *dp, double *pp, int *ndp, double *w,
double beta = 0;
int one = 1;
- #pragma omp parallel for private(j)
+#pragma omp parallel for private(j)
for(i = 0; i < *nZ; i++){
for(j = 0; j < *ndp; j++){
- dpshocked[j] = shockprob(dp[j], *rho, Z[i], 0);
- ppshocked[j] = shockprob(pp[j], *rho, -Z[i], 0);
+ dpshocked[j + (*ndp) * i] = shockprob(dp[j], *rho, Z[i], 0);
+ ppshocked[j + (*ndp) * i] = shockprob(pp[j], *rho, -Z[i], 0);
}
- lossdistrib_prepay_joint(dpshocked, ppshocked, ndp, w, S + *ndp *i, N, defaultflag, qmat + N2 * i);
+ lossdistrib_prepay_joint(dpshocked + (*ndp) * i, ppshocked + (*ndp) * i, ndp, w,
+ S + (*ndp) * i, N, defaultflag, qmat + N2 * i);
}
dgemv_("n", &N2, nZ, &alpha, qmat, &N2, wZ, &one, &beta, q, &one);
diff --git a/R/tranche_functions.R b/R/tranche_functions.R
index 482d6237..4650c19b 100644
--- a/R/tranche_functions.R
+++ b/R/tranche_functions.R
@@ -280,6 +280,14 @@ lossdistC.prepay.joint <- function(dp, pp, w, S, N, defaultflag=FALSE){
}
lossdistC.prepay.jointZ <- function(dp, pp, w, S, N, defaultflag = FALSE, rho, Z, wZ){
+ ## N is the size of the grid
+ ## dp is of size n.credits
+ ## pp is of size n.credits
+ ## w is of size n.credits
+ ## S is of size n.credits by nZ
+ ## rho is a double
+ ## 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)))
}
@@ -842,10 +850,12 @@ MFlossdist.prepay.joint2 <- function(w, Z, rho, defaultprob, defaultprobmod,
Rstoch[i,,t] <- stochasticrecovC(recov[i], 0, Z, w, rho, defaultprob[i,t], defaultprobmod[i,t])
}
}
+
Q <- array(0, dim=c(ncol(defaultprob), Ngrid, Ngrid))
for(t in 1:ncol(defaultprob)){
S <- 1 - Rstoch[,,t]
- Q[t,,] <- lossdistC.prepay.jointZ(dp[,t], pp[,t], issuerweights, S, Ngrid, defaultflag, rho, Z, w)
+ Q[t,,] <- lossdistC.prepay.jointZ(defaultprobmod[,t], prepayprobmod[,t], issuerweights,
+ S, Ngrid, defaultflag, rho, Z, w)
}
return( Q )
}