#' 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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.