-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
Hi, first of all I want to say that I am big fun of the toolbox.
As per the title of the issue, would it be possible to vectorise the cashflow related functions? I have done a microbenchmark test with another
today <- Sys.Date()
test <- seq(from = 3, to = 50*12, by = 3)
cashflows <- today + months(test)
RQuantLib::yearFraction(today, cashflows, 2)returns [1] 0 ie. only the year_fraction for the first element.
microbenchmark::microbenchmark(
"Rquantlib" = mapply(function(x) RQuantLib::yearFraction(today, x, 2), cashflows),
"fmdates" = fmdates::year_frac(today, cashflows, "act/365")
)The difference is quite material
Unit: microseconds
expr min lq mean median uq max neval
Rquantlib 2863.532 3044.524 3625.3488 3158.520 3390.6060 11575.490 100
fmdates 203.336 229.387 292.9247 304.839 340.7695 488.034 100On the other hand, the RQuantLib::advance function works just much better than the equivalent fmdates one.
microbenchmark::microbenchmark(
"Rquantlib" = mapply(function(x) RQuantLib::advance(dates = today, x, timeUnit = 2, calendar = "TARGET"), test),
"fmdates" = mapply(function(x) fmdates::shift(today, months(x)), test)
)
expr min lq mean median uq max neval
Rquantlib 14.80745 15.37617 18.37219 15.79076 16.54245 123.6318 100
fmdates 1726.72736 1765.48300 1881.30645 1784.04107 1867.18817 3772.2047 100Hence I think that having a vectorised version of the cashflow related functions (advance and yearFraction could be the best of the two worlds.
Metadata
Metadata
Assignees
Labels
No labels