bizday: Business Days

View source: R/business.R

bizdayR Documentation

Business Days

Description

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.

Usage

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)

Arguments

d

an object of tind class or an R object coercible to it, dates.

convention

a character value determining date rolling convention, see Details.

calendar

a function determining working days and holidays (see Details) or NULL.

n

an integer vector (for bizday_advance) or integer value (for next_bizdays), numebr of business days.

m

an object of tind class or an R object coercible to it, months.

q

an object of tind class or an R object coercible to it, quarters.

y

an object of tind class or an R object coercible to it, years.

d1

an object of tind class or an R object coercible to it, start dates.

d2

an object of tind class or an R object coercible to it, end dates.

start.incl

a logical value, if TRUE, the starting date is included in computation of the number of business days between two dates (TRUE by default).

end.incl

a logical value, if TRUE, the end date is included in computation of the number of business days between two dates (FALSE by default).

Details

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.

Value

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.

See Also

calendars for examples of calendar functions, daycount_frac for computations of day count fractions / accrual factors.

Examples

# 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)


tind documentation built on Dec. 28, 2025, 1:06 a.m.