module fundit::task_monthlyPerformance use fundit::dataPuller; use fundit::dataSaver; use fundit::bfiMatcher; use fundit::rankingCalculator; /* * [定时任务] 计算基金一、二级分类排名并存入数据库 * * @param entity_type : 'MF', 'HF' * @param end_date : * @param isFromMySQL : false 时读取dolphin本地的收益及指标表,用于初始化数据 * * * Example: CalEntityRankingTask('MF', 2024.09M, true); */ def CalEntityRankingTask(entity_type, end_date, isFromMySQL=true) { if(!(entity_type in ['MF', 'HF'])) return NULL; entity_info = get_entity_info(entity_type, NULL); v_ranking_tables = cal_indicator_ranking('strategy', entity_type, entity_info, end_date, isFromMySQL); save_ranking_tables(entity_type, v_ranking_tables); } /* * [定时任务] 计算基金BFI排名并存入数据库 * * @param entity_type : 'MF', 'HF' * @param end_date : * @param isFromMySQL : false 时读取dolphin本地的收益及指标表,用于初始化数据 * * * Example: CalEntityBfiRankingTask('MF', 2024.09M, true); */ def CalEntityBfiRankingTask(entity_type, end_date, isFromMySQL=true) { if(!(entity_type in ['MF', 'HF'])) return NULL; entity_info = get_entity_info(entity_type, NULL); v_ranking_tables = cal_indicator_ranking('bfi', entity_type, entity_info, end_date, isFromMySQL); save_ranking_tables(entity_type, v_ranking_tables); } /* * Private Method: 计算相对排名并存入数据库 * * */ def cal_and_save_relative_ranking(entity_type, benchmark_ranking, entity_ranking, ranking_by, isFromMySQL=true) { // benchmark_ranking= tb_fund_ranking t_entity_ranking = entity_ranking; cal_relative_ranking(benchmark_ranking, t_entity_ranking, isFromMySQL); t_entity_ranking.rename!('category_id', iif(ranking_by=='bfi', 'factor_id', ranking_by)); save_relative_ranking_table(entity_type, t_entity_ranking, ranking_by); } /* * * [定时任务] 以公募基金为评级参考,计算组合、私有基金收益及指标排名 * * TODO: customer fund * TODO: 计算单个组合时总耗时1.5min, 大部分时间用来获取Mysql数据 * * Example: CalRelativeRankingTask('PF', NULL, 2024.09M, true); * CalRelativeRankingTask('PF', 143109, 2024.09M, true); */ def CalRelativeRankingTask(entity_type, entity_ids, end_date, isFromMySQL=true) { // entity_type = 'PF' // end_date = 2024.09M // isFromMySQL = true // ranking_by = 'bfi' // entity_ids = 143109 entity_info = get_entity_info(entity_type, entity_ids); if(entity_type == 'PF') entity_info = SELECT * FROM entity_info WHERE portfolio_type IN (1, 2) // 1: 用户组合、2:客户真实组合,忽略客户推荐组合、总览综合等虚拟组合 v_ranking_by = ['strategy', 'substrategy', 'bfi']; // 暂时以公募混合基金为排名参考 for(ranking_by in v_ranking_by) { if(ranking_by == 'strategy') { v_category = EXEC DISTINCT strategy FROM entity_info WHERE strategy IS NOT NULL; tb_fund_ranking = get_fund_indicator_ranking(NULL, end_date, v_category, isFromMySQL); UPDATE tb_fund_ranking SET category_id = strategy$STRING; } else if(ranking_by == 'substrategy') { v_category = EXEC DISTINCT substrategy FROM entity_info WHERE substrategy IS NOT NULL; tb_fund_ranking = get_fund_indicator_substrategy_ranking(NULL, end_date, v_category, isFromMySQL); UPDATE tb_fund_ranking SET category_id = substrategy$STRING; } else if(ranking_by == 'bfi') { if(entity_ids != NULL || entity_ids != '') v_category = EXEC DISTINCT factor_id FROM get_portfolio_bfi_factors(entity_ids, end_date.temporalFormat('yyyy-MM'), end_date.temporalFormat('yyyy-MM')); else v_category = NULL; tb_fund_ranking = get_fund_bfi_bm_indicator_ranking(NULL, end_date, v_category, isFromMySQL); UPDATE tb_fund_ranking SET category_id = factor_id; } if(tb_fund_ranking.isVoid() || tb_fund_ranking.size() == 0) return; entity_ranking = transform_data_for_ranking(entity_type, entity_info, end_date, ranking_by, isFromMySQL); cal_and_save_relative_ranking(entity_type, tb_fund_ranking, entity_ranking, ranking_by, isFromMySQL); } }