|
@@ -1,13 +1,13 @@
|
|
|
module fundit::task_monthlyPerformance
|
|
|
|
|
|
-
|
|
|
+use fundit::sqlUtilities;
|
|
|
use fundit::operationDataPuller;
|
|
|
use fundit::performanceDataPuller;
|
|
|
use fundit::indicatorCalculator;
|
|
|
use fundit::dataSaver;
|
|
|
use fundit::bfiMatcher;
|
|
|
use fundit::rankingCalculator;
|
|
|
-
|
|
|
+use fundit::navCalculator;
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -136,3 +136,127 @@ def CalRelativeRankingTask(entity_type, entity_ids, end_date, isFromMySQL=true)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+/*
|
|
|
+ * 计算基金经理和公司净值(月度)
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+def cal_and_save_mc_nav(entity_type, entity_date, is_save_local) {
|
|
|
+
|
|
|
+ rt = '';
|
|
|
+
|
|
|
+ if(entity_type == 'PL') s_entity_type = 'manager';
|
|
|
+ else if(entity_type == 'CO') s_entity_type = 'company';
|
|
|
+ else return rt;
|
|
|
+
|
|
|
+ if(entity_date.isVoid() || entity_date.size() == 0) return rt;
|
|
|
+
|
|
|
+ // 准备类似MySQL结构的数据表
|
|
|
+ tb_entity_nav = create_entity_fitted_curve();
|
|
|
+
|
|
|
+ // 暂时与 MySQL 保持一致,只计算公募,私募,公私募综合三条时间序列。未来可细化至公、私募+主策略
|
|
|
+ d_curve_type = dict(INT, INT);
|
|
|
+ d_curve_type[1] = 1; // 私募
|
|
|
+ d_curve_type[4] = 2; // 公募
|
|
|
+ d_curve_type[7] = -99; // 公私募综合
|
|
|
+
|
|
|
+ // 分批跑
|
|
|
+ i = 0;
|
|
|
+ batch_size = 1000;
|
|
|
+
|
|
|
+ all_entity_id = entity_date.entity_id.distinct();
|
|
|
+
|
|
|
+ do { // 14 sec
|
|
|
+
|
|
|
+ tb_entity = SELECT * FROM entity_date
|
|
|
+ WHERE entity_id IN all_entity_id[i : min(all_entity_id.size(), i+batch_size)];
|
|
|
+
|
|
|
+ if(tb_entity.isVoid() || tb_entity.size() == 0) break;
|
|
|
+
|
|
|
+ s_json = tb_entity.toStdJson();
|
|
|
+ t_ret = get_mc_monthly_return(s_entity_type, s_json, 0, 1, true);
|
|
|
+
|
|
|
+
|
|
|
+ for(cur in d_curve_type.keys()) {
|
|
|
+
|
|
|
+ tmp = SELECT entity_id, cur AS curve_type, 0 AS strategy, end_date, price_date, ret, incl_cal_cnt
|
|
|
+ FROM t_ret WHERE raise_type = d_curve_type[cur] AND strategy = -99; // 目前只需要全策略
|
|
|
+ // 取净值前值
|
|
|
+ tb_nav = cal_mc_nav_by_return(entity_type, tmp);
|
|
|
+
|
|
|
+ INSERT INTO tb_entity_nav
|
|
|
+ SELECT entity_id, curve_type, strategy, end_date, nav, incl_cal_cnt
|
|
|
+ FROM ej(tb_nav, tmp, ['entity_id', 'curve_type', 'strategy', 'end_date']);
|
|
|
+ }
|
|
|
+
|
|
|
+ i += batch_size;
|
|
|
+
|
|
|
+ } while (i <= all_entity_id.size());
|
|
|
+
|
|
|
+
|
|
|
+ if(! tb_entity_nav.isVoid() && tb_entity_nav.size() > 0) {
|
|
|
+
|
|
|
+ // save data to MySQL (12 sec)
|
|
|
+ try {
|
|
|
+
|
|
|
+ tb_entity_nav.rename!('entity_id', iif(entity_type == 'PL', 'fund_manager_id', 'company_id'));
|
|
|
+ save_and_sync(tb_entity_nav, iif(entity_type == 'PL', 'raw_db.fund_manager_fitted_curve', 'raw_db.company_fitted_curve'), );
|
|
|
+
|
|
|
+ // 数据初始化时将指标存入本地
|
|
|
+ if(is_save_local == true) {
|
|
|
+ save_table(tb_entity_nav, iif(entity_type == 'PL', 'mfdb.fund_manager_fitted_curve', 'mfdb.company_fitted_curve'), false);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch(ex) {
|
|
|
+
|
|
|
+ //TODO: Log errors
|
|
|
+ rt = ex;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return rt;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * [定时任务]: 基金经理月净值计算
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+def CalManagerNavTask(updatetime) {
|
|
|
+//updatetime = 2024.11.05;
|
|
|
+
|
|
|
+ is_save_local = iif(updatetime <= get_ini_data_const()['updatetime'], true, false);
|
|
|
+
|
|
|
+ // 31 sec
|
|
|
+ entity_date = get_manager_list_by_fund_updatetime(updatetime);
|
|
|
+
|
|
|
+ entity_date.rename!('manager_id', 'entity_id');
|
|
|
+
|
|
|
+ cal_and_save_mc_nav('PL', entity_date, is_save_local);
|
|
|
+
|
|
|
+ entity_date = null;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+ * [定时任务]: 基金公司月净值计算
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+def CalCompanyNavTask(updatetime) {
|
|
|
+//updatetime = 2024.11.05;
|
|
|
+
|
|
|
+ is_save_local = iif(updatetime <= get_ini_data_const()['updatetime'], true, false);
|
|
|
+
|
|
|
+ // 31 sec
|
|
|
+ entity_date = get_company_list_by_fund_updatetime(updatetime);
|
|
|
+
|
|
|
+ entity_date.rename!('company_id', 'entity_id');
|
|
|
+
|
|
|
+ cal_and_save_mc_nav('CO', entity_date, is_save_local);
|
|
|
+
|
|
|
+ entity_date = null;
|
|
|
+}
|
|
|
+
|