diff options
| -rw-r--r-- | R/cds_utils.R | 36 | ||||
| -rw-r--r-- | R/intex_deal_functions.R | 25 |
2 files changed, 36 insertions, 25 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))
}
diff --git a/R/intex_deal_functions.R b/R/intex_deal_functions.R index a1e4626b..1717a336 100644 --- a/R/intex_deal_functions.R +++ b/R/intex_deal_functions.R @@ -391,15 +391,20 @@ getdealschedule <- function(dealdata, freq = c("Monthly", "Quarterly"), tradedat } intexportfolio.forwardprice <- function(cdrmonthly, recoverymonthly, startdate, maturity, - coupontype, margin, liborfloor){ - if(missing(liborfloor)||is.na(liborfloor)){ - currentcoupon <- margin - }else{ - currentcoupon <- margin + liborfloor - } - forwardcs <- data.table(couponSchedule(nextpaydate=startdate+45, maturity, - frequency="Q", coupontype, margin, - currentcoupon, tradedate=startdate), key="dates") + coupontype, margin, liborfloor) { + forwardcs <- + if( missing(liborfloor) || is.na(liborfloor) ) { + data.table(couponSchedule(nextpaydate=startdate+45, maturity, + frequency="Q", coupontype, margin, + 0., tradedate=startdate), + key="dates") + } else { + data.table(couponSchedule(nextpaydate=startdate+45, maturity, + frequency="Q", coupontype, margin, + NA, tradedate=startdate, liborfloor=liborfloor), + key="dates") + } + notionals <- cdrmonthly[date>=startdate, lapply(.SD,function(x)cumprod(1-x/100*1/12)), .SDcols=paste0("V",1:100)] recovery <- as.matrix(recoverymonthly[date>=startdate, .SD, .SDcols=paste0("V",1:100)])* @@ -420,7 +425,7 @@ intexportfolio.forwardprice <- function(cdrmonthly, recoverymonthly, startdate, mean(recovery+po+io) } -compute.reinvprices <- function(dealname, cdrmonthly, recoverymonthly, params, rollingmaturity, tradedate){ +compute.reinvprices <- function(dealname, cdrmonthly, recoverymonthly, params, rollingmaturity, tradedate) { reinvassets <- get.reinvassets(dealname, tradedate) reinvprices <- list() if(length(reinvassets) > 0) { |
