Learn R Programming

bizdays (version 1.0.16)

create.calendar: Creates calendars

Description

create.calendar creates calendars and stores them in the calendar register.

Usage

create.calendar(
  name,
  holidays = integer(0),
  weekdays = NULL,
  start.date = NULL,
  end.date = NULL,
  adjust.from = adjust.none,
  adjust.to = adjust.none,
  financial = TRUE
)

Arguments

name

calendar's name. This is used to retrieve calendars from register.

holidays

a vector of Dates which contains the holidays

weekdays

a character vector which defines the weekdays to be used as non-working days (defaults to NULL which represents an actual calendar). It accepts: sunday, monday, tuesday, wednesday, thursday, friday, saturday. Defining the weekend as nonworking days is weekdays=c("saturday", "sunday").

start.date

the date which the calendar starts

end.date

the date which the calendar ends

adjust.from

is a function to be used with the bizdays's from argument. That function adjusts the argument if it is a nonworking day according to calendar.

adjust.to

is a function to be used with the bizdays's to argument. See also adjust.from.

financial

is a logical argument that defaults to TRUE. This argument defines the calendar as a financial or a non financial calendar. Financial calendars don't consider the ending business day when counting working days in bizdays. bizdays calls for non financial calendars are greater than financial calendars calls by one day.

Calendars register

Every named calendar is stored in a register so that it can be retrieved by its name (in calendars). bizdays' methods also accept the calendar's name on their cal argument. Given that, naming calendars is strongly recommended.

Details

The arguments start.date and end.date can be set but once they aren't and holidays is set, start.date is defined to min(holidays) and end.date to max(holidays). If holidays isn't set start.date is set to '1970-01-01' and end.date to '2071-01-01'.

weekdays is controversial but it is only a sequence of nonworking weekdays. In the great majority of situations it refers to the weekend but it is also possible defining it differently. weekdays accepts a character sequence with lower case weekdays ( sunday, monday, tuesday, wednesday, thursday, friday, saturday). This argument defaults to NULL because the default intended behavior for create.calendar returns an actual calendar, so calling create.calendar(name="xxx") returns a actual calendar named xxx. (for more calendars see Day Count Convention) To define the weekend as the nonworking weekdays one could simply use weekdays=c("saturday", "sunday").

The arguments adjust.from and adjust.to are used to adjust bizdays' arguments from and to, respectively. These arguments need to be adjusted when nonworking days are provided. The default behavior, setting adjust.from=adjust.previous and adjust.to=adjust.next, works like Excel's function NETWORKDAYS, since that is fairly used by a great number of practitioners.

See Also

calendars, bizdays

Examples

Run this code
# ANBIMA's calendar (from Brazil)
holidays <- as.Date(c(
  "2015-01-01", "2015-02-16", "2015-02-17", "2015-04-03", "2015-04-21",
  "2015-05-01", "2015-06-04", "2015-09-07", "2015-10-12", "2015-11-02",
  "2015-11-15", "2015-12-25", "2016-01-01", "2016-02-08", "2016-02-09",
  "2016-03-25", "2016-04-21", "2016-05-01", "2016-05-26", "2016-09-07",
  "2016-10-12", "2016-11-02", "2016-11-15", "2016-12-25"
))
cal <- create.calendar("ANBIMA",
  holidays = holidays,
  weekdays = c("saturday", "sunday")
)

# ACTUAL calendar
cal <- create.calendar("Actual")

# named calendars can be accessed by its name
create.calendar(name = "Actual")
bizdays("2016-01-01", "2016-03-14", "Actual")

Run the code above in your browser using DataLab