aboutsummaryrefslogtreecommitdiffstats
path: root/R/calibration.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/calibration.R')
-rw-r--r--R/calibration.R27
1 files changed, 18 insertions, 9 deletions
diff --git a/R/calibration.R b/R/calibration.R
index 674e1817..73479fbd 100644
--- a/R/calibration.R
+++ b/R/calibration.R
@@ -17,25 +17,29 @@ buildSC <- function(quote, cs, cdsdates){
return( SC )
}
-get.cdsSchedule <- function(tradedate){
+get.cdsSchedule <- function(tradedate, indexmaturity){
cdsdates <- as.Date(character(0))
- for(tenor in paste0(1:5, "y")){
- cdsdates <- c(cdsdates, cdsMaturity(tenor, date=tradedate))
+ for(tenor in paste0(c(1:5, 7,10), "y")){
+ newdate <- cdsMaturity(tenor, date=tradedate)
+ cdsdates <- c(cdsdates, newdate)
+ if(newdate>indexmaturity){
+ break
+ }
}
return( list(cs=couponSchedule(IMMDate(tradedate), cdsdates[length(cdsdates)], "Q", "FIXED",
1, tradedate, IMMDate(tradedate, "prev")), cdsdates=cdsdates) )
}
set.singlenamesdata <- function(index, tradedate){
- cds.cs <- get.cdsSchedule(tradedate)
+ cds.cs <- get.cdsSchedule(tradedate, index$maturity)
quotes <- get.indexquotes(index$name, tradedate)
- tenor <- paste0(1:5, "y")
+ tenor <- names(cds.cs$cdsdates)
index$portfolio <- list()
for(i in seq_along(quotes$tickers)){
quote <- list(ticker = quotes$ticker[i],
running = quotes$spread_curve[i, tenor] * 1e-4,
upfront = quotes$upfront_curve[i, tenor] * 0.01,
- recovery = quotes$recovery[i,tenor][1])
+ recovery = as.double(quotes$recovery[i,tenor][1]))
index$portfolio <- c(index$portfolio, buildSC(quote, cds.cs$cs, cds.cs$cdsdates))
}
index$issuerweights <- rep(1/length(index$portfolio), length(index$portfolio))
@@ -45,9 +49,14 @@ set.singlenamesdata <- function(index, tradedate){
set.tranchedata <- function(index, tradedate){
temp <- get.tranchequotes(index$name, tradedate)
- index$indexref <- temp$refbasketprice[1]/100
- index$cs <- couponSchedule(IMMDate(tradedate), index$maturity,"Q", "FIXED", 0.05, 0, tradedate,
- IMMDate(tradedate, "prev"))
+ if(!is.na(index$indexrefprice[1])){
+ index$indexrefprice <- temp$indexrefprice[1]/100
+ }else{
+ index$indexrefprice <- 1
+ }
+ index$indexrefspread <- temp$indexrefspread*1e-4
+ index$cs <- couponSchedule(IMMDate(tradedate), index$maturity,"Q", "FIXED", index$indexrefspread,
+ 0, tradedate, IMMDate(tradedate, "prev"))
index$portfolio <- tweakcurves(index, tradedate)$portfolio
index$defaultprob <- 1-SPmatrix(index$portfolio, length(index$cs$dates))
negprob <- which(index$defaultprob<0, arr.ind=T)