diff options
Diffstat (limited to 'R/cds_utils.R')
| -rw-r--r-- | R/cds_utils.R | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/R/cds_utils.R b/R/cds_utils.R index 2b37788d..7553231a 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -36,7 +36,7 @@ addTenor <- function(date, tenor) { couponSchedule <- function(nextpaydate=NULL, maturity,
frequency=c("Quarterly", "Monthly", "Bimonthly", "Semiannual", "Annual"),
- coupontype, currentcoupon,
+ coupontype=c("FLOAT", "FIXED"), currentcoupon,
margin, tradedate=Sys.Date(), prevpaydate=tradedate){
## computes the coupon schedule
## inputs:
@@ -45,6 +45,7 @@ couponSchedule <- function(nextpaydate=NULL, maturity, ## frequency: letter specifying the frequency between "Q", "M", "B", "S" or "A"
## if startdate is provided, we generate the forward coupon schedule starting from that date.
frequency <- match.arg(frequency)
+ coupontype <- if (is.na(coupontype)) "FLOAT" else match.arg(coupontype)
bystring <- switch(frequency,
Quarterly = "3 months",
Monthly = "1 month",
@@ -84,11 +85,11 @@ couponSchedule <- function(nextpaydate=NULL, maturity, Bimonthly = "2m",
Annual = "1y")
forwards <- YC$forwardRate(dates, period)
- if(is.na(coupontype) || (toupper(coupontype)=="FLOAT" && !is.na(margin))){
+ 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)
- }else{
+ } else {
coupons <- rep(currentcoupon, length(dates))
}
yf <- diff(c(0, yearFrac(prevpaydate, dates, "act/360")))
|
