diff options
Diffstat (limited to 'R/calibration.R')
| -rw-r--r-- | R/calibration.R | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/R/calibration.R b/R/calibration.R index 98460489..7caec58f 100644 --- a/R/calibration.R +++ b/R/calibration.R @@ -57,7 +57,7 @@ set.tranchedata <- function(index, tradedate){ } index$cs <- couponSchedule(IMMDate(tradedate, noadj=TRUE), index$maturity,"Q", "FIXED", 1, 0, tradedate, IMMDate(tradedate, "prev")) - if(!is.na(temp$indexrefprice[1])&&temp$indexrefprice[1]!=0){ + if(!is.na(temp$indexrefprice[1]) && temp$indexrefprice[1] != 0){ index$quotes$price <- temp$indexrefprice[1]/100 }else{ ##rewrite as a snac function @@ -67,22 +67,24 @@ set.tranchedata <- function(index, tradedate){ defaultleg(index$cs, sc, index$recovery, startdate) index$quotes$price <- 1 + cds.pv - cdsAccrued(tradedate, index$quotes$spread[1]) } - index$portfolio <- tweakcurves(index, tradedate)$portfolio + tweak <- tweakcurves(index, tradedate) + index$portfolio <- NULL + index <- c(index, tweak) index$defaultprob <- 1 - SPmatrix(index$portfolio, length(index$cs$dates)) negprob <- which(index$defaultprob<0, arr.ind=T) - if(nrow(negprob)>0){ + if(nrow(negprob) > 0){ stop(paste(index$portfolio[[negprob[1,1]]]@issuer, "has negative probability, check single names data")) } K <- c(0, temp$detach/100) index$K.orig <- K index$K <- adjust.attachments(K, index$loss, index$factor) index$tranche.upf <- temp$trancheupfrontmid - index$tranche.running <- temp$trancherunningmid*1e-4 + index$tranche.running <- temp$trancherunningmid * 1e-4 ## compute dirty protection price if(length(grep("hy", index$name, ignore.case=TRUE))>0){ - index$tranche.quotes <- 1-index$tranche.upf/100-cdsAccrued(tradedate, index$tranche.running) + index$tranche.quotes <- 1 - index$tranche.upf/100 - cdsAccrued(tradedate, index$tranche.running) }else{ - index$tranche.quotes <- index$tranche.upf/100-cdsAccrued(tradedate, index$tranche.running) + index$tranche.quotes <- index$tranche.upf/100 - cdsAccrued(tradedate, index$tranche.running) } return( index ) } |
