| bizday | R Documentation |
bizday computes the nearest business day from the date given
a calendar function and one of the date rolling conventions (see Details).
bizday_advance advances date(s) by n business days.
next_bizdays determines the following n business days after a date.
first_bizday_in_month/quarter and last_bizday_in_month/quarter
determine the first and the last business day in a month and a quarter.
bizdays_in_month, bizdays_in_quarter, and bizdays_in_year
return the number of business days in particular time period.
bizday_diff computes the number of business days between two dates.
bizday(d, convention, calendar)
bizday_advance(d, n = 1L, calendar)
next_bizdays(d, n = 1L, calendar)
first_bizday_in_month(m, calendar)
last_bizday_in_month(m, calendar)
first_bizday_in_quarter(q, calendar)
last_bizday_in_quarter(q, calendar)
bizdays_in_month(m, calendar)
bizdays_in_quarter(q, calendar)
bizdays_in_year(y, calendar)
bizday_diff(d1, d2, calendar, start.incl = TRUE, end.incl = FALSE)
d |
an object of |
convention |
a character value determining date rolling convention, see Details. |
calendar |
a function determining working days and holidays (see Details)
or |
n |
an integer vector (for |
m |
an object of |
q |
an object of |
y |
an object of |
d1 |
an object of |
d2 |
an object of |
start.incl |
a logical value, if |
end.incl |
a logical value, if |
The vectorised implementations of bizday, bizday_advance,
and next_bizdays work under the assumption of at least one business day
in a week and could return NAs for pathological calendar functions.
bizday_advance with increment 0 will adjust the date to the first
preceding business day if it is not a business day (will act as
bizday(d, "p", *)).
next_bizdays accepts negative arguments and returns an increasing
sequence of business dates prior to d of length abs(n).
Conventions
The following date rolling conventions are supported (applied when the day is not a business day):
"p"preceding, the previous business day,
"f"following, the next business day,
"mp"modified preceding, the previous business day unless it falls in the previous month, in which case the next business day is chosen,
"mf"modified following, the next business day unless it falls in the next month, in which case the the previous business day is chosen,
"mf2"modified following bimonthly, the next business day unless it falls in the next month or the next half of the month (after 15th), in which case the the previous business day is chosen.
Calendar Functions
Calendar function should take a vector of days as an argument and return
a logical vector of the same length marking business days (as TRUE)
or a list of two or three logical vectors of the same length with the first
marking business days. See also calendars for real-life
examples of calendar functions. When calendar function is not supplied,
Monday-Friday are marked as business days.
bizday and first/last_bizday_in_month/quarter return
vectors of dates of the same length as their first argument.
bizday_advance returns a vector of dates of length equal to length
of the longer of the first two arguments (d and n).
next_bizdays returns a vector of dates of length abs(n).
bizday_diff and bizdays_in_month/quarter/year return integer
vectors.
calendars for examples of calendar functions,
daycount_frac for computations of day count fractions /
accrual factors.
# a trivial calendar function (Mon-Fri)
monfri <- function(d) (day_of_week(d) <= 5L)
# 2022-10-01 was Saturday
calendar("2022-10", monfri)
(d <- as.date("2022-10-01"))
bizday(d, "p", monfri)
bizday(d, "mp", monfri)
bizday(d, "f", monfri)
bizday(d, "mf", monfri)
bizday(d, "mf2", monfri)
# 2022-10-15 was Saturday again
calendar("2022-10", monfri)
(d <- as.date("2022-10-15"))
bizday(d, "p", monfri)
bizday(d, "mp", monfri)
bizday(d, "f", monfri)
bizday(d, "mf", monfri)
bizday(d, "mf2", monfri)
# 2022-12-31 was also Saturday
calendar("2022-12", monfri)
(d <- as.date("2022-12-31"))
bizday(d, "p", monfri)
bizday(d, "mp", monfri)
bizday(d, "f", monfri)
bizday(d, "mf", monfri)
bizday(d, "mf2", monfri)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.