create.calendar {bizdays} | R Documentation |
create.calendar
creates calendars and stores them in the calendar register.
create.calendar(name, holidays = integer(0), weekdays = NULL, start.date = NULL, end.date = NULL, adjust.from = adjust.none, adjust.to = adjust.none, financial = TRUE)
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 |
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 |
adjust.to |
is a function to be used with the |
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 |
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
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.
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.
# ANBIMA's calendar (from Brazil) cal <- create.calendar("Brazil/ANBIMA", holidays=holidaysANBIMA, 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')