Joey hace 4 meses
padre
commit
36c50c8541
Se han modificado 2 ficheros con 22 adiciones y 79 borrados
  1. 9 73
      modules/task_fundPerformance.dos
  2. 13 6
      modules/task_monthlyPerformance.dos

+ 9 - 73
modules/task_fundPerformance.dos

@@ -4,30 +4,32 @@ use fundit::dataPuller;
 use fundit::dataSaver;
 use fundit::returnCalculator;
 use fundit::indicatorCalculator;
-use fundit::bfiMatcher;
-use fundit::rankingCalculator;
+
 
 /*
  *   [定时任务]:最新净值触发的业绩指标计算
  * 
  *   @param entityType <STRING>: 'MF', 'HF'...
- *   @param date <DATETIME>: 净值更新时间, 为空时缺省为当前时间-1天;为1900.01.01或更早日期时代表初始化,指标会被存入本地数据库
+ *   @param date <DATETIME>: 净值更新时间, 为空时缺省为当前时间-1天;为1990.01.01或更早日期时代表初始化,指标会被存入本地数据库
  *   
  *   NOTE: 与Java不同的是当月indicator计算每日触发,不必等到Month-end production
  *   
  *   Example: calFundPerformanceTask('MF', 2024.10.28);
  *            calFundPerformanceTask('MI', 2024.10.28);
  */
-def calFundPerformanceTask(entityType, mutable date) {
+def calFundPerformanceTask(entityType, date) {
 
     rt = '';
 
     if(!(entityType IN ['MF', 'HF', 'MI', 'FI'])) return null;
 
-    if(date.isNothing() || date.isNull()) date = temporalAdd(now(), -1d);
+    if(date.isNothing() || date.isNull())
+    	end_day = temporalAdd(now(), -1d);
+    else
+    	end_day = date;
 
     // 取有最新净值变动的基金列表 (1s)
-    tb_cal_funds = get_entity_list_by_nav_updatetime(entityType, NULL, date, true);
+    tb_cal_funds = get_entity_list_by_nav_updatetime(entityType, NULL, end_day, true);
 
     if(tb_cal_funds.isVoid() || tb_cal_funds.size() == 0 ) return;
 
@@ -120,7 +122,7 @@ def calFundPerformanceTask(entityType, mutable date) {
             save_and_sync(tb_fund_latest_performance, 'raw_db.fund_latest_performance', 'raw_db.fund_latest_nav_performance');
 
             // 数据初始化时将指标存入本地,做排名之用
-            if(date <= 1900.01.01) {
+            if(end_day <= 1990.01.01) {
             	save_table(tb_fund_performance, 'raw_db.fund_performance', false);
             	save_table(tb_fund_indicator, 'raw_db.fund_indicator', false);
             	save_table(tb_fund_risk_stats, 'raw_db.fund_risk_stats', false);
@@ -281,69 +283,3 @@ def calFundIndexCorrelation(entityType, date) {
 
     return coe;
 }
-
-
-/*
- *   计算排名并存入数据库
- * 
- *   @param end_date <MONTH>
- * 
- *   Example: cal_entity_ranking('MF', 2024.09M, true);
- */
-def CalEntityRanking(entity_type, end_date, isFromMySQL) {
-/*
-entity_type = 'MF';
-end_date = 2024.09M;
-isFromMySQL = true;
-*/
-	entity_info = get_entity_info(entity_type, NULL);
-
-	// 收益
-	v_ranking_tables = cal_ret_ranking(entity_type, entity_info, end_date, isFromMySQL);
-    save_ranking_tables(v_ranking_tables);
-
-    // 风险相关的指标
-    v_ranking_tables = cal_risk_ranking(entity_type, entity_info, end_date, isFromMySQL);
-    save_ranking_tables(v_ranking_tables);
-
-    // 风险调整收益指标
-    v_ranking_tables = cal_risk_adj_return_ranking(entity_type, entity_info, end_date, isFromMySQL);
-    save_ranking_tables(v_ranking_tables);
-
-    // 杂项指标
-    v_ranking_tables = cal_other_indicator_ranking(entity_type, entity_info, end_date, isFromMySQL);
-    save_ranking_tables(v_ranking_tables);
-
-/*
-    v_tables = NULL;
-
-    if(entity_type IN ['MF', 'HF', 'MI', 'FI']) {
-    	
-    	v_tables = ['mfdb.fund_performance', 'mfdb.fund_risk_stats', 'mfdb.fund_riskadjret_stats', 'mfdb.fund_indicator', 'mfdb.fund_style_stats'];
-    	
-    } else if(entity_type = 'PF') {
-
-    	v_tables = ['pfdb.pf_portfolio_performance', 'pfdb.pf_portfolio_risk_stats', 'pfdb.pf_portfolio_riskadjret_stats', 'pfdb.pf_portfolio_indicator', 'pfdb.pf_portfolio_style_stats'];
-
-    } else if(entity_type = 'CF') {
-
-    	v_tables = ['pfdb.pf_cus_fund_performance', 'pfdb.pf_cus_fund_risk_stats', 'pfdb.pf_cus_fund_riskadjret_stats', 'pfdb.pf_cus_fund_indicator', 'pfdb.pf_cus_fund_style_stats'];
-
-    } else if(entity_type = 'FA') {
-    	
-    	v_tables = ['pfdb.cm_factor_performance', 'pfdb.cm_factor_risk_stats', 'pfdb.cm_factor_riskadjret_stats', 'pfdb.cm_factor_indicator', 'pfdb.cm_factor_style_stats'];
-
-    } else if(entity_type = 'CI') {
-    	
-    	v_tables = ['pfdb.cm_udf_index_performance', 'pfdb.cm_udf_index_risk_stats', 'pfdb.cm_udf_index_riskadjret_stats', 'pfdb.cm_udf_index_indicator', 'pfdb.cm_udf_index_style_stats'];
-    }
-
-    if(v_tables.isNull()) return null;
-    
-	for(table in v_tables) {
-		
-        tb_data = get_monthly_indicator_data(table, end_date, isFromMySQL);
-        
-	}
-*/
-}

+ 13 - 6
modules/task_monthlyPerformance.dos

@@ -69,19 +69,22 @@ def cal_and_save_relative_ranking(entity_type, benchmark_ranking, entity_ranking
 
 /*
  * 
- *   以公募基金为评级参考,计算组合、私有基金收益及指标排名
+ *   [定时任务] 以公募基金为评级参考,计算组合、私有基金收益及指标排名
  * 
  *   TODO: customer fund
+ *   TODO: 计算单个组合时总耗时1.5min, 大部分时间用来获取Mysql数据
  * 
- *   Example: CalRelativeRanking('PF', 2024.09M, true);
+ *   Example: CalRelativeRankingTask('PF', NULL, 2024.09M, true);
+ *            CalRelativeRankingTask('PF', 143109, 2024.09M, true); 
  */
-def CalRelativeRanking(entity_type, end_date, isFromMySQL=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, NULL);
+	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:客户真实组合,忽略客户推荐组合、总览综合等虚拟组合
@@ -107,7 +110,12 @@ def CalRelativeRanking(entity_type, end_date, isFromMySQL=true) {
     	
     	} else if(ranking_by == 'bfi') {
 
-    		tb_fund_ranking = get_fund_bfi_bm_indicator_ranking(NULL, end_date, NULL, isFromMySQL);
+			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;
 	    }
@@ -119,6 +127,5 @@ def CalRelativeRanking(entity_type, end_date, isFromMySQL=true) {
         cal_and_save_relative_ranking(entity_type, tb_fund_ranking, entity_ranking, ranking_by, isFromMySQL);
 
     }
-//    SELECT * FROM entity_ranking WHERE entity_id = 143109
 	
 }