diff options
| -rw-r--r-- | build_SC.R | 15 | ||||
| -rw-r--r-- | tranche_functions.R | 21 |
2 files changed, 23 insertions, 13 deletions
@@ -140,20 +140,9 @@ dist.joint <- MFlossdist.prepay.joint(cl, w.mod, Z, rho, dp, dpmod, ## first using the actual function (numerically instable)
## dist.joint2 <- MFlossdist.prepay.joint(cl, w.mod, Z, rho, dp, dpmod,
## pp, ppmod, issuerweights, 1-S, Ngrid=201, TRUE)
+
## second, by doing a change of variable seems to work better for now
-distDR <- array(0, dim=dim(dist.joint))
-u <- seq(0, 1, length=Ngrid)
-v <- seq(0, 1, length=Ngrid)
-for(t in 1:ncol(dp)){
- for(i in 1:Ngrid){
- for(j in 1:Ngrid){
- index <- i+j
- if(index<=Ngrid){
- distDR[t,index,j] <- distDR[t,index,j] + dist.joint[t,i,j]
- }
- }
- }
-}
+distDR <- dist.transform(dist.joint)
## compute E(R|D)
R <- matrix(0, Ngrid, ncol(dp))
diff --git a/tranche_functions.R b/tranche_functions.R index 63f5d20b..51a0cd87 100644 --- a/tranche_functions.R +++ b/tranche_functions.R @@ -339,6 +339,27 @@ lossrecovdist.joint.term <- function(defaultprob, prepayprob, w, S, N, defaultfl return(Q)
}
+
+dist.transform <- function(dist.joint){
+ ## compute the joint (D, R) distribution
+ ## from the (L, R) distribution using D = L+R
+ distDR <- array(0, dim=dim(dist.joint))
+ Ngrid <- dim(dist.joint)[2]
+ u <- seq(0, 1, length=Ngrid)
+ v <- seq(0, 1, length=Ngrid)
+ for(t in 1:ncol(dp)){
+ for(i in 1:Ngrid){
+ for(j in 1:Ngrid){
+ index <- i+j
+ if(index <= Ngrid){
+ distDR[t,index,j] <- distDR[t,index,j] + dist.joint[t,i,j]
+ }
+ }
+ }
+ }
+ return( distDR )
+}
+
shockprob <- function(p, rho, Z, log.p=F){
## computes the shocked default probability as a function of the copula factor
pnorm((qnorm(p)-sqrt(rho)*Z)/sqrt(1-rho), log.p=log.p)
|
