Learn R Programming

bizdays (version 0.2.2)

Calendar: Creates a calendar

Description

The Calendar stores all information necessary to compute business days. This works like a helper class for many of bizdays' methods.

Usage

Calendar(holidays = integer(0), start.date = NULL, end.date = NULL, name = NULL, weekdays = NULL, dib = NULL, adjust.from = adjust.next, adjust.to = adjust.previous)

Arguments

holidays
a vector of Dates which contains the holidays
start.date
the date which the calendar starts
end.date
the date which the calendar ends
name
calendar's name
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, thuesday, wednesday, thursday, friday, saturday. Defining the weekend as nonworking days is weekdays=c("saturday", "sunday").
dib
a single numeric variable which indicates the amount of days within a year (dib stands for days in base).
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.

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, thuesday, wednesday, thursday, friday, saturday). This argument defaults to NULL because the default intended behavior for Calendar returns an actual calendar, so calling Calendar(dib=365) returns a actual/365 calendar and Calendar(dib=360) and actual/360 (for more calendars see Day Count Convention) To define the weekend as the nonworking weekdays one could simply use weekdays=c("saturday", "sunday").

dib reffers to days in base and represents the amount of days within a year. That is necessary for defining Day Count Conventions and for accounting annualized periods (see bizyears).

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.

Calendar doesn't have to be named, but it helps identifying the calendars once many are instantiated. You name a Calendar by setting the argument name.

Examples

Run this code
# holidays has iso-formated dates
data(holidaysANBIMA)
cal <- Calendar(name="ANBIMA", holidays=holidaysANBIMA,
                weekdays=c("saturday", "sunday"), dib=252)
# ACTUAL calendar
cal <- Calendar(name="Actual", dib=365)
# unnamed calendars have NULL names
cal <- Calendar(start.date="1976-07-12", end.date="2013-10-28")
is.null(cal$name) # TRUE

Run the code above in your browser using DataLab