if (data_loaded && !is.null(history) && !is.null(metadata)) {
avg_vol <- history %>%
group_by(ticker) %>%
summarise(avg_daily_vol = mean(volume, na.rm = TRUE))
if ("isin" %in% colnames(universe) && "isin" %in% colnames(metadata)) {
combined <- universe %>%
inner_join(metadata, by = "isin")
if (!"ticker" %in% names(combined)) {
ticker_cols <- intersect(c("ticker", "ticker.x", "ticker.y", "ticker_meta"), names(combined))
if (length(ticker_cols) > 0) {
combined <- combined %>%
dplyr::mutate(
ticker = dplyr::coalesce(!!!rlang::syms(ticker_cols))
) %>%
dplyr::select(-dplyr::any_of(setdiff(ticker_cols, "ticker")))
}
}
combined <- combined %>%
inner_join(avg_vol, by = "ticker")
if (requireNamespace("stringr", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE)) {
if ("aum_text" %in% names(combined) && any(!is.na(combined$aum_text))) {
combined <- bind_cols(combined, parse_aum(combined$aum_text))
} else {
combined <- combined %>%
dplyr::mutate(
aum_amount = NA_real_,
aum_units = NA_character_,
total_amount = NA_real_
)
}
}
if (requireNamespace("readr", quietly = TRUE) && requireNamespace("stringr", quietly = TRUE)) {
if ("ter_text" %in% names(combined)) {
combined <- combined %>%
mutate(
ter_val = readr::parse_number(ter_text),
ter_units = stringr::str_extract(ter_text, "[%]")
)
} else {
combined <- combined %>%
mutate(
ter_val = NA_real_,
ter_units = NA_character_
)
}
}
cols_to_show <- c("ticker", "name", "currency", "aum_amount", "aum_units", "avg_daily_vol", "ter_val")
cols_to_show <- intersect(cols_to_show, colnames(combined))
knitr::kable(head(combined %>% select(all_of(cols_to_show))))
}
} else {
print("Combined data not available for this build.")
}