Annual fractions using Actual / 365 in R

Is there any function / package that can calculate the annual share (differences between the two dates) with a different daily account arrangement like yearfrac () in Matlab? I need to use the Actual / 365 agreement.

+6
source share
1 answer
rollYourOwn <- function(D, origin=as.Date("1970-01-01")) { if (!inherits(D, "Date")) D <- as.Date(D, origin=origin) as.numeric(D - as.Date(format(D, "%Y-01-01"), origin=origin) + 1) / 365 } rollYourOwn("2014-01-01") # [1] 0.00273973 rollYourOwn(Sys.Date()) # [1] 0.742466 rollYourOwn("2014-12-31") # [1] 1 
+4
source

Source: https://habr.com/ru/post/975959/


All Articles