diff options
Diffstat (limited to 'R/cds_utils.R')
| -rw-r--r-- | R/cds_utils.R | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/R/cds_utils.R b/R/cds_utils.R index d48bbd11..2d83457d 100644 --- a/R/cds_utils.R +++ b/R/cds_utils.R @@ -108,7 +108,7 @@ couponSchedule <- function(nextpaydate=NULL, maturity, frequency, coupontype, cu return( data.frame(dates=dates, coupons=coupons, df = df) )
}
-IMMDate <- function(tradedate, type="next") {
+IMMDate <- function(tradedate, type="next", noadj=FALSE) {
## returns the next IMM date for a CDS, adjusted for settlement
## or previous one if type="prev"
## protection seems to be assumed at close of business day
@@ -119,14 +119,17 @@ IMMDate <- function(tradedate, type="next") { startyear <- startyear - 1
nextimmdates <- seq(as.Date(paste(startyear, 3, 20, sep="-")), length=9, by="3 months")
if(type == "next"){
- val <- adjust(calendar = "UnitedStates/GovernmentBond",
- nextimmdates[nextimmdates >= start.protection][1] )
+ val <- nextimmdates[nextimmdates >= start.protection][1]
}else if(type == "prev"){
temp <- nextimmdates[nextimmdates < start.protection]
- val <- adjust(calendar = "UnitedStates/GovernmentBond", temp[length(temp)] )
+ val <- temp[length(temp)]
+
}else{
stop("incorrect type")
}
+ if(!noadj){
+ val <- adjust(calendar = "UnitedStates/GovernmentBond", val )
+ }
names(val) <- NULL
return( val )
}
|
