R/get_start_dates.R

Defines functions get_start_dates

Documented in get_start_dates

.datatable.aware = TRUE 
if (getRversion() >= '2.15.1') 
  utils::globalVariables(c('.', 'Date', 'out'), utils::packageName()) 

#' @title get_start_dates
#' @description Shows the start dates of all OHLCV series in the 'prices' directory.
#' @return A data table containing a symbol in one column, and the start date of its OHLCV series in the other.
#' @export 
#' @importFrom zoo index
#' @importFrom utils head
#' @importFrom data.table data.table
get_start_dates <- function()
{

  lapply(list.files('prices'), function(x) {
    ohlcv <- readRDS(file.path('prices', x))
    date <- ohlcv %>% zoo::index(out) %>% utils::head(1)
    name <- names(ohlcv)[1] %>% sub(pattern='.Open', replacement='')
    data.table::data.table(name, date)
  }) %>%
    do.call(what = rbind) %>%
    `names<-`(c('Symbol', 'Date')) %>%
    .[order(Date)]

}
causality-loop/updateprices documentation built on Aug. 31, 2022, 5:36 a.m.