diff options
Diffstat (limited to 'R/cds_utils.R')
| -rw-r--r-- | R/cds_utils.R | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/R/cds_utils.R b/R/cds_utils.R index 7553231a..cdccbb78 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -37,7 +37,8 @@ addTenor <- function(date, tenor) { couponSchedule <- function(nextpaydate=NULL, maturity,
frequency=c("Quarterly", "Monthly", "Bimonthly", "Semiannual", "Annual"),
coupontype=c("FLOAT", "FIXED"), currentcoupon,
- margin, tradedate=Sys.Date(), prevpaydate=tradedate){
+ margin, tradedate=Sys.Date(), prevpaydate=tradedate,
+ liborfloor){
## computes the coupon schedule
## inputs:
## nextpaydate: first payment date of the coupon schedule
@@ -53,26 +54,27 @@ couponSchedule <- function(nextpaydate=NULL, maturity, Semiannual = "6 months",
Annual = "12 months")
- if(is.null(bystring)){
+ if(is.null(bystring)) {
stop("unknown frequency")
}
- if(is.null(nextpaydate)){
- dates <- rev(seq(maturity, tradedate, by =paste0("-", bystring)))
- }else{
- if(nextpaydate>maturity){
- dates <- maturity
- }else{
- ## weird bug with non integer dates, hence the as.Date(as.POSIXlt(.)) trick
- dates <- seq(nextpaydate, as.Date(as.POSIXlt(maturity)), by = bystring)
+ dates <-
+ if(is.null(nextpaydate)){
+ rev(seq(maturity, tradedate, by =paste0("-", bystring)))
+ } else {
+ if(nextpaydate>maturity) {
+ maturity
+ } else {
+ ## weird bug with non integer dates, hence the as.Date(as.POSIXlt(.)) trick
+ dates <- seq(nextpaydate, as.Date(as.POSIXlt(maturity)), by = bystring)
+ }
}
- }
- dates <- dates[ dates >= tradedate]
+ dates <- dates[dates >= tradedate]
## we want to make sure maturity is last date
- if(length(dates)==0 || dates[length(dates)] < maturity){
+ if(length(dates) == 0 || dates[length(dates)] < maturity){
dates <- c(dates, maturity)
}
unadj.dates <- dates
- if(length(dates) > 1){
+ if(length(dates) > 1) {
cal <- Calendar$new("UnitedStates/GovernmentBond")
dates[-length(dates)] <- cal$adjust(dates[-length(dates)])
}
@@ -88,7 +90,11 @@ couponSchedule <- function(nextpaydate=NULL, maturity, if(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, forwards + margin)
+ if( missing(liborfloor) ) {
+ coupons <- pmax(currentcoupon, forwards + margin)
+ } else {
+ coupons <- pmax(forwards, liborfloor) + margin
+ }
} else {
coupons <- rep(currentcoupon, length(dates))
}
|
