aboutsummaryrefslogtreecommitdiffstats
path: root/R/cds_functions_generic.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/cds_functions_generic.R')
-rw-r--r--R/cds_functions_generic.R8
1 files changed, 5 insertions, 3 deletions
diff --git a/R/cds_functions_generic.R b/R/cds_functions_generic.R
index 1b35e42c..6f9900bd 100644
--- a/R/cds_functions_generic.R
+++ b/R/cds_functions_generic.R
@@ -234,10 +234,12 @@ setMethod("defaultleg", signature("data.frame", "defaultcurve", "numeric"),
## coupon schedule, hazard rate curve, and recovery.
function(cs, sc, recovery, startdate=Sys.Date()+1){
T <- yearFrac(startdate, cs$dates)
+ x1T <- yearFrac(startdate, sc@dates)
+ hfun <- approxfun(x1T, sc@hazardrates, method="constant", rule=2)
dT <- diff(c(0, T))
- Q <- cumprod(exp(-sc@hazardrates[1:length(dT)] * dT)) * cs$df
+ Q <- cumprod(exp(-hfun(T) * dT)) * cs$df
Qmid <- 1/2 * (c(1, Q[-length(Q)]) + Q)
- r <- (1 - recovery) * crossprod(sc@hazardrates[1:length(dT)] * Qmid, dT)
+ r <- (1 - recovery) * crossprod(hfun(T) * Qmid, dT)
return( as.numeric(r) )
})
@@ -651,7 +653,7 @@ indexspread <- function(index, tradedate=Sys.Date()){
indextheta <- function(index, tradedate=Sys.Date()){
current.pv <- indexpv(index, tradedate=tradedate)$bp
- newmaturity <- index$cs$dates[nrow(index$cs)-4]
+ 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