diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/tranche_functions.R | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/R/tranche_functions.R b/R/tranche_functions.R index e1f0ab91..49b1c218 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -409,8 +409,14 @@ fit.prob <- function(Z, w, rho, p0){ }
stochasticrecov <- function(R, Rtilde, Z, w, rho, porig, pmod){
- ptilde <- fit.prob(Z, w, rho, (1-R)/(1-Rtilde) * porig)
- return(abs(1-(1-Rtilde) * exp(shockprob(ptilde, rho, Z, TRUE) - shockprob(pmod, rho, Z, TRUE))))
+ ## if porig == 0 (probably matured asset) then return orginal recovery
+ ## it shouldn't matter anyway since we never default that asset
+ if(porig == 0){
+ return(rep(R, length(Z)))
+ }else{
+ ptilde <- fit.prob(Z, w, rho, (1-R)/(1-Rtilde) * porig)
+ return(abs(1-(1-Rtilde) * exp(shockprob(ptilde, rho, Z, TRUE) - shockprob(pmod, rho, Z, TRUE))))
+ }
}
pos <- function(x){
@@ -756,7 +762,7 @@ MFlossdist.prepay.joint <- function(cl, w, Z, rho, defaultprob, defaultprobmod, ## we cut it in chunks to keep it manageable
chunksize <- length(w)/n.chunks
for(chunk in 1:n.chunks){
- if(length(cl)>0){
+ if(!is.null(cl)){
clusterExport(cl, list("Rstoch", "defaultprobmod", "prepayprobmod"), envir=environment())
temp <- parSapply(cl, (1+chunksize*(chunk-1)):(chunksize*chunk), parf)
## need to call gc twice for some reason, otherwise doesn't release everything
|
