You start by defining a Calendar object.
library(bizdays)
cal <- Calendar(holidaysANBIMA, weekdays=c('sunday', 'saturday'), dib=252)
where holidays is a sequence of dates which represents nonworking dates and the second argument, weekdays, is a sequence with nonworking weekdays, so what Calendar does is define gaps.
holidays is a sequence of Date (or POSIX*) objects and
weekdays must be a sequence of weekdays in words (lowercase).
Once you have instantiated a Calendar object you simply call bizdays function to get the amount of business days between 2 dates (or set of dates).
from_dates <- c('2013-07-12', '2012-06-13')
to_dates <- seq(as.Date('2014-02-17'), as.Date('2016-07-21'), by='months')
bizdays(from_dates, to_dates, cal)
## [1] 153 442 194 483 234 526 276 570 321 613 364 655 404 695
## [15] 446 735 486 779 529 822 571 863 614 904 654 946 695 987
## [29] 738 1029
Why define weekdays?
I am frequently asked Why do I have to define weekdays? or even Shouldn't it be
weekenddaysinstead?.The reason I created
weekdays: I want to provide a way to compute business days accordingly to any definition or satisfying any needs. In my world, the financial industry, weekends are nonworking days, but for those who work with events, for example, mondays migth be nonworking days.
weekdaysdefaults toNULLbecause I wanted theCalendar()call returned an Actual calendar. So callingCalendar(dib=365, name='Actual/365')returns an Actual/365 calendar.