Calculate the Number of Business Days in Months, Quarters, etc
Source:R/periodic_bizdays.R
periodic_bizdays.RdThis function calculates the number of business days in each periodic interval (e.g., month, quarter) between two dates, using specified QuantLib calendars for holiday definitions.
Arguments
- from, to
start and end dates. Date object or something coercible with
as.Date().- by
periodicity, passed to
seq.Date()(e.g., "month", "quarter", "year"). Seeseq.Date()for more options.- quantlib_calendars
(character) A vector of QuantLib calendar ids (the vector qlcal::calendars lists all valid options).
Value
a tibble with columns:
- calendar
the QuantLib calendar used
- start
the start date of the period
- end
the end date of the period
- business_days
the number of business days in the period, according to the calendar
Examples
periodic_bizdays(
from = as.Date("2023-01-01"),
to = as.Date("2023-12-31"),
by = "month",
quantlib_calendars = c("UnitedStates", "UnitedKingdom")
)
#> # A tibble: 24 × 4
#> calendar start end business_days
#> <chr> <date> <date> <int>
#> 1 UnitedStates 2023-01-01 2023-01-31 20
#> 2 UnitedStates 2023-02-01 2023-02-28 19
#> 3 UnitedStates 2023-03-01 2023-03-31 23
#> 4 UnitedStates 2023-04-01 2023-04-30 20
#> 5 UnitedStates 2023-05-01 2023-05-31 22
#> 6 UnitedStates 2023-06-01 2023-06-30 21
#> 7 UnitedStates 2023-07-01 2023-07-31 20
#> 8 UnitedStates 2023-08-01 2023-08-31 23
#> 9 UnitedStates 2023-09-01 2023-09-30 20
#> 10 UnitedStates 2023-10-01 2023-10-31 21
#> # ℹ 14 more rows