3

I'm attempting to use the bizdays R package in order to calculate the number of business days in the week excluding weekends and holidays.

Below I have a simple examples that evaluates the number of business days between 12/24/2018 and 12/28/2018 with the 24th and the 25th as holidays.

I would anticipate the bizdays functions to return 3 days (26th, 27th and 28th), however it is returning 2 days.

What confuses me even more is if I call is.bizday for each of the five weekdays within that week I get 3 TRUE and 2 FALSE (what I would expect).

Does anyone have any idea what I'm doing wrong?

If this is working as intended, is there a good work around for getting all days inclusive between two dates?

Code is below:

> library(bizdays)
> 
> holidays<-as.Date(c("2018-12-24", "2018-12-25"))
> 
> calfr<-as.Date("2018-01-01")
> calto<-as.Date("2018-12-31")
> 
> fr<-as.Date("2018-12-24")
> to<-as.Date("2018-12-28")
> 
> 
> cal <- create.calendar('mycal',holidays=holidays, weekdays=c("saturday", "sunday"), start.date = calfr, end.date = calto)
> 
> bizdays(fr,to,cal)
[1] 2
> 
> is.bizday(c('2018-12-24','2018-12-25','2018-12-26','2018-12-27','2018-12-28'), cal)
[1] FALSE FALSE  TRUE  TRUE  TRUE

edit:

I found an answer that does not involve the bizdays package at Calculating Business Days.

I'm leaving the original question up, as the bizdays package has an incredible amount of potential, and i'm still curious as to why it did not work.

Matt
  • 174
  • 1
  • 2
  • 14

1 Answers1

2

You should use the option financial=FALSE inside create.calendar function to add 1 day to every calculation:

cal <- create.calendar('mycal', holidays=holidays, weekdays=c("saturday", "sunday"), start.date = calfr, end.date = calto,
    financial=FALSE)
crestor
  • 1,388
  • 8
  • 21