diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/script_calibrate_tranches.R | 21 | ||||
| -rw-r--r-- | R/tranche_functions.R | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/R/script_calibrate_tranches.R b/R/script_calibrate_tranches.R index a62e7822..e360a712 100644 --- a/R/script_calibrate_tranches.R +++ b/R/script_calibrate_tranches.R @@ -125,7 +125,26 @@ for(l in 1:100){ cat(err,"\n")
}
-dist <- BClossdistC(p, issuerweights, recov, rho, Z, w.mod, Ngrid)
+Rstoch <- array(0, dim=c(n.credit, n.int, ncol(SurvProb)))
+for(t in 1:ncol(SurvProb)){
+ for(i in 1:n.credit){
+ Rstoch[i,,t] <- stochasticrecovC(recov[i], 0, Z, w.mod, rho[i], defaultprob[i,t], p[i,t])
+ }
+}
+
+Lw <- matrix(0, Ngrid, n.int)
+Rw <- matrix(0, Ngrid, n.int)
+L <- matrix(0, Ngrid, ncol(defaultprob))
+R <- matrix(0, Ngrid, ncol(defaultprob))
+for(t in 1:ncol(defaultprob)){
+ S <- 1 - Rstoch[,,t]
+ Lw <- lossdistCZ(p[,t], issuerweights, S, Ngrid, 0, rho, Z)
+ Rw <- lossdistCZ(p[,t], issuerweights, 1-S, Ngrid, 0, rho, Z)
+ L[,t] <- Lw%*%w.mod
+ R[,t] <- Rw%*%w.mod
+}
+
+dist <- list(L=L, R=R)
write.table(data.frame(Z=Z, w=w.mod),
file=file.path(root.dir, "Scenarios", "Calibration",
diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 1bb48487..287310ff 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -677,6 +677,8 @@ BClossdist <- function(defaultprob, issuerweights, recov, rho, Z, w, Z <- quadrature$nodes
w <- quadrature$weights
}
+ ## do not use if weights are not gaussian, results would be incorrect
+ ## since shockseverity is invalid in that case (need to use stochasticrecov)
LZ <- matrix(0, N, length(Z))
RZ <- matrix(0, N, length(Z))
L <- matrix(0, N, ncol(defaultprob))
|
