From 680eda103914219b756e9630315378ae83dbd4f8 Mon Sep 17 00:00:00 2001 From: CJ Yetman Date: Fri, 15 Mar 2024 15:18:01 +0100 Subject: [PATCH] utilize new `pacta.data.preparation::prepare_isin_to_fund_table()` function (#194) - [x] depends on https://github.com/RMI-PACTA/pacta.data.preparation/pull/352 Co-authored-by: CJ Yetman - RMI --- run_pacta_data_preparation.R | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/run_pacta_data_preparation.R b/run_pacta_data_preparation.R index 8f88360..a338ca6 100644 --- a/run_pacta_data_preparation.R +++ b/run_pacta_data_preparation.R @@ -500,35 +500,13 @@ readRDS(file.path(config[["data_prep_outputs_path"]], "fund_data.rds")) %>% logger::log_info("Saving file: \"isin_to_fund_table.rds\".") -isin_to_fund_table <- readRDS(factset_isin_to_fund_table_path) - -# filter out fsyms that have more than 1 row and no fund data -isin_to_fund_table <- - isin_to_fund_table %>% - mutate(has_fund_data = factset_fund_id %in% fund_data$factset_fund_id) %>% - group_by(fsym_id) %>% - mutate(n = n()) %>% - filter(n == 1 | (n > 1 & has_fund_data)) %>% - ungroup() %>% - select(-n, -has_fund_data) - -# filter out fsyms that have more than 1 row and have fund data for both rows -isin_to_fund_table <- - isin_to_fund_table %>% - mutate(has_fund_data = factset_fund_id %in% fund_data$factset_fund_id) %>% - group_by(fsym_id) %>% - mutate(n = n()) %>% - filter(!(all(has_fund_data) & n > 1)) %>% - ungroup() %>% - select(-n, -has_fund_data) - -isin_to_fund_table %>% +pacta.data.preparation::prepare_isin_to_fund_table( + isin_to_fund_table = readRDS(factset_isin_to_fund_table_path), + fund_data = readRDS(file.path(config[["data_prep_outputs_path"]], "fund_data.rds")) +) %>% saveRDS(file.path(config[["data_prep_outputs_path"]], "isin_to_fund_table.rds")) -rm(isin_to_fund_table) -invisible(gc()) - logger::log_info("Fund data prepared.")