|
@@ -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);
|
|
|
|