quantdates

Julian Chitiva

2020-06-05

This package is a R library that provides the user to work with dates and days count for financial analysis. It works with business days from New York (US), London (UK) and Bogota (CO). It also implements day counting using common financial conventions such as ACT/360, ACT/365, ACT/ACT and 30/360, among others.

Dates Manipulation

This part implement functions for dates manipulation such as add days (business days) to a date, transform dates between various formats and obtain business days for a given city calendar.

Add Date

AddDate(date = Sys.Date(),addDays=14,addMonths=2,addYears=3)
#> [1] "2023-08-19"
AddDate(date = '2019-10-04',addDays=14,addMonths=2,addYears=3)
#> [1] "2022-12-18"

Add Business Days

AddBusinessDays(date = Sys.Date(),numDate = 15,loc = 'NY')
#> [1] "2020-06-26"
AddBusinessDays(date = '2020-10-03',numDate = 15,loc = 'NY')
#> [1] "2020-10-26"
AddBusinessDays(date = Sys.Date(),numDate = 15,loc = 'BOG')
#> [1] "2020-07-01"
AddBusinessDays(date = Sys.Date(),numDate = 15,loc = 'LDN')
#> [1] "2020-06-26"

Last Day of Month

LastDayOfMonth(year = 2020, month = 2)
#> [1] "2020-02-29"
LastDayOfMonth(year = 2024, month = 5)
#> [1] "2024-05-31"
LastDayOfMonth(date = '2020-02-03')
#> [1] "2020-02-29"

Business Days

BusinessDays(loc='BOG')[2500:2520]
#>  [1] "2021-03-26" "2021-03-29" "2021-03-30" "2021-03-31" "2021-04-05"
#>  [6] "2021-04-06" "2021-04-07" "2021-04-08" "2021-04-09" "2021-04-12"
#> [11] "2021-04-13" "2021-04-14" "2021-04-15" "2021-04-16" "2021-04-19"
#> [16] "2021-04-20" "2021-04-21" "2021-04-22" "2021-04-23" "2021-04-26"
#> [21] "2021-04-27"
BusinessDays(loc='BOG', from='2020-10-10', to='2020-11-10')
#>  [1] "2020-10-13" "2020-10-14" "2020-10-15" "2020-10-16" "2020-10-19"
#>  [6] "2020-10-20" "2020-10-21" "2020-10-22" "2020-10-23" "2020-10-26"
#> [11] "2020-10-27" "2020-10-28" "2020-10-29" "2020-10-30" "2020-11-03"
#> [16] "2020-11-04" "2020-11-05" "2020-11-06" "2020-11-09" "2020-11-10"

Num to Date

NumR2DateR(as.numeric(Sys.Date()))
#> [1] "2020-06-05"
NumExcel2DateR(as.numeric(Sys.Date()))
#> [1] "1950-06-04"

Counting Dates

This section shows the usage of day count functions.

Difftime

difftime_leap_year(tfinal='2023-03-05',tinitial='2019-02-28',leapDatesIn=TRUE)
#> [1] 1466
difftime_leap_year(tfinal=as.Date('2023-03-05'),tinitial=as.Date('2019-02-28'),leapDatesIn=TRUE)
#> [1] 1466
difftime_leap_year(tfinal='2023-03-05',tinitial='2019-02-28',leapDatesIn=FALSE)
#> [1] 1465
difftime_leap_year(tfinal='2023-03-05',tinitial=as.Date('2019-02-28'),leapDatesIn=FALSE)
#> [1] 1465

Difftime in Business Days

difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdBOG)
#> [1] 988
difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdLDN)
#> [1] 1023
difftime_business(tfinal='2023-03-08',tinitial='2019-02-28',wd=wdNY)
#> [1] 1016

Day Count

day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/365')
#> [1] 4.024658
day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/360')
#> [1] 4.080556
day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='30/360')
#> [1] 4.027778
day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='NL/365')
#> [1] 4.021918
day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/ACT-ISDA')
#> [1] 4.024658
day_count(tfinal='2023-03-08',tinitial='2019-02-28',convention='ACT/ACT-AFB')
#> [1] 4.019178