I have a Date
object in R and would like to add 1 business day to this date. If the result is a holiday, I would like the date to be incremented to the next non-holiday date. Let's assume I mean NYSE holidays. How can I do this?
Example:
mydate = as.Date("2013-12-24")
mydate + 1 #this is a holiday so I want this to roll over to the 26th instead
I might use a combo of
timeDate::nextBizDay()
androll=-Inf
to set up adata.table
lookup calendar, like this:Lubridate will not help you as it does not a notion of business days.
At least two packages do, and they both have a financial bent:
RQuantLib has exchange calendars for many exchanges (but it is a pretty large package)
timeDate also has calendars
Both packages have decent documentation which will permit you to set this up from working examples.
A third option (for simple uses) is to just store a local calendar out a few years and use that.
Edit: Here is a quick RQuantLib example:
It just moves the given day (from argument
dates
) forward to the next biz day.holidayNYSE(year = getRmetricsOptions("currentYear"))
also check outisHoliday
fromtimeDate
package