aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/calibrate_tranches_BC.R4
-rw-r--r--R/calibration.R3
-rw-r--r--R/cds_functions_generic.R14
3 files changed, 20 insertions, 1 deletions
diff --git a/R/calibrate_tranches_BC.R b/R/calibrate_tranches_BC.R
index 6b8414bb..e3c30cf8 100644
--- a/R/calibrate_tranches_BC.R
+++ b/R/calibrate_tranches_BC.R
@@ -75,6 +75,10 @@ for(i in seq_along(runs$name)){
## calibrate the single names curves
index <- set.singlenamesdata(index, tradedate)
index <- set.tranchedata(index, tradedate)
+ if(is.null(index)){
+ loginfo(paste("skipping", index.name, tenor))
+ next
+ }
temp <- BCindex.pv(index)
index$EL <- -temp$pl
index$duration <- temp$cl-cdsAccrued(tradedate, 1)
diff --git a/R/calibration.R b/R/calibration.R
index c16cdaca..9c0e9b2d 100644
--- a/R/calibration.R
+++ b/R/calibration.R
@@ -71,6 +71,9 @@ set.tranchedata <- function(index, tradedate){
defaultleg(index$cs, sc, index$recovery, startdate)
index$quotes$price <- 1 + cds.pv - cdsAccrued(tradedate, index$quotes$spread[1])
}
+ if(length(indexpv(index, tradedate=tradedate, check=TRUE))==1){
+ return(NULL)
+ }
tweak <- tweakcurves(index, tradedate)
index$portfolio <- NULL
index <- c(index, tweak)
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index cdab10ae..fe8d4707 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -539,7 +539,7 @@ tweakportfolio <- function(portfolio, epsilon, multiplicative=TRUE, forward.twea
}
indexpv <- function(index, epsilon=0, tradedate=Sys.Date(), clean=TRUE,
- maturity=index$maturity, forward.tweak=1){
+ maturity=index$maturity, forward.tweak=1, check=FALSE){
## computes the intrinsic price of a portfolio of cds
## If maturity is provided, only computes the pv up to that point
## (Say we compute the 3 year pv based on 5 year curves
@@ -555,6 +555,18 @@ indexpv <- function(index, epsilon=0, tradedate=Sys.Date(), clean=TRUE,
cs <- index$cs[index$cs$dates-maturity< 3,]
cl.list <- unlist(lapply(portfolio, function(x){couponleg(cs, x@curve, startdate)}))
pl.list <- unlist(lapply(portfolio, function(x){defaultleg(cs, x@curve, x@recovery, startdate)}))
+ if(check){
+ if(any(is.na(cl.list))){
+ logerror(paste("couldn't compute single name protection leg for",
+ index$portfolio[[which(is.na(pl.list))]]@issuer))
+ return(NA)
+ }
+ if(any(is.na(pl.list))){
+ logerror(paste("couldn't compute single name protection leg for",
+ index$portfolio[[which(is.na(pl.list))]]@issuer))
+ return(NA)
+ }
+ }
spread <- index$quotes$spread[index$quotes$maturity==maturity]
r <- list(cl = spread * mean(cl.list), pl = mean(pl.list), bp = 1+mean(spread*cl.list-pl.list))
if(clean){