瀏覽代碼

小修小补

Joey 1 周之前
父節點
當前提交
0f875ae83b
共有 1 個文件被更改,包括 9 次插入5 次删除
  1. 9 5
      modules/indicatorCalculator.dos

+ 9 - 5
modules/indicatorCalculator.dos

@@ -881,6 +881,8 @@ 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;
 
+    if(ret.isVoid() || ret.size() == 0) return null;
+
     // 有数据缺失时要插入相应的月份
     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;
 
@@ -889,12 +891,14 @@ def cal_indicators(entity_info, benchmarks, end_day, tb_ret, benchmark_ret, risk
     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;
+			               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);
+	if(t_entity_all_month.size() > 0) {
+	    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']);
 	ret.nav.bfill!();