R/get_stock_prices.R

Defines functions get_stock_prices

#' get_stock_prices
#' @export get_stock_prices
get_stock_prices <- function(ticker, return_format = "tibble", ...) {
  # Get stock prices
  stock_prices_xts <- getSymbols(Symbols = ticker, auto.assign = FALSE, ...)
  # Rename
  names(stock_prices_xts) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")
  # Return in xts format if tibble is not specified
  if (return_format == "tibble") {
    stock_prices <- stock_prices_xts %>%
      fortify.zoo() %>%
      as_tibble() %>%
      rename(Date = Index)
  } else {
    stock_prices <- stock_prices_xts
  }
  stock_prices
}
pereira94/stockanalysis documentation built on Feb. 5, 2021, 12:48 a.m.