File: Calendars.Rd

package info (click to toggle)
rquantlib 0.4.17-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,308 kB
  • sloc: cpp: 3,690; sh: 69; makefile: 6; ansic: 4
file content (239 lines) | stat: -rw-r--r-- 10,355 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
\name{Calendars}
\alias{isBusinessDay}
\alias{businessDay}
\alias{isHoliday}
\alias{isWeekend}
\alias{isEndOfMonth}
\alias{getEndOfMonth}
\alias{endOfMonth}
\alias{getHolidayList}
\alias{holidayList}
\alias{getBusinessDayList}
\alias{businessDayList}
\alias{setCalendarContext}
\alias{adjust}
\alias{advance}
\alias{businessDaysBetween}
\alias{dayCount}
\alias{yearFraction}
\alias{setEvaluationDate}
\alias{advanceDate}
\alias{addHolidays}
\alias{removeHolidays}
\alias{calendars}
\title{Calendar functions from QuantLib}
\description{
The \code{isBusinessDay} function evaluates the given dates in the context
of the given calendar, and returns a vector of booleans indicating
business day status. \code{BusinessDay} is also
recognised (but may be deprecated one day).

The \code{isHoliday} function evaluates the given dates in the context
of the given calendar, and returns a vector of booleans indicating
holiday day status.

The \code{isWeekend} function evaluates the given dates in the context
of the given calendar, and returns a vector of booleans indicating
weekend status.

The \code{isEndOfMonth} function evaluates the given dates in the context
of the given calendar, and returns a vector of booleans indicating
end of month status.

The \code{getEndOfMonth} function evaluates the given dates in the context
of the given calendar, and returns a vector that corresponds to the end
of month. \code{endOfMonth} is a deprecated form for this function.

The \code{getHolidayList} function returns the holidays between the
given dates, with an option to exclude weekends.  \code{holidayList} is
a deprecated form for this function. Similarly,
\code{getBusinessDayList} and, for symmetry, \code{businessDayList}
return the list of business days; this always excludes weekends.

The \code{adjust} function evaluates the given dates in the context
of the given calendar, and returns a vector that adjusts each input
dates to the appropriate near business day with respect to the given convention.

The \code{advance} function evaluates the given dates in the context
of the given calendar, and returns a vector that advances the given
dates of the given number of business days and returns the result.
This functions gets called either with both argument \code{n} and
\code{timeUnit}, or with argument \code{period}.

The \code{businessDaysBetween} function evaluates two given dates in the context
of the given calendar, and returns a vector that gives the number of
business day between.

The \code{dayCount} function returns the number of day between two dates
given a day counter, see \link{Enum}.

The \code{yearFraction} function returns year fraction between two dates
given a day counter, see \link{Enum}.

The \code{setCalendarContext} function sets three values to a singleton
instance at the C++ layer.

The \code{setEvaluationDate} function sets the evaluation date used by
the QuantLib pricing engines.

The \code{advanceDate} function advances the given date by the given
number of days in the current calendar instance.

The \code{addHolidays} and \code{removeHolidays} add (and remove)
holidays to (from) the given calendar. Note that this change is
transitory and does not persist the session as all actual calendar
information comes from the QuantLib library that this package is linked
against.

The \code{calendars} vector contains all calendar identifiers.

}
\usage{
isBusinessDay(calendar, dates)
businessDay(calendar="TARGET", dates=Sys.Date())  # deprecated form
isHoliday(calendar, dates)
isWeekend(calendar, dates)
isEndOfMonth(calendar, dates)
getEndOfMonth(calendar, dates)
endOfMonth(calendar="TARGET", dates=Sys.Date())
getHolidayList(calendar, from, to, includeWeekends=FALSE)
holidayList(calendar="TARGET", from=Sys.Date(), to = Sys.Date() + 5,
            includeWeekends=FALSE)
getBusinessDayList(calendar, from, to)
businessDayList(calendar="TARGET", from=Sys.Date(), to = Sys.Date() + 5)
adjust(calendar, dates, bdc = 0L)
advance(calendar="TARGET", dates=Sys.Date(), n, timeUnit, period, bdc = 0, emr =0)
%advance(calendar="TARGET", dates=Sys.Date(), period, bdc = 0, emr =0)
businessDaysBetween(calendar, from, to, includeFirst = TRUE, includeLast = FALSE)
dayCount(startDates, endDates, dayCounters)
yearFraction(startDates, endDates, dayCounters)
setCalendarContext(calendar, fixingDays, settleDate)
setEvaluationDate(evalDate)
addHolidays(calendar, dates)
removeHolidays(calendar, dates)
}
\arguments{
  \item{calendar}{A string identifying one of the supported QuantLib
    calendars, see Details for more}
  \item{dates}{A vector (or scalar) of \code{Date} types.}
  \item{from}{A vector (or scalar) of \code{Date} types.}
  \item{to}{A vector (or scalar) of \code{Date} types.}
  \item{includeWeekends}{boolean that indicates whether the calculation
    should include the weekends. Default = false}
  \item{fixingDays}{An integer for the fixing day period, defaults to 2.}
  \item{settleDate}{A date on which trades settles, defaults to two days
    after the current day.}
  \item{n}{an integer number}
  \item{timeUnit}{A value of 0,1,2,3 that corresponds to Days, Weeks,
    Months, and Year; for more detail, see the QuantLib documentation at
    \url{https://www.quantlib.org//reference/group__datetime.html}}
  \item{period}{See \link{Enum}}
  \item{bdc}{Business day convention. By default, this value is 0 and correspond to Following convention}
  \item{emr}{End Of Month rule, default is false}
  \item{includeFirst}{boolean that indicates whether the calculation
    should include the first day. Default = true}
  \item{includeLast}{Default = false}
  \item{startDates}{A vector of \code{Date} type.}
  \item{endDates}{A vector of \code{Date} type.}
  \item{dayCounters}{A vector of numeric type. See \link{Enum}}
  \item{evalDate}{A single date used for the pricing valuations.}
}
\value{
  A named vector of booleans each of which is true if the corresponding
  date is a business day (or holiday or weekend) in the given calendar.
  The element names are
  the dates (formatted as text in yyyy-mm-dd format).

  For \code{setCalendarContext}, a boolean or NULL in case of error.
}
\details{
  The calendars are coming from QuantLib, and the QuantLib documentation
  should be consulted for details.

  Currently, the following strings are recognised: TARGET (a default
  calendar), Argentina, Australia, Brazil, Canada and Canada/Settlement,
  Canada/TSX, China, CzechRepublic, Denmark, Finland, Germany and
  Germany/FrankfurtStockExchange, Germany/Settlement, Germany/Xetra,
  Germany/Eurex, HongKong, Hungary, Iceland, India, Indonesia, Italy and
  Italy/Settlement, Italy/Exchange, Japan, Mexico, NewZealand, Norway,
  Poland, Russia, SaudiArabia, Singapore, Slovakia, SouthAfrica,
  SouthKorea, SouthKorea/KRX, Sweden, Switzerland, Taiwan, Turkey,
  Ukraine, UnitedKingdom and UnitedKingdom/Settlement,
  UnitedKingdom/Exchange, UnitedKingdom/Metals, UnitedStates and
  UnitedStates/Settlement, UnitedStates/NYSE,
  UnitedStates/GovernmentBond, UnitedStates/NERC and WeekendsOnly.

  (In case of multiples entries per country, the country default is listed
  right after the country itself. Using the shorter form is equivalent.)

}
\references{\url{https://www.quantlib.org/} for details on \code{QuantLib}.}
\author{Dirk Eddelbuettel \email{edd@debian.org} for the \R interface;
  the QuantLib Group for \code{QuantLib}}
\note{The interface might change in future release as \code{QuantLib}
  stabilises its own API.}
\examples{
  dates <- seq(from=as.Date("2009-04-07"), to=as.Date("2009-04-14"), by=1)
  isBusinessDay("UnitedStates", dates)
  isBusinessDay("UnitedStates/Settlement", dates)      ## same as previous
  isBusinessDay("UnitedStates/NYSE", dates)            ## stocks
  isBusinessDay("UnitedStates/GovernmentBond", dates)  ## bonds
  isBusinessDay("UnitedStates/NERC", dates)            ## energy

  isHoliday("UnitedStates", dates)
  isHoliday("UnitedStates/Settlement", dates)      ## same as previous
  isHoliday("UnitedStates/NYSE", dates)            ## stocks
  isHoliday("UnitedStates/GovernmentBond", dates)  ## bonds
  isHoliday("UnitedStates/NERC", dates)            ## energy

  isWeekend("UnitedStates", dates)
  isWeekend("UnitedStates/Settlement", dates)      ## same as previous
  isWeekend("UnitedStates/NYSE", dates)            ## stocks
  isWeekend("UnitedStates/GovernmentBond", dates)  ## bonds
  isWeekend("UnitedStates/NERC", dates)            ## energy

  isEndOfMonth("UnitedStates", dates)
  isEndOfMonth("UnitedStates/Settlement", dates)      ## same as previous
  isEndOfMonth("UnitedStates/NYSE", dates)            ## stocks
  isEndOfMonth("UnitedStates/GovernmentBond", dates)  ## bonds
  isEndOfMonth("UnitedStates/NERC", dates)            ## energy

  getEndOfMonth("UnitedStates", dates)
  getEndOfMonth("UnitedStates/Settlement", dates)      ## same as previous
  getEndOfMonth("UnitedStates/NYSE", dates)            ## stocks
  getEndOfMonth("UnitedStates/GovernmentBond", dates)  ## bonds
  getEndOfMonth("UnitedStates/NERC", dates)            ## energy

  from <- as.Date("2009-04-07")
  to<-as.Date("2009-04-14")
  getHolidayList("UnitedStates", from, to)
  to <- as.Date("2009-10-7")
  getHolidayList("UnitedStates", from, to)

  dates <- seq(from=as.Date("2009-04-07"), to=as.Date("2009-04-14"), by=1)

  adjust("UnitedStates", dates)
  adjust("UnitedStates/Settlement", dates)      ## same as previous
  adjust("UnitedStates/NYSE", dates)            ## stocks
  adjust("UnitedStates/GovernmentBond", dates)  ## bonds
  adjust("UnitedStates/NERC", dates)            ## energy

  advance("UnitedStates", dates, 10, 0)
  advance("UnitedStates/Settlement", dates, 10, 1)      ## same as previous
  advance("UnitedStates/NYSE", dates, 10, 2)            ## stocks
  advance("UnitedStates/GovernmentBond", dates,  10, 3) ## bonds
  advance("UnitedStates/NERC", dates, period = 3)       ## energy

  from <- as.Date("2009-04-07")
  to<-as.Date("2009-04-14")
  businessDaysBetween("UnitedStates", from, to)

  startDates <- seq(from=as.Date("2009-04-07"), to=as.Date("2009-04-14"),by=1)
  endDates <- seq(from=as.Date("2009-11-07"), to=as.Date("2009-11-14"), by=1)
  dayCounters <- c(0,1,2,3,4,5,6,1)
  dayCount(startDates, endDates, dayCounters)
  yearFraction(startDates, endDates, dayCounters)

  head(calendars, 10)
}
\keyword{misc}