Joey 1 månad sedan
förälder
incheckning
6cfab6fe1f
2 ändrade filer med 21 tillägg och 4 borttagningar
  1. 19 1
      modules/indicatorCalculator.dos
  2. 2 3
      modules/task_fundPerformance.dos

+ 19 - 1
modules/indicatorCalculator.dos

@@ -78,7 +78,7 @@ def cal_basic_performance(entity_info, ret, trailing_month) {
     if(trailing_month == 'incep') {
 
         // 需要至少6个数才计算标准差、峰度、偏度
-        t0 = SELECT price_date.max() AS price_date, nav, ret,
+        t0 = SELECT price_date.max() AS price_date, nav,  ret,
                     ret.mean() AS arith_mean, (1+ret).prod().pow(1\count(entity_id))-1 AS geom_mean,
                     iif(count(entity_id) > 5, std(ret), null) AS std_dev,
                     iif(count(entity_id) > 5, skew(ret, false), null) AS skewness,
@@ -874,6 +874,24 @@ def cal_indicators(entity_info, benchmarks, end_day, tb_ret, benchmark_ret, risk
     // sorting for correct first() and last() value
     ret = SELECT * FROM tb_ret WHERE end_date <= end_day.month() ORDER BY entity_id, price_date;
 
+    // 有数据缺失时要插入相应的月份
+    tmp_dates = SELECT entity_id, ret.price_date.min() AS first_date, ret.price_date.max() AS last_date FROM ret GROUP BY entity_id;
+
+    all_monthend = temporalSeq(ret.price_date.min(), ret.price_date.max(), 'M');
+    t_all_month = table(all_monthend.month() AS end_date, all_monthend AS price_date);
+    t_entity_all_month = SELECT entity_id, end_date, price_date
+		    			 FROM cj(tmp_dates, t_all_month)
+			             WHERE t_all_month.price_date >= tmp_dates.first_date
+			              AND t_all_month.price_date <= tmp_dates.last_date;
+
+    INSERT INTO ret
+		SELECT entity_id, end_date, price_date, double(NULL) AS nav, 0 AS ret
+		FROM t_entity_all_month
+	    WHERE NOT EXISTS ( SELECT * FROM ret r WHERE r.entity_id = t_entity_all_month.entity_id AND r.end_date = t_entity_all_month.end_date);
+
+	ret.sortBy!(['entity_id', 'price_date']);
+
+
     // 收益、标准差、偏度、峰度、最大回撤、VaR, CVaR、卡玛比率
     rtn = cal_basic_performance(entity_info, ret, month);
 

+ 2 - 3
modules/task_fundPerformance.dos

@@ -98,7 +98,6 @@ def calFundPerformanceTask(entityType, date) {
     i = 0;
     batch_size = 200;
 
-
     do {
 
 	    // 按照 MySQL 建好各表
@@ -113,7 +112,7 @@ def calFundPerformanceTask(entityType, date) {
 	    tb_fund_latest_performance = create_entity_latest_performance();
 
         funds = tb_cal_funds[i : min(tb_cal_funds.size(), i+batch_size)];
-// funds = SELECT * FROM tb_cal_funds WHERE entity_id = 'MF000206S8'
+// funds = SELECT * FROM tb_cal_funds WHERE entity_id = 'IN000002L0'
         if(funds.isVoid() || funds.size() == 0) break;
 
         // 200ms
@@ -122,7 +121,7 @@ def calFundPerformanceTask(entityType, date) {
 
         // 计算月收益 (17s)
         rets = mix_monthly_returns(entityType, fund_info);
-//SELECT * FROM rets WHERE entity_id = 'MF000206S8'
+
         if(!rets.isVoid() && rets.size() > 0) {
 
             // 计算月度指标 (78s)