diff options
Diffstat (limited to 'R/cds_utils.R')
| -rw-r--r-- | R/cds_utils.R | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/R/cds_utils.R b/R/cds_utils.R index 4c352163..044c616a 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -6,7 +6,8 @@ today <- function() { }
addBusDay <- function(tradedate = Sys.Date(), n.days = 3, calendar = "UnitedStates/GovernmentBond"){
- advance(calendar = calendar, dates=tradedate, n=n.days, timeUnit=0)
+ cal <- Calendar$new(calendar)
+ cal$advance(dates=tradedate, n=n.days, timeUnit=0)
}
convertTenor <- function(tenor) {
@@ -70,8 +71,9 @@ couponSchedule <- function(nextpaydate=NULL, maturity, dates <- c(dates, maturity)
}
unadj.dates <- dates
- if(length(dates)>1){
- dates[-length(dates)] <- adjust(calendar="UnitedStates/GovernmentBond", dates[-length(dates)])
+ if(length(dates) > 1){
+ cal <- Calendar$new("UnitedStates/GovernmentBond")
+ dates[-length(dates)] <- cal$adjust(dates[-length(dates)])
}
names(dates) <- NULL
@@ -81,7 +83,7 @@ couponSchedule <- function(nextpaydate=NULL, maturity, Monthly = "1m",
Bimonthly = "2m",
Annual = "1y")
- forwards <- forwardRates(YC, dates, period)
+ forwards <- YC$forwardRate(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
@@ -94,10 +96,10 @@ couponSchedule <- function(nextpaydate=NULL, maturity, yf[length(yf)] <- yf[length(yf)]+1/360
coupons <- yf * coupons
- if(tradedate != referenceDate(YC)){
+ if(tradedate != YC$referenceDate){
df <- cumprod(exp(-forwards * diff(c(0, yearFrac(tradedate, dates)))))
}else{
- df <- discountFactors(YC, dates)
+ df <- YC$discount(dates)
}
return( data.frame(dates=dates, unadj.dates = unadj.dates, coupons=coupons, df = df) )
}
@@ -123,7 +125,8 @@ IMMDate <- function(tradedate, type=c("next", "prev"), noadj=FALSE) { stop("incorrect type")
}
if(!noadj){
- val <- adjust(calendar = "UnitedStates/GovernmentBond", val )
+ cal <- Calendar$new("UnitedStates/GovernmentBond")
+ cal$adjust(val)
}
names(val) <- NULL
return( val )
@@ -144,7 +147,8 @@ IMMDate2 <- function(tradedate, tenor, noadj=FALSE) { firstimmdate <- temp[length(temp)]
maturity <- addTenor(addTenor(firstimmdate, tenor), "3m")
if(!noadj){
- maturity <- adjust(calendar = "UnitedStates/GovernmentBond", maturity )
+ cal <- Calendar$new("UnitedStates/GovernmentBond")
+ maturity <- cal$adjust( maturity )
}
names(maturity) <- NULL
return( maturity )
|
