Title: | Manipulate Dates for Finance |
---|---|
Description: | Functions to manipulate dates and count days for quantitative finance analysis. The 'quantdates' package considers leap, holidays and business days for relevant calendars in a financial context to simplify quantitative finance calculations, consistent with International Swaps and Derivatives Association (ISDA) (2006) <https://www.isda.org/book/2006-isda-definitions/> regulations. |
Authors: | Julian Chitiva [aut], Diego Jara [aut], Erick Translateur [com], Juan Pablo Bermudez [aut, cre], Quantil S.A.S [aut, cph] |
Maintainer: | Juan Pablo Bermudez <[email protected]> |
License: | GPL-3 |
Version: | 2.0.4 |
Built: | 2025-02-10 04:59:17 UTC |
Source: | https://github.com/quantilma/quantdates |
Function to add a number of business days to a specific date. Currently the function work for returning values between 1990 and 2100.
AddBusinessDays(date = Sys.Date(), numDate, loc = "BOG")
AddBusinessDays(date = Sys.Date(), numDate, loc = "BOG")
date |
Initial date, the default is set to the date returned by Sys.Date(). |
numDate |
Number of dates to be add (positive or negative). |
loc |
String that determines the location for business days. See details. |
loc refers to the location for business days:
NY for New York Stock Exchange Market.
NYGB for New York Government Bonds Market.
LDN for London.
NYLDN for the intersection of business days in New York Stock Exchange and London.
NYGBLDN for the intersection of business days in New York Government Bond and London.
BOG for Bogota.
BOGNY for the intersection of business days in Bogota and New York Stock Exchange.
BOGNYGB for the intersection of business days in Bogota and New York Government Bond.
The output is the final date after adding the number of business dates to the initial date. If the initial date is a non-working date, the result of the function for numDate equal to 0 or 1 is the same.
Diego Jara and Juan Pablo Bermudez
# Date input as Date object AddBusinessDays(date = Sys.Date(),numDate = 15,loc = 'BOG') # Date input as character object AddBusinessDays(date = as.character(Sys.Date()),numDate = 15,loc = 'BOG')
# Date input as Date object AddBusinessDays(date = Sys.Date(),numDate = 15,loc = 'BOG') # Date input as character object AddBusinessDays(date = as.character(Sys.Date()),numDate = 15,loc = 'BOG')
Function to add a number of days, months and years to a specific date.
AddDate(date = Sys.Date(), addDays = 0, addMonths = 0, addYears = 0)
AddDate(date = Sys.Date(), addDays = 0, addMonths = 0, addYears = 0)
date |
Initial date. |
addDays |
If specified, vector number of days to add to the initial date. |
addMonths |
If specified, vector number of months to add to the initial date. |
addYears |
If specified, vector number of years to add to the initial date. |
The output is a vector of final dates after adding the number of days, months and years to the initial date.
Julian Chitiva, Diego Jara and Juan Pablo Bermudez
# Date input as Date object AddDate(date = Sys.Date(),addDays=14,addMonths=2,addYears=3) # Date input as character object AddDate(date = '2019-10-04',addDays=14,addMonths=2,addYears=3) # Date vectors to add to initial date AddDate(Sys.Date(), addDays = c(1,2), addMonths = c(4,5),addYears = c(5,6))
# Date input as Date object AddDate(date = Sys.Date(),addDays=14,addMonths=2,addYears=3) # Date input as character object AddDate(date = '2019-10-04',addDays=14,addMonths=2,addYears=3) # Date vectors to add to initial date AddDate(Sys.Date(), addDays = c(1,2), addMonths = c(4,5),addYears = c(5,6))
Calculate business days for a given location. Currently, data availability goes from 1990 to 2100.
BusinessDays(loc = "BOG", from = NULL, to = NULL)
BusinessDays(loc = "BOG", from = NULL, to = NULL)
loc |
String that determines the location for business days. See details. |
from |
If provided returns available business dates after this date (inclusive). |
to |
If provided returns available business dates until this date (inclusive). |
loc refers to the location for business days:
NYGB for New York Government Bonds Market.
NY for New York Stock Exchange Market.
LDN for London.
NYLDN for the intersection of business days in New York Stock Exchange and London.
NYGBLDN for the intersection of business days in New York Government Bond and London.
BOG for Bogota.
BOGNYGB for the intersection of business days in Bogota and New York Government Bond.
BOGNY for the intersection of business days in Bogota and New York Stock Exchange.
Vector of business days. Data availability from 1990 up to 2100.
Diego Jara, Julian Chitiva and Juan Pablo Bermudez
# Returns all business days available for the location BusinessDays(loc='BOG') # Returns business days within given range for the location and Dates as # character BusinessDays(loc='BOG', from='2020-10-10', to='2020-11-10') # Returns business days within given range for the location and Dates as # Dates BusinessDays(loc='BOG', from=as.Date('2020-10-10'), to='2020-11-10') # Returns all available business days for the location after given # 'from' date as character BusinessDays(loc='BOG', from='2020-10-10')
# Returns all business days available for the location BusinessDays(loc='BOG') # Returns business days within given range for the location and Dates as # character BusinessDays(loc='BOG', from='2020-10-10', to='2020-11-10') # Returns business days within given range for the location and Dates as # Dates BusinessDays(loc='BOG', from=as.Date('2020-10-10'), to='2020-11-10') # Returns all available business days for the location after given # 'from' date as character BusinessDays(loc='BOG', from='2020-10-10')
Function to count the number of years between two dates according to the given convention.
day_count(tfinal, tinitial, convention = "ACT/365")
day_count(tfinal, tinitial, convention = "ACT/365")
tfinal |
Final date. |
tinitial |
Initial date. |
convention |
Character that specifies the convention. See details. |
The convention accepts the following values:
30/360.
Here the dates are in the following format
tfinal = -
-
(YYYY-MM-DD).
tinitial = -
-
(YYYY-MM-DD).
It is important to note that
If then
ACT/365 (Default).
Also known as ACT/365 Fixed.
ACT/360.
ACT/365L.
If February 29 is in the range from Date1 (exclusive) to Date2 (inclusive), then DiY = 366, else DiY = 365.
NL/365.
If February 29 is not in the period then actual number of days between dates is used. Else actual number of days minus 1 is used. Day count basis = 365.
ACT/ACT-ISDA.
ACT/ACT-AFB.
The basic rule is that if February 29 is in the range from Date1 (inclusive) to Date2 (exclusive), then DiY = 366, else DiY = 365.
If the period from Date1 to Date2 is more than one year, the calculation is split into two parts:
The number of complete years, counted back from the last day of the period.
The remaining initial stub, calculated using the basic rule.
Number of years between the specified dates according to the convention.
Julian Chitiva
International Swaps and Derivatives Association - ISDA.
International Swaps and Derivatives Association. (2006). 2006 ISDA definitions. New York, N.Y: International Swaps and Derivatives Association.
#Function accepts Dates as Dates or as characters. day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/365') day_count(tfinal=as.Date('2023-03-08'),tinitial=as.Date('2019-02-28'),convention='ACT/360') day_count(tfinal='2023-03-08',tinitial=as.Date('2019-02-28'),convention='30/360') day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='NL/365') day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/ACT-ISDA') day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/ACT-AFB')
#Function accepts Dates as Dates or as characters. day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/365') day_count(tfinal=as.Date('2023-03-08'),tinitial=as.Date('2019-02-28'),convention='ACT/360') day_count(tfinal='2023-03-08',tinitial=as.Date('2019-02-28'),convention='30/360') day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='NL/365') day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/ACT-ISDA') day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/ACT-AFB')
difftime_business
difftime_business(tfinal, tinitial, wd = wdBOG)
difftime_business(tfinal, tinitial, wd = wdBOG)
tfinal |
Final date, it must be a business day. |
tinitial |
Initial date, it must be a business day. |
wd |
Vector of dates with business days. The default are the business days of Bogota. See details |
wd refers to the business days of a specific location:
wdNYGB for New York Government Bonds Market.
wdNY for New York Stock Exchange Market.
wdLDN for London.
wdBOG for Bogota.
Number of days between the specified dates.
Diego Jara and Juan Pablo Bermudez
Function to count the number of business days between two dates.
#Function accepts Dates as Dates or as characters. difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdBOG) difftime_business(tfinal=as.Date('2023-03-08'),tinitial=as.Date('2019-02-28'),wd=wdBOG) difftime_business(tfinal='2023-03-08',tinitial=as.Date('2019-02-28'),wd=wdLDN) difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdNY) difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdNYGB)
#Function accepts Dates as Dates or as characters. difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdBOG) difftime_business(tfinal=as.Date('2023-03-08'),tinitial=as.Date('2019-02-28'),wd=wdBOG) difftime_business(tfinal='2023-03-08',tinitial=as.Date('2019-02-28'),wd=wdLDN) difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdNY) difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdNYGB)
Function to count the number of days between two dates. Optional parameters to count without the leap-days.
difftime_leap_year(tfinal, tinitial, leapDatesIn = TRUE)
difftime_leap_year(tfinal, tinitial, leapDatesIn = TRUE)
tfinal |
Final date. |
tinitial |
Initial date. |
leapDatesIn |
If TRUE count leap Dates, else exclude from counting. |
Number of days between the specified dates.
Julian Chitiva and Diego Jara
#Function accepts Dates as Dates or as characters. difftime_leap_year(tfinal='2023-03-05',tinitial='2019-02-28',leapDatesIn=TRUE) difftime_leap_year(tfinal=as.Date('2023-03-05'),tinitial=as.Date('2019-02-28'),leapDatesIn=TRUE) difftime_leap_year(tfinal='2023-03-05',tinitial='2019-02-28',leapDatesIn=FALSE) difftime_leap_year(tfinal='2023-03-05',tinitial=as.Date('2019-02-28'),leapDatesIn=FALSE)
#Function accepts Dates as Dates or as characters. difftime_leap_year(tfinal='2023-03-05',tinitial='2019-02-28',leapDatesIn=TRUE) difftime_leap_year(tfinal=as.Date('2023-03-05'),tinitial=as.Date('2019-02-28'),leapDatesIn=TRUE) difftime_leap_year(tfinal='2023-03-05',tinitial='2019-02-28',leapDatesIn=FALSE) difftime_leap_year(tfinal='2023-03-05',tinitial=as.Date('2019-02-28'),leapDatesIn=FALSE)
Bogota (Colombia) holidays dates. The holidays were created using the package bizdays. Dates range between 1990-01-01 and 2100-12-08.
Vector of dates of Bogota holidays
holiDaysBOG
holiDaysBOG
Vector of dates.
Quantil S.A.S
Author Calculations
London (England) holidays dates. The holidays were created using the package bizdays. Dates range between 1990-01-01 and 2100-12-28.
Vector of dates of London holidays
holiDaysLDN
holiDaysLDN
Vector of dates.
Quantil S.A.S
Author Calculations
New York Stock Exchange -United States holidays dates. The holidays were created using the package bizdays. Dates range between 1990-01-01 and 2100-12-24.
Vector of dates of New York Stock Exchange holidays
holiDaysNY
holiDaysNY
Vector of dates.
Quantil S.A.S
Author Calculations
New York Government Bonds -United States holidays dates. The holidays were created using the package bizdays. Dates range between 1990-01-01 and 2100-12-24.
Vector of dates of New York Government Bonds holidays
holiDaysNYGB
holiDaysNYGB
Vector of dates.
Quantil S.A.S
Author Calculations
Returns the last day of a month.
LastDayOfMonth(year, month, date = NULL)
LastDayOfMonth(year, month, date = NULL)
year |
Year as a number. |
month |
Month as a number. |
date |
If provided, uses year and month from this date. It could be date or a string format date YYYY-MM-DD. |
Last day of the month in the current year.
Diego Jara
# Return last day of the month in year LastDayOfMonth(year = 2020, month = 2) # Return last day of the month for the date LastDayOfMonth(date = '2020-02-03')
# Return last day of the month in year LastDayOfMonth(year = 2020, month = 2) # Return last day of the month for the date LastDayOfMonth(date = '2020-02-03')
Takes a date represented by a number in Excel format (origin="1899-12-30") and returns a date in R format.
NumExcel2DateR(date)
NumExcel2DateR(date)
date |
numeric vector. |
date in R.
Diego Jara
For dates with R origin.
Other Number to Date:
NumR2DateR()
NumExcel2DateR(as.numeric(Sys.Date()))
NumExcel2DateR(as.numeric(Sys.Date()))
Takes a date represented by a number in R format (origin="1970-01-01") and returns a date.
NumR2DateR(date)
NumR2DateR(date)
date |
numeric vector. |
date in R.
Diego Jara
For dates with Excel origin.
Other Number to Date:
NumExcel2DateR()
NumR2DateR(as.numeric(Sys.Date()))
NumR2DateR(as.numeric(Sys.Date()))
Bogota (Colombia) business dates. Dates range between 1990-01-02 and 2100-12-31.
Vector of dates of Bogota business days
wdBOG
wdBOG
Vector of dates.
Quantil S.A.S
Author Calculations
London (England) business dates. Dates range between 1990-01-02 and 2100-12-31.
Vector of dates of London business days
wdLDN
wdLDN
Vector of dates.
Quantil S.A.S
Author Calculations
New York (United States) Stock Exchange business dates. Dates range between 1990-01-02 and 2100-12-31.
Vector of dates of New York Stock Exchange (NYSE) business days
wdNY
wdNY
Vector of dates.
Quantil S.A.S
Author Calculations
New York (United States) Government Bonds business dates. Dates range between 1990-01-02 and 2100-12-31.
Vector of dates of New York Government Bonds (NYGB) business days
wdNYGB
wdNYGB
Vector of dates.
Quantil S.A.S
Author Calculations