#' @title Historical Constituents
#' @description Get history of index constituents
#'
#' @param index Index ticker - ^GSPC, ^DJI
#'
#' @importFrom tibble tibble
#' @importFrom dplyr mutate select
#' @importFrom lubridate ymd now
#'
#' @return
#' @export
#'
#' @examples
#' historical_constituents('^GSPC')
#' historical_constituents('^DJI')
historical_constituents <- function(index, ...){
url <- finnhub_endpoint('historical_constituents')
df <- retry_get(url,
query = list(token = finnhub_key(),
symbol = index))
df %>%
.[['historicalConstituents']] %>%
dplyr::mutate(index = index,
date = lubridate::ymd(date, tz = finnhub_timezone),
query_date = lubridate::now()) %>%
dplyr::select(index, constituents = symbol, date, action, query_date)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.