aboutsummaryrefslogtreecommitdiffstats
path: root/R/calibration.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/calibration.R')
-rw-r--r--R/calibration.R35
1 files changed, 16 insertions, 19 deletions
diff --git a/R/calibration.R b/R/calibration.R
index 73479fbd..e1b8a74f 100644
--- a/R/calibration.R
+++ b/R/calibration.R
@@ -48,33 +48,30 @@ set.singlenamesdata <- function(index, tradedate){
}
set.tranchedata <- function(index, tradedate){
- temp <- get.tranchequotes(index$name, tradedate)
- if(!is.na(index$indexrefprice[1])){
- index$indexrefprice <- temp$indexrefprice[1]/100
+ temp <- get.tranchequotes(index$name, index$tenor, tradedate)
+ if(!is.na(temp$indexrefprice[1])&&temp$indexrefprice[1]!=0){
+ index$priceref <- temp$indexrefprice[1]/100
}else{
- index$indexrefprice <- 1
+ index$priceref <- 1
}
- index$indexrefspread <- temp$indexrefspread*1e-4
- index$cs <- couponSchedule(IMMDate(tradedate), index$maturity,"Q", "FIXED", index$indexrefspread,
+ index$spreadref <- temp$indexrefspread[1]*1e-4
+ index$cs <- couponSchedule(IMMDate(tradedate), index$maturity,"Q", "FIXED", index$spreadref,
0, tradedate, IMMDate(tradedate, "prev"))
index$portfolio <- tweakcurves(index, tradedate)$portfolio
- index$defaultprob <- 1-SPmatrix(index$portfolio, length(index$cs$dates))
+ index$defaultprob <- 1 - SPmatrix(index$portfolio, length(index$cs$dates))
negprob <- which(index$defaultprob<0, arr.ind=T)
if(nrow(negprob)>0){
stop(paste(index$portfolio[[negprob[1,]]]@issuer, "has negative probability, check single names data"))
}
K <- c(0, temp$detach/100)
index$K <- adjust.attachments(K, index$loss, index$factor)
- index$tranche.upf <- temp$upfront
- index$tranche.running <- temp$running*1e-4
-
- ## convert the quotes
- ## - we convert to protection terms x->1-x/100
- ## - we remove accrued x->x-acc
- ## - we weight it by the size of the tranche
- ## - we take the cumsum to convert to 0-5, 0-10, 0-15 quotes, etc...
- ## calibrate the tranches using base correlation
- index$quotes <- cumsum(diff(index$K) *
- (1-index$tranche.upf/100-cdsAccrued(tradedate, index$tranche.running)))
- return(index)
+ index$tranche.upf <- temp$trancheupfront
+ 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)
+ }else{
+ index$quotes <- index$tranche.upf/100+cdsAccrued(tradedate, index$tranche.running)
+ }
+ return( index )
}