diff options
Diffstat (limited to 'tranche_functions.R')
| -rw-r--r-- | tranche_functions.R | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/tranche_functions.R b/tranche_functions.R index 45662584..7329c971 100644 --- a/tranche_functions.R +++ b/tranche_functions.R @@ -648,10 +648,12 @@ MFlossdistrib2 <- function(cl, w, Z, rho, defaultprob, defaultprobmod, issuerwei pshocked <- apply(defaultprobmod, 2, shockprob, rho=rho, Z=Z[i])
S <- 1 - Rstoch[i,,]
dist <- lossrecovdist.joint.term(pshocked, 0, issuerweights, S, Ngrid)
+ gc()
return(dist)
}
- Q <- array(0, dim=c(ncol(defaultprob), Ngrid, Ngrid))
temp <- parSapply(cl, 1:length(w), parf)
+ clusterCall(cl, gc)
+ Q <- array(0, dim=c(ncol(defaultprob), Ngrid, Ngrid))
for(i in 1:length(w)){
Q <- Q + w[i]*array(temp[,i], dim=c(ncol(defaultprob), Ngrid, Ngrid))
}
@@ -680,9 +682,11 @@ MFlossrecovdist2 <- function(cl, w, Z, rho, defaultprob, defaultprobmod, dist <- lossrecovdist.joint.term(dpshocked, ppshocked, issuerweights, S, Ngrid)
return(dist)
}
+ ## temp <- sapply(1:length(w), parf)
+ clusterExport(cl, list("Rstoch", "defaultprobmod", "prepayprobmod"), envir=environment())
+ temp <- parSapply(cl, 1:length(w), parf)
+ clusterCall(cl, gc)
Q <- array(0, dim=c(ncol(defaultprob), Ngrid, Ngrid))
- ## temp <- parSapply(cl, 1:length(w), parf)
- temp <- sapply(1:length(w), parf)
for(i in 1:length(w)){
Q <- Q + w[i]*array(temp[,i], dim=c(ncol(defaultprob), Ngrid, Ngrid))
}
@@ -706,7 +710,7 @@ MFtranche.pv <- function(cl, cs, w, rho, defaultprob, defaultprobmod, issuerweig dist <- lossrecovdist.term(pshocked, 0, issuerweights, S, Ngrid)
return( tranche.pvvec(Kmodified, dist$L, dist$R, cs))
}
- clusterExport(cl, list("Rstoch", "p"))
+ clusterExport(cl, list("Rstoch", "p"), envir=environment())
result <- parSapply(cl, 1:length(w), parf)
return( list(pv=100*(1+result%*%w), pv.w=result))
}
|
