Package 'qlcal'

Title: R Bindings to the Calendaring Functionality of 'QuantLib'
Description: 'QuantLib' bindings are provided for R using 'Rcpp' via an evolved version of the initial header-only 'Quantuccia' project offering an subset of 'QuantLib' (now maintained separately just for the calendaring subset). See the included file 'AUTHORS' for a full list of contributors to 'QuantLib' (and hence also 'Quantuccia').
Authors: Dirk Eddelbuettel [aut, cre] , QuantLib Authors [aut]
Maintainer: Dirk Eddelbuettel <[email protected]>
License: GPL (>= 2)
Version: 0.0.12
Built: 2024-10-04 02:43:48 UTC
Source: https://github.com/qlcal/qlcal-r

Help Index


R Bindings to the Calendaring Functionality of 'QuantLib'

Description

'QuantLib' bindings are provided for R using 'Rcpp' via an evolved version of the initial header-only 'Quantuccia' project offering an subset of 'QuantLib' (now maintained separately just for the calendaring subset). See the included file 'AUTHORS' for a full list of contributors to 'QuantLib' (and hence also 'Quantuccia').

Details

The DESCRIPTION file:

Package: qlcal
Type: Package
Title: R Bindings to the Calendaring Functionality of 'QuantLib'
Version: 0.0.12
Date: 2024-07-23
Authors@R: c(person("Dirk", "Eddelbuettel", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0001-6419-907X")), person("QuantLib Authors", role = "aut"))
Description: 'QuantLib' bindings are provided for R using 'Rcpp' via an evolved version of the initial header-only 'Quantuccia' project offering an subset of 'QuantLib' (now maintained separately just for the calendaring subset). See the included file 'AUTHORS' for a full list of contributors to 'QuantLib' (and hence also 'Quantuccia').
URL: https://github.com/qlcal/qlcal-r, https://dirk.eddelbuettel.com/code/qlcal-r.html
BugReports: https://github.com/qlcal/qlcal-r/issues
License: GPL (>= 2)
Imports: Rcpp
LinkingTo: Rcpp, BH
RoxygenNote: 6.0.1
NeedsCompilation: yes
Encoding: UTF-8
Repository: https://qlcal.r-universe.dev
RemoteUrl: https://github.com/qlcal/qlcal-r
RemoteRef: HEAD
RemoteSha: 04121c9180cf3feb6adf53cfbf077e5349c56edf
Author: Dirk Eddelbuettel [aut, cre] (<https://orcid.org/0000-0001-6419-907X>), QuantLib Authors [aut]
Maintainer: Dirk Eddelbuettel <[email protected]>

Package Content

Index of help topics:

adjust_cpp              Compute adjusted dates
advanceDate             Advance a date
advanceUnits_cpp        Compute adjusted dates
businessDaysBetween     Compute number of business dates between
                        calendar dates
calendars               The 'calendars' vector contains all calendar
                        identifiers.
getEndOfMonth           Compute end-of-month
getHolidays             Compute holidays or business days
getName                 Get calendar name, or id
isBusinessDay           Test for business days
isEndOfMonth            Test for end-of-month
isHoliday               Test for holidays
isWeekend               Test for weekends
qlcal-package           R Bindings to the Calendaring Functionality of
                        'QuantLib'
setCalendar             Set a calendar

Maintainer

Dirk Eddelbuettel <[email protected]>

Author(s)

Dirk Eddelbuettel [aut, cre] (<https://orcid.org/0000-0001-6419-907X>), QuantLib Authors [aut]

References

https://www.quantlib.org/


Compute adjusted dates

Description

Adjust a vector of dates following a business-day convention

Usage

adjust_cpp(dates, bdc = 0L)

adjust(dates, bdc = c("Following", "ModifiedFollowing", "Preceding",
  "ModifiedPreceding", "Unadjusted", "HalfMonthModifiedFollowing", "Nearest"))

Arguments

dates

A Date vector with dates

bdc

A character variable describing one of several supported values, the C++ version implements expects a corresponding integer value

Details

This function takes a vector of dates and returns another vector of dates of the same length returning at each position the adjusted date according to the selected business-day convention. Currently supported values for the business day convention are (starting from zero): ‘Following’, ‘ModifiedFollowing’, ‘Preceding’, ‘ModifiedPreceding’, ‘Unadjusted’, ‘HalfModifiedFollowing’ and ‘Nearest’.

Value

A Date vector with dates adjust according to business-day convention

Examples

adjust(Sys.Date()+0:6)

Advance a date

Description

Advance a date to the next business day plus an optional shift

Usage

advanceDate(rd, days = 0L, unit = "Days", bdc = "Following",
  eom = FALSE)

Arguments

rd

A Date object describing the date to be advanced to the next business day.

days

An optional integer offset applied to the date

unit

An optional character value denoting a time unit, default value is “Day”, and supported values are “Days”, “Weeks”, “Months”, “Years”, “Hours”, “Seconds”, “Minutes”, “Milliseconds”, “Microseconds”.

bdc

An optional integer defining a business day convention, default is “Following”, and supported values are “Following”, “ModifiedFollowing”, “Preceding”, “ModifiedPreceding”, “Unadjusted”, “HalfMonthModifiedFollowing” and “Nearest”.

eom

An optional boolean toggle whether end-of-month is to be respected

Details

This function takes a given date and advances it to the next business day under the current (global) calendar setting. If an optional offset value is given it is applied as well.

Value

The advanced date is returned

See Also

The advanceUnits functions offers the same functionality from R.

Examples

advanceDate(Sys.Date(), 2)  # today to the next biz day, plus 2 days

Compute adjusted dates

Description

Advance a vector of dates by a given number of time units

Usage

advanceUnits_cpp(dates, n, unit, bdc, emr)

advanceUnits(dates, n, unit = c("Days", "Weeks", "Months", "Years", "Hours",
  "Minutes", "Seconds", "Milliseconds", "Microseconds"), bdc = c("Following",
  "ModifiedFollowing", "Preceding", "ModifiedPreceding", "Unadjusted",
  "HalfMonthModifiedFollowing", "Nearest"), emr = FALSE)

Arguments

dates

A Date vector with dates

n

An integer variable with the number of units to advance

unit

A character variable describing one of several supported values; the C++ version implements expects a corresponding integer value

bdc

A character variable describing one of several supported values, the C++ version implements expects a corresponding integer value

emr

A boolean variable select end-of-month, default is ‘FALSE’

Details

This function takes a vector of dates and returns another vector of dates of the same length returning at each position the date advanced by the given number of steps in the selected time unit, also respecting a business day convention and and of month boolean switch. Currently supported values for the time unit are ‘Days’, ‘Weeks’, ‘Months’ ‘Years’, ‘Hours’, ‘Seconds’, ‘Milliseconds’ and ‘Microseconds’; all are specified as integers. Note that intra-daily units are not currently supported for advancing ‘Date’ objects. Currently supported values for the business day convention are (starting from zero): ‘Following’, ‘ModifiedFollowing’, ‘Preceding’, ‘ModifiedPreceding’, ‘Unadjusted’, ‘HalfModifiedFollowing’ and ‘Nearest’.

Value

A Date vector with dates advanced according to the selected inputs

Examples

advanceUnits(Sys.Date()+0:6, 5, "Days", "Following")

Compute number of business dates between calendar dates

Description

Compute the number of business days between dates

Usage

businessDaysBetween(from, to, includeFirst = TRUE, includeLast = FALSE)

Arguments

from

A Date vector with interval start dates

to

A Date vector with interval end dates

includeFirst

A boolean indicating if the start date is included, default is ‘TRUE’

includeLast

A boolean indicating if the end date is included, default is ‘FALSE’

Details

This function takes two vectors of start and end dates and returns another vector of the number of business days between each corresponding date pair according to the active calendar.

Value

A numeric vector with the number of business dates between the corresponding date pair

Examples

businessDaysBetween(Sys.Date() + 0:6, Sys.Date() + 3 + 0:6)

The calendars vector contains all calendar identifiers.

Description

The calendars vector contains all calendar identifiers.

Examples

head(calendars, 10)

Compute end-of-month

Description

Compute a vector of dates with end-of-month

Usage

getEndOfMonth(dates)

Arguments

dates

A Date vector with dates

Details

This function takes a vector of dates and returns another vector of dates of the same length returning at each position whether the corresponding end-of-month date in the currently active (global) calendar.

Value

A Date vector with dates which are end-of-month

Examples

getEndOfMonth(Sys.Date()+0:6)

Compute holidays or business days

Description

Compute the number of holidays (or business days) between two dates

Usage

getHolidays(from, to, includeWeekends = FALSE)

getBusinessDays(from, to)

Arguments

from

A Date object with the start date

to

A Date object with the end date

includeWeekends

A boolean indicating if weekends should be included, default is ‘FALSE’

Details

This function takes a start and end date and returns a vector of holidays (or business days) between them according to the active calendar.

Value

A Date vector with holidays or business days between the given dates

Examples

getHolidays(Sys.Date(), Sys.Date() + 30)

Get calendar name, or id

Description

Get calendar name or id

Usage

getName()

getId()

Details

This function returns the corresponding (full) name (as in the underlying implementationclass) or identification string (used to select it) of the current calendar.

Value

A string with the calendar name

Examples

getName()

Test for business days

Description

Test a vector of dates for business day

Usage

isBusinessDay(dates)

Arguments

dates

A Date vector with dates to be examined

Details

This function takes a vector of dates and returns a logical vector of the same length indicating at each position whether the corresponding date is a business day in the currently active (global) calendar.

Value

A logical vector indicating which dates are business days

Examples

isBusinessDay(Sys.Date()+0:6)

Test for end-of-month

Description

Test a vector of dates for end-of-month

Usage

isEndOfMonth(dates)

Arguments

dates

A Date vector with dates to be examined

Details

This function takes a vector of dates and returns a logical vector of the same length indicating at each position whether the corresponding date is at the end of a month in the currently active (global) calendar.

Value

A logical vector indicating which dates are end-of-month

Examples

isEndOfMonth(Sys.Date()+0:6)

Test for holidays

Description

Test a vector of dates for holiday

Usage

isHoliday(dates)

Arguments

dates

A Date vector with dates to be examined

Details

This function takes a vector of dates and returns a logical vector of the same length indicating at each position whether the corresponding date is a holiday in the currently active (global) calendar.

Value

A logical vector indicating which dates are holidays

Examples

isHoliday(Sys.Date()+0:6)

Test for weekends

Description

Test a vector of dates for weekends

Usage

isWeekend(dates)

Arguments

dates

A Date vector with dates to be examined

Details

This function takes a vector of dates and returns a logical vector of the same length indicating at each position whether the corresponding date is a weekend in the currently active (global) calendar.

Value

A logical vector indicating which dates are weekends

Examples

isWeekend(Sys.Date()+0:6)

Set a calendar

Description

Set a calendar

Usage

setCalendar(calstr)

Arguments

calstr

A character variable containing the market for which a calendar is to be set

Details

This function sets a calendar to the given market or country convention. Note that at present only the default ‘TARGET’ and ‘UnitedStates’ are supported.

Value

Nothing is returned but the global state is changed

Examples

setCalendar("UnitedStates")