diff options
Diffstat (limited to 'R')
| -rw-r--r-- | R/calibrate_tranches_BC.R | 7 | ||||
| -rw-r--r-- | R/tranche_functions.R | 25 |
2 files changed, 16 insertions, 16 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R index a2db8f56..47d0fad4 100644 --- a/R/calibrate_tranches_BC.R +++ b/R/calibrate_tranches_BC.R @@ -114,7 +114,12 @@ for(run in config$runs){ ## compute various risk numbers
index$tranches <- cbind(index$tranches, BCtranche.delta(index))
- index$tranches <- cbind(index$tranches, BCtranche.theta(index, method="TLP"))
+ index$tranches <- cbind(index$tranches, tryCatch(BCtranche.theta(index, method="TLP"),
+ error = function(e) {
+ logerror(e$message)
+ n <- nrow(index$tranches)
+ data.frame(theta=rep(NA, n),
+ fw.delta=rep(NA, n)) }))
index$tranches$corr01 <- BCtranche.corr01(index)
temp <- BCtranche.pv(index, protection=TRUE)
index$tranches$duration <-
diff --git a/R/tranche_functions.R b/R/tranche_functions.R index 125b5a40..3a7a643c 100644 --- a/R/tranche_functions.R +++ b/R/tranche_functions.R @@ -236,23 +236,18 @@ adjust.skew <- function(index1, index2, method="ATM"){ return(c(NA, cap(skew(K1eq)), NA)) } -theta.adjust.skew <- function(index, shortened=4, method="ATM"){ - #ajust the correlation skew by doing ATM mapping on the expected loss +BCtranche.theta <- function(index, shortened=4, complement=FALSE, method="ATM") { + N <- nrow(index$cs) - shortened + if(N < 0) { + stop("Maturity too short for computing tranche thetas") + } indexshort <- index - N <- nrow(index$cs)-shortened - indexshort$defaultprob <- indexshort$defaultprob[,1:N] - indexshort$cs <- indexshort$cs[1:N,] - return(adjust.skew(index, indexshort, method)) -} - -BCtranche.theta <- function(index, shortened=4, complement=FALSE, method="ATM"){ + indexshort$defaultprob <- index$defaultprob[,1:N] + indexshort$cs <- index$cs[1:N,] + indexshort$rho <- adjust.skew(index, indexshort, method) temp <- BCtranche.pv(index, complement=complement) - index$rho <- theta.adjust.skew(index, shortened, method) - N <- nrow(index$cs) - shortened - index$cs <- index$cs[1:N,] - index$defaultprob <- index$defaultprob[,1:N] - temp2 <- BCtranche.pv(index, complement=complement) - temp3 <- BCtranche.delta(index, complement=complement) + temp2 <- BCtranche.pv(indexshort, complement=complement) + temp3 <- BCtranche.delta(indexshort, complement=complement) return(data.frame(theta=temp2$bp-temp$bp+index$tranches$running, fw.delta=temp3$delta)) } |
