R/intersect_prices.R

Defines functions intersect_prices

Documented in intersect_prices

#' Return commmon time series
#'
#' @param prices List of price dataframes
#'
#' @return Input dataframes with common time series to all input dataframes
#'
#' @importFrom purrr reduce
#'
#' @examples
intersect_prices <- function(prices) {
  common_idx <- purrr::map(prices, "date_time") %>%
    purrr::reduce(intersect) %>%
    lubridate::as_datetime()

  if (length(common_idx) == 0) warning("No common datetimes found in prices")

  purrr::map(prices, ~ dplyr::filter(., .data$date_time %in% common_idx))
}
zumthor86/OptionsAnalytics documentation built on Oct. 20, 2020, 1:15 p.m.