stevecondylios / priceR

Economics and Pricing in R
https://stevecondylios.github.io/priceR/
Other
59 stars 7 forks source link

`make_dates()` generates time segment with same to/from date #16

Closed stevecondylios closed 4 years ago

stevecondylios commented 4 years ago

make_dates() has a bug

This probably occurs when exactly 365 days (and probably exact multiples too) between from and to (note the identical start/end date in api_time_splits()

library(priceR)
library(tidyverse)
library(lubridate)

historical_exchange_rates("AUD", "USD", today() - 365, today())
historical_exchange_rates("AUD", "USD", "2019-07-30", "2020-07-29")

start_date = "2019-07-30"
end_date = "2020-07-29"

api_time_splits <- priceR:::make_dates(start_date, end_date, 365)

#   start_date   end_date
# 1 2019-07-30 2020-07-29
# 2 2020-07-29 2020-07-29

This should instead be

#   start_date   end_date
# 1 2019-07-30 2020-07-28
# 2 2020-07-29 2020-07-29

Note that the row with the same start and end date is fine (the API handles such queries without issue).

The only problem here is the doubling up on the end date of the first time segment ( / start of next time segment)