diff options
Diffstat (limited to 'R/cds_functions_generic.R')
| -rw-r--r-- | R/cds_functions_generic.R | 14 |
1 files changed, 13 insertions, 1 deletions
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){
|
