#' @title ETF Industry Exposure
#' @description Get exchange traded industry exposure
#'
#' @param etf ETF ticker - SPY, XLK, IYW
#'
#' @importFrom stringr str_remove_all
#' @importFrom tibble as_tibble
#' @importFrom dplyr mutate select arrange desc
#'
#' @return
#' @export
#'
#' @examples
#' etf_industry_exposure('SPY')
#' etf_industry_exposure('XLK')
#' etf_industry_exposure('IYW')
etf_industry_exposure <- function(etf, ...){
url <- finnhub_endpoint('etfs_industry')
df <- retry_get(url,
query = list(token = finnhub_key(),
symbol = etf))
df %>%
.[['sectorExposure']] %>%
dplyr::mutate(exposure_perc = stringr::str_remove_all(exposure, '%') %>% as.numeric,
exposure_perc = exposure_perc / 100,
etf = etf,
query_date = lubridate::now()) %>%
dplyr::select(etf, industry, exposure_perc, exposure, query_date) %>%
dplyr::arrange(dplyr::desc(exposure_perc))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.