diff options
| -rw-r--r-- | R/calibration.R | 8 | ||||
| -rw-r--r-- | R/cds_functions_generic.R | 20 | ||||
| -rw-r--r-- | R/cds_utils.R | 2 |
3 files changed, 12 insertions, 18 deletions
diff --git a/R/calibration.R b/R/calibration.R index b6b5b5c6..9eeb03b5 100644 --- a/R/calibration.R +++ b/R/calibration.R @@ -13,7 +13,7 @@ buildSC <- function(quote, cs, cdsdates){ get.cdsSchedule <- function(tradedate){ cdsdates <- as.Date(character(0)) - for(tenor in paste0(c(1:5, 7), "y")){ + for(tenor in paste0(c(1:5, 7, 10), "y")){ newdate <- cdsMaturity(tenor, date=tradedate) cdsdates <- c(cdsdates, newdate) } @@ -32,10 +32,6 @@ set.singlenamesdata <- function(index, tradedate){ quotes$upfront_curve[i,] <- rep(0,8) quotes$recovery[i,] <- rep(0.4,8) } - - if(quotes$ticker[i] == "PLCOAL" && is.na(quotes$upfront_curve[i, "5y"])){ - quotes$upfront_curve[i, "5y"] = 85 - } quotes$upfront_curve[i, tenor] <- pmax(-yearFrac(tradedate+2,cds.cs$cdsdates)* quotes$spread_curve[i, tenor]*1e-2, quotes$upfront_curve[i, tenor]) @@ -72,7 +68,7 @@ set.tranchedata <- function(index, tradedate){ refspread=temp$indexrefspread[1], refprice=temp$indexrefprice[1]) index$quotes$spread <- couponfromindex(index$name, index$tenor)*1e-4 - index$cs <- couponSchedule(IMMDate(tradedate, noadj=TRUE), index$maturity,"Q", "FIXED", 1, + index$cs <- couponSchedule(IMMDate(tradedate, noadj=TRUE), index$maturity, "Q", "FIXED", 1, 0, tradedate, IMMDate(tradedate, "prev")) if(!is.na(index$quotes$refprice) && index$quotes$refprice != 0){ index$quotes$price <- index$quotes$refprice/100 diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R index 5407ccaa..6ccf7c37 100644 --- a/R/cds_functions_generic.R +++ b/R/cds_functions_generic.R @@ -608,10 +608,9 @@ indexpv <- function(index, epsilon=0, tradedate=Sys.Date(), clean=TRUE, portfolio <- index$portfolio
}
startdate <- tradedate + 1
- #ugly hack
- 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)}))
+ cs <- index$cs[index$cs$unadj.dates <= maturity,]
+ 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",
@@ -639,7 +638,7 @@ indexduration <- function(index, tradedate, maturity=index$maturity){ ## compute the duration of a portfolio of survival curves
cs <- index$cs[index$cs$dates-maturity< 3,]
startdate <- tradedate+1
- cl.list <- unlist(lapply(index$portfolio, function(x){couponleg(cs, x@curve, startdate)}))
+ cl.list <- unlist(lapply(index$portfolio, function(x) couponleg(cs, x@curve, startdate) ))
return( mean(cl.list) )
}
@@ -656,15 +655,14 @@ indexspread <- function(index, tradedate=Sys.Date()){ return(S)
}
-indextheta <- function(index, tradedate=Sys.Date()){
- if(nrow(index$cs)<=4){
+indextheta <- function(index, tradedate=Sys.Date()) {
+ if(nrow(index$cs) <= 4) {
return( NA )
}
current.pv <- indexpv(index, tradedate=tradedate)$bp
- newmaturity <- index$cs$unadj.dates[nrow(index$cs)-4]
- index$quotes$maturity <- newmaturity
- forward.pv <- indexpv(index, tradedate=tradedate, maturity=newmaturity)$bp
- theta <- forward.pv-current.pv+index$quotes$spread
+ newmaturity <- index$maturity - lubridate::years(1)
+ rolled.pv <- indexpv(index, tradedate=tradedate, maturity=newmaturity)$bp
+ theta <- rolled.pv - current.pv + index$quotes$spread[index$quotes$maturity == index$maturity]
return( theta )
}
diff --git a/R/cds_utils.R b/R/cds_utils.R index 044c616a..2b37788d 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -164,7 +164,7 @@ cdsMaturity <- function(tenor, date=Sys.Date()){ if(date < as.Date("2015-12-20")){
r <- IMMDate(addTenor(date, tenor))
}else{
- r <- IMMDate2(date, tenor)
+ r <- IMMDate2(date, tenor, noadj=T)
}
names(r) <- tenor
|
