[R-SIG-Finance] Determine the number of trading days for XETRA or EUREX in a given period

Joachim Breit jbreit at nexgo.de
Tue Jan 3 15:13:16 CET 2012


Thank you, Enrico. I wasn't aware of the RQuantLib functions. Looks good...

Regards,
Joachim

Am 02.01.2012 17:55, schrieb Enrico Schumann:
>
> Hi Joachim,
>
> I don't think you need much experience with R to count the days; but it
> may take some work to tabulate the holidays.
>
> You could do something like this:
>
> start <- as.Date("2012-01-01")
> end <- as.Date("2012-12-31")
>
> ## define a list of holidays
> holidays <- as.Date(c("2012-01-01","2012-12-25"))
>
> ## create date sequence
> allDates <- seq(start, end, by = "day")
>
> ## remove weekends
> dayofweek <- as.POSIXlt(allDates)$wday
> isweekend <- dayofweek==0L | dayofweek==6L
> allDates <- allDates[!isweekend]
>
> ## delete holidays
> allDates <- allDates[-match(holidays, allDates, nomatch = 0L)]
>
> ## count (including 'start' and 'end')
> length(allDates)
>
>
> Quite a lot of this seems already implemented in package RQuantLib. I
> say 'seems' because I do not use these functions, so I cannot guarantee
> that the package gives you what you need. Try this:
>
>
> require("RQuantLib")
> allDates <- seq(start, end, by = "day")
> istradingday <- !isHoliday("Germany/Eurex", allDates)
> length(allDates[istradingday])
>
> ## or ...
> businessDaysBetween(calendar = "Germany/Eurex",
> from = start,
> to = end,
> includeFirst = 1, includeLast = 1)
>
> Regards,
> Enrico
>
>



More information about the R-SIG-Finance mailing list