|
@@ -73,9 +73,9 @@ def GetEntityNavTask(date) {
|
|
|
* NOTE: 1) 与Java不同的是当月indicator计算每日触发,不必等到Month-end production
|
|
|
* 2) latest performance 尝试用 dolphin 本地数据
|
|
|
*
|
|
|
- * Example: calFundPerformanceTask('HF', 2020.01.23);
|
|
|
- * calFundPerformanceTask('MI', 2020.10.28);
|
|
|
- * calFundPerformanceTask('FI', 2024.10.28);
|
|
|
+ * Example: calFundPerformanceTask('HF', 2025.01.23);
|
|
|
+ * calFundPerformanceTask('MI', 2025.01.23);
|
|
|
+ * calFundPerformanceTask('FI', 2025.01.23);
|
|
|
* calFundPerformanceTask('MF', get_ini_data_const()['date']); -- 【初始化数据专用】(100min)
|
|
|
*/
|
|
|
def calFundPerformanceTask(entityType, date) {
|
|
@@ -158,27 +158,27 @@ def calFundPerformanceTask(entityType, date) {
|
|
|
try {
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_performance, 'fund_id');
|
|
|
- save_and_sync(tb_fund_performance, 'raw_db.fund_performance', 'raw_db.fund_performance');
|
|
|
+ save_and_sync(tb_fund_performance, 'raw_db.fund_performance', 'raw_db.fund_performance', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_indicator, 'fund_id');
|
|
|
- save_and_sync(tb_fund_indicator, 'raw_db.fund_indicator', 'raw_db.fund_indicator');
|
|
|
+ save_and_sync(tb_fund_indicator, 'raw_db.fund_indicator', 'raw_db.fund_indicator', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_risk_stats, 'fund_id');
|
|
|
// mfdb.fund_performance 表中 maxdrawdown_6m & maxdrawdown_ytd 是虚拟列,这里用数据列顺序强行写入真实列 6m_maxdrawdown & ytd_maxdrawdown (DolphinDB 不允许字段名以数字开头)
|
|
|
- save_and_sync(tb_fund_risk_stats, 'raw_db.fund_risk_stats', 'raw_db.fund_risk_stats');
|
|
|
+ save_and_sync(tb_fund_risk_stats, 'raw_db.fund_risk_stats', 'raw_db.fund_risk_stats', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_riskadjret_stats, 'fund_id');
|
|
|
- save_and_sync(tb_fund_riskadjret_stats, 'raw_db.fund_riskadjret_stats', 'raw_db.fund_riskadjret_stats');
|
|
|
+ save_and_sync(tb_fund_riskadjret_stats, 'raw_db.fund_riskadjret_stats', 'raw_db.fund_riskadjret_stats', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_style_stats, 'fund_id');
|
|
|
- save_and_sync(tb_fund_style_stats, 'raw_db.fund_style_stats', 'raw_db.fund_style_stats');
|
|
|
+ save_and_sync(tb_fund_style_stats, 'raw_db.fund_style_stats', 'raw_db.fund_style_stats', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_ms_stats, 'fund_id');
|
|
|
- save_and_sync(tb_fund_ms_stats, 'raw_db.fund_ms_stats', 'mfdb.fund_ms_stats'); // new table, write into directly
|
|
|
+ save_and_sync(tb_fund_ms_stats, 'raw_db.fund_ms_stats', 'mfdb.fund_ms_stats', 'fund_id', 'end_date'); // new table, write into directly
|
|
|
|
|
|
- save_and_sync(tb_fund_performance_weekly, 'raw_db.fund_performance_weekly', 'raw_db.fund_performance_weekly');
|
|
|
+ save_and_sync(tb_fund_performance_weekly, 'raw_db.fund_performance_weekly', 'raw_db.fund_performance_weekly', 'fund_id', 'year_week');
|
|
|
|
|
|
- save_and_sync(tb_fund_latest_performance, 'raw_db.fund_latest_performance', 'raw_db.fund_latest_nav_performance');
|
|
|
+ save_and_sync(tb_fund_latest_performance, 'raw_db.fund_latest_performance', 'raw_db.fund_latest_nav_performance', 'fund_id', 'price_date');
|
|
|
|
|
|
// 数据初始化时将指标存入本地
|
|
|
if(end_day <= get_ini_data_const()['date']) {
|
|
@@ -210,6 +210,68 @@ def calFundPerformanceTask(entityType, date) {
|
|
|
|
|
|
|
|
|
/*
|
|
|
+ * [批量测试]:最新净值触发的周收益计算 (31min)
|
|
|
+ *
|
|
|
+ * @param entityType <STRING>: 'MF', 'HF'...
|
|
|
+ * @param date <DATETIME>: 净值更新时间, 为空时缺省为当前时间-1天;为1989.01.01或更早日期时代表初始化,指标会被存入本地数据库
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * Example: CalEntityWeeklyPerformance('FI', NULL, 2000.01.01);
|
|
|
+ * CalEntityWeeklyPerformance('MF', ['MF00006AGP'], 2020.01.23);
|
|
|
+ *
|
|
|
+ */
|
|
|
+def CalEntityWeeklyPerformance(entityType, entityIds, date) {
|
|
|
+
|
|
|
+ rt = '';
|
|
|
+
|
|
|
+ if(!(entityType IN ['MF', 'HF', 'MI', 'FI'])) return null;
|
|
|
+
|
|
|
+ if(date.isNothing() || date.isNull())
|
|
|
+ end_day = temporalAdd(now(), -1d);
|
|
|
+ else
|
|
|
+ end_day = date;
|
|
|
+
|
|
|
+ // 取有最新净值变动的基金列表 (2.5 min)
|
|
|
+ tb_cal_funds = get_entity_list_by_nav_updatetime(entityType, entityIds, end_day, true);
|
|
|
+
|
|
|
+ if(tb_cal_funds.isVoid() || tb_cal_funds.size() == 0 ) return;
|
|
|
+
|
|
|
+ // 分批跑
|
|
|
+ i = 0;
|
|
|
+ batch_size = 1000;
|
|
|
+
|
|
|
+ do {
|
|
|
+
|
|
|
+ // 按照 MySQL 建好各表
|
|
|
+ tb_fund_performance_weekly = create_entity_performance_weekly();
|
|
|
+
|
|
|
+ funds = tb_cal_funds[i : min(tb_cal_funds.size(), i+batch_size)];
|
|
|
+// funds = SELECT * FROM tb_cal_funds WHERE entity_id = 'MF00004QR9'
|
|
|
+ if(funds.isVoid() || funds.size() == 0) break;
|
|
|
+
|
|
|
+ // 200ms
|
|
|
+ fund_info = SELECT entity_id, price_date, inception_date, benchmark_id, ini_value
|
|
|
+ FROM ej(funds, get_entity_info(entityType, funds.entity_id), 'entity_id');
|
|
|
+
|
|
|
+ // 计算周收益
|
|
|
+ rets_w = cal_weekly_returns(entityType, fund_info);
|
|
|
+//select * from rets_w where entity_id = 'MF00003PW1' and year_week = '200801'
|
|
|
+ if(! rets_w.isVoid() && rets_w.size() > 0) {
|
|
|
+ generate_entity_performance_weekly(fund_info, rets_w, true, tb_fund_performance_weekly);
|
|
|
+
|
|
|
+ save_and_sync(tb_fund_performance_weekly, 'raw_db.fund_performance_weekly', 'raw_db.fund_performance_weekly', 'fund_id', 'year_week');
|
|
|
+ }
|
|
|
+
|
|
|
+ i += batch_size;
|
|
|
+
|
|
|
+ } while (i <= tb_cal_funds.size());
|
|
|
+
|
|
|
+
|
|
|
+ return rt;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
* 【临时】用于数据初始化:只计算收益
|
|
|
*
|
|
|
* @param entityType <STRING>: 'MF', 'HF'...
|
|
@@ -299,24 +361,24 @@ def ms_calFundReturns() {
|
|
|
try {
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_performance, 'fund_id');
|
|
|
- save_and_sync(tb_fund_performance, 'raw_db.fund_performance', 'raw_db.fund_performance');
|
|
|
+ save_and_sync(tb_fund_performance, 'raw_db.fund_performance', 'raw_db.fund_performance', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_indicator, 'fund_id');
|
|
|
- save_and_sync(tb_fund_indicator, 'raw_db.fund_indicator', 'raw_db.fund_indicator');
|
|
|
+ save_and_sync(tb_fund_indicator, 'raw_db.fund_indicator', 'raw_db.fund_indicator', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_risk_stats, 'fund_id');
|
|
|
// mfdb.fund_performance 表中 maxdrawdown_6m & maxdrawdown_ytd 是虚拟列,这里用数据列顺序强行写入真实列 6m_maxdrawdown & ytd_maxdrawdown (DolphinDB 不允许字段名以数字开头)
|
|
|
- save_and_sync(tb_fund_risk_stats, 'raw_db.fund_risk_stats', 'raw_db.fund_risk_stats');
|
|
|
+ save_and_sync(tb_fund_risk_stats, 'raw_db.fund_risk_stats', 'raw_db.fund_risk_stats', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_riskadjret_stats, 'fund_id');
|
|
|
- save_and_sync(tb_fund_riskadjret_stats, 'raw_db.fund_riskadjret_stats', 'raw_db.fund_riskadjret_stats');
|
|
|
+ save_and_sync(tb_fund_riskadjret_stats, 'raw_db.fund_riskadjret_stats', 'raw_db.fund_riskadjret_stats', 'fund_id', 'end_date');
|
|
|
|
|
|
chg_columns_for_mysql(tb_fund_style_stats, 'fund_id');
|
|
|
- save_and_sync(tb_fund_style_stats, 'raw_db.fund_style_stats', 'raw_db.fund_style_stats');
|
|
|
+ save_and_sync(tb_fund_style_stats, 'raw_db.fund_style_stats', 'raw_db.fund_style_stats', 'fund_id', 'end_date');
|
|
|
|
|
|
- save_and_sync(tb_fund_performance_weekly, 'raw_db.fund_performance_weekly', 'raw_db.fund_performance_weekly');
|
|
|
+ save_and_sync(tb_fund_performance_weekly, 'raw_db.fund_performance_weekly', 'raw_db.fund_performance_weekly', 'fund_id', 'year_week');
|
|
|
|
|
|
- save_and_sync(tb_fund_latest_performance, 'raw_db.fund_latest_performance', 'raw_db.fund_latest_nav_performance');
|
|
|
+ save_and_sync(tb_fund_latest_performance, 'raw_db.fund_latest_performance', 'raw_db.fund_latest_nav_performance', 'fund_id', 'price_date');
|
|
|
|
|
|
} catch(ex) {
|
|
|
|