[R-sig-Finance] IMM Dates

Robert Sams Robert at sanctumfi.com
Wed May 24 18:30:33 CEST 2006


Hi David, 

This will give you the IMM date (3rd wednesday of the month) for a given integer month and year. A little hacking on it will yield exactly what you want. 

Cheers,
Robert

dcIMMDate <- function(year, month, ...){
  dcTuple <- function(x){
    lt <- as.POSIXlt(x)
    year <- lt$year + 1900
    month <- lt$mon + 1
    mday <- lt$mday
    wday <- lt$wday
    if(length(x)!=1){
      return(matrix(c(year,month,mday,wday),ncol=4))
    }
    else{
      return(c(year,month,mday,wday))
    }
  }
  dcDatePart <- function(x, part){ 
    parts <- c("year", "month", "mday", "wday")
    if(!class(x)[1] %in% c("Date", "chron", "POSIXt")){
      return(x)
    }
    if(is.character(part)){
      part <- which(parts == part)
    }
    if(length(x) == 1){
      return(dcTuple(x)[part])
    }
    else{
      return(dcTuple(x)[, part])
    }
  }
  dcNthDayOfWeek <- function(x, dow, n){
    m <- dcDatePart(x, "month")
    y <- dcDatePart(x, "year")
    dow1 <- dcDatePart(as.Date(ISOdate(y, m, 1)), "wday")
    return((n -  1) * 7 + (dow - dow1) %% 7 + x)
  }
  x <- as.Date(ISOdate(year, month, 1))
  x <- dcNthDayOfWeek(x, n = 3, dow = 3)
}


> -----Original Message-----
> From: r-sig-finance-bounces at stat.math.ethz.ch
> [mailto:r-sig-finance-bounces at stat.math.ethz.ch]On Behalf Of
> david.fiorino at abnamro.com
> Sent: Wednesday, May 24, 2006 5:04 PM
> To: r-sig-finance at stat.math.ethz.ch
> Subject: [R-sig-Finance] IMM Dates
> 
> 
> 
> Before I reinvent the wheel, does anyone know of functionality that
> calculates the next IMM settlement date given today's date?
> 
> Thanks - David
> --------------------------------------------------------------
> -------------
> This message (including any attachments) is confidential\ ...{{dropped}}



More information about the R-SIG-Finance mailing list