Description Usage Arguments Details Value Author(s) Source References Examples
View source: R/CountingDates.R
Function to count the number of years between two dates according to the given convention.
1  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.
DayCount = (360*(Y_2Y_1)+30*(M_2M_1) + (D_2D_1))/360
Here the dates are in the following format
tfinal = Y_2M_2D_2 (YYYYMMDD).
tinitial = Y_1M_1D_1 (YYYYMMDD).
It is important to note that
D_1=\min(D_1,30)
If D_1=30 then D_2=\min(D_2,30)
ACT/365 (Default).
DayCount = \frac{Days(tintial, tfinal)}{365}
Also known as ACT/365 Fixed.
ACT/360.
DayCount = \frac{Days(tintial, tfinal)}{365}
ACT/365L.
DayCount = \frac{Days(tintial, tfinal)}{DiY}
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/ACTISDA.
DayCount = \frac{Days\; not\; in\; leap\; year}{365} + \frac{Days\; in\; leap\; year}{366}
ACT/ACTAFB.
DayCount = \frac{Days(tintial, tfinal)}{DiY}
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.
1 2 3 4 5 6 7  #Function accepts Dates as Dates or as characters.
day_count(tfinal='20230308',tinitial='20190228',convention='ACT/365')
day_count(tfinal=as.Date('20230308'),tinitial=as.Date('20190228'),convention='ACT/360')
day_count(tfinal='20230308',tinitial=as.Date('20190228'),convention='30/360')
day_count(tfinal='20230308',tinitial='20190228',convention='NL/365')
day_count(tfinal='20230308',tinitial='20190228',convention='ACT/ACTISDA')
day_count(tfinal='20230308',tinitial='20190228',convention='ACT/ACTAFB')

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.