diff options
Diffstat (limited to 'R/calibration.R')
| -rw-r--r-- | R/calibration.R | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/R/calibration.R b/R/calibration.R index 9ef99a83..7394dbec 100644 --- a/R/calibration.R +++ b/R/calibration.R @@ -22,7 +22,7 @@ get.cdsSchedule <- function(tradedate, indexmaturity){ for(tenor in paste0(c(1:5, 7,10), "y")){ newdate <- cdsMaturity(tenor, date=tradedate) cdsdates <- c(cdsdates, newdate) - if(newdate>indexmaturity){ + if(newdate>=indexmaturity){ break } } @@ -51,18 +51,19 @@ set.singlenamesdata <- function(index, tradedate){ set.tranchedata <- function(index, tradedate){ temp <- get.tranchequotes(index$name, index$tenor, tradedate) - index$spreadref <- temp$indexrefspread[1]*1e-4 + index$quotes <- data.frame(spread=temp$indexrefspread[1]*1e-4, maturity=index$maturity) if(index$name=="ig19" || index$name=="ig21"){ - index$spreadref <- 0.01 + index$quotes$spread <- 0.01 } - index$cs <- couponSchedule(IMMDate(tradedate), index$maturity,"Q", "FIXED", index$spreadref, + index$cs <- couponSchedule(IMMDate(tradedate, noadj=TRUE), index$maturity,"Q", "FIXED", + index$quotes$spread[1], 0, tradedate, IMMDate(tradedate, "prev")) if(!is.na(temp$indexrefprice[1])&&temp$indexrefprice[1]!=0){ - index$priceref <- temp$indexrefprice[1]/100 + index$quotes$price <- temp$indexrefprice[1]/100 }else{ sc <- new("flatcurve", h=temp$indexrefspread[1]*1e-4/(1-index$recovery)) index$priceref <- 1 + cdspv(index$cs, sc, index$recovery, tradedate)- - cdsAccrued(tradedate, index$spreadref) + cdsAccrued(tradedate, index$quotes$spread[1]) } index$portfolio <- tweakcurves(index, tradedate)$portfolio index$defaultprob <- 1 - SPmatrix(index$portfolio, length(index$cs$dates)) @@ -76,9 +77,9 @@ set.tranchedata <- function(index, tradedate){ index$tranche.running <- temp$trancherunning*1e-4 ## compute dirty protection price if(length(grep("hy", index$name, ignore.case=TRUE))>0){ - index$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$quotes <- index$tranche.upf/100+cdsAccrued(tradedate, index$tranche.running) + index$tranche.quotes <- index$tranche.upf/100+cdsAccrued(tradedate, index$tranche.running) } return( index ) } |
