diff options
Diffstat (limited to 'R/cds_utils.R')
| -rw-r--r-- | R/cds_utils.R | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/R/cds_utils.R b/R/cds_utils.R index 95dbca65..4c352163 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -75,19 +75,17 @@ couponSchedule <- function(nextpaydate=NULL, maturity, }
names(dates) <- NULL
- dt <- switch(frequency,
- Semiannual = 1/2,
- Quarterly = 1/4,
- Monthly = 1/12,
- Bimonthly = 1/6,
- Annual = 1)
- DC <- DiscountCurve(c(YC$params, list(dt=dt)),
- YC$tsQuotes, yearFrac(YC$params$tradeDate, dates), YC$legparams)
-
+ period <- switch(frequency,
+ Semiannual = "6m",
+ Quarterly = "3m",
+ Monthly = "1m",
+ Bimonthly = "2m",
+ Annual = "1y")
+ forwards <- forwardRates(YC, dates, period)
if(is.na(coupontype) || (toupper(coupontype)=="FLOAT" && !is.na(margin))){
## if is.na(margin) probably letter of credit
## we floor the coupon at the current gross rate
- coupons <- pmax(currentcoupon, DC$forwards + margin)
+ coupons <- pmax(currentcoupon, forwards + margin)
}else{
coupons <- rep(currentcoupon, length(dates))
}
@@ -96,10 +94,10 @@ couponSchedule <- function(nextpaydate=NULL, maturity, yf[length(yf)] <- yf[length(yf)]+1/360
coupons <- yf * coupons
- if(tradedate!=DC$params$tradeDate){
- df <- cumprod(exp(-DC$forwards * diff(c(0, yearFrac(tradedate, dates)))))
+ if(tradedate != referenceDate(YC)){
+ df <- cumprod(exp(-forwards * diff(c(0, yearFrac(tradedate, dates)))))
}else{
- df <- DC$discounts
+ df <- discountFactors(YC, dates)
}
return( data.frame(dates=dates, unadj.dates = unadj.dates, coupons=coupons, df = df) )
}
|
