|
@@ -7,8 +7,8 @@ use fundit::performanceDataPuller
|
|
|
/*
|
|
|
* 通用月收益计算
|
|
|
*
|
|
|
- * @param entity_info <TABLE>: COLUMN NEED entity_id, price_date, inception_date, ini_value
|
|
|
- * @param nav <TABLE>: COLUMN NEED entity_id, price_date, cumulative_nav
|
|
|
+ * @param entity_info <TABLE>: [COLUMNS] entity_id, price_date, inception_date, ini_value
|
|
|
+ * @param nav <TABLE>: [COLUMNS] entity_id, price_date, cumulative_nav
|
|
|
*
|
|
|
*/
|
|
|
def cal_monthly_returns_by_nav(entity_info, mutable nav) {
|
|
@@ -183,7 +183,7 @@ def cal_weekly_returns(entity_type, entity_info){
|
|
|
|
|
|
tb_rets_1w = null;
|
|
|
|
|
|
- if(!(entity_type IN ['HF', 'MF', 'PF', 'MI', 'FI'])) return tb_rets_1w;
|
|
|
+ if(!(entity_type IN ['HF', 'MF', 'PF', 'MI', 'FI', 'FA'])) return tb_rets_1w;
|
|
|
|
|
|
// 将每支证券ID+某个日期转为JSON用于调用sp
|
|
|
s_json = (SELECT entity_id AS sec_id, price_date FROM entity_info).toStdJson();
|
|
@@ -192,8 +192,9 @@ def cal_weekly_returns(entity_type, entity_info){
|
|
|
tb_nav = get_nav_for_return_calculation(entity_type, 'w', s_json);
|
|
|
tb_nav.rename!('sec_id', 'entity_id');
|
|
|
|
|
|
- UPDATE tb_nav SET year_week = price_date.year()$STRING + (price_date.weekOfYear()$STRING).lpad(2, "0");
|
|
|
-
|
|
|
+ UPDATE tb_nav // 当12月31日是周四、五、六时,该周为第52周,所以次年前几天有可能是上一年的第52,53周
|
|
|
+ SET year_week = iif(price_date.weekOfYear() >= 52 && price_date.monthOfYear() == 1, price_date.year()-1, price_date.year())$STRING + (price_date.weekOfYear()$STRING).lpad(2, "0");
|
|
|
+
|
|
|
tb_weekly_nav = SELECT entity_id, year_week, price_date.last() AS price_date, cumulative_nav.last() AS cumulative_nav
|
|
|
FROM tb_nav n
|
|
|
INNER JOIN entity_info ei ON n.entity_id = ei.entity_id
|
|
@@ -391,10 +392,10 @@ def cal_latest_performance(entity_type, entity_info, isFromMySQL) {
|
|
|
FROM tb_last_nav a
|
|
|
INNER JOIN entity_info fi ON a.entity_id = fi.entity_id
|
|
|
|
|
|
- // annulized since reception return
|
|
|
- UPDATE tb_incep SET ret_incep_a = (1 + ret_incep).pow(365.25\(price_date-inception_date)) - 1
|
|
|
+ // annulized since reception return following GIPS rule
|
|
|
+ UPDATE tb_incep SET ret_incep_a = iif((price_date-inception_date)<=365, ret_incep, (1 + ret_incep).pow(365.25\(price_date-inception_date)) - 1)
|
|
|
UPDATE tb_incep SET ret_incep_a_all = ret_incep_a,
|
|
|
- ret_incep_a_gips = iif((price_date-inception_date)<365, ret_incep, ret_incep_a)
|
|
|
+ ret_incep_a_gips = ret_incep_a
|
|
|
|
|
|
// 最大回撤
|
|
|
tb_drawdown_1m = SELECT a.entity_id, max( 1 - b.cumulative_nav \ b.cumulative_nav.cummax() ) AS drawdown_1m
|
|
@@ -424,7 +425,7 @@ def cal_latest_performance(entity_type, entity_info, isFromMySQL) {
|
|
|
ytd.ret_ytd, incep.ret_incep, incep.ret_incep_a, incep.ret_incep_a_all, incep.ret_incep_a_gips,
|
|
|
dd_m1.drawdown_1m AS maxdrawdown_1m, dd_m3.drawdown_3m AS maxdrawdown_3m, dd_y1.drawdown_1y AS maxdrawdown_1y,
|
|
|
dd_incep.drawdown_incep AS maxdrawdown_incep,
|
|
|
- iif(dd_incep.drawdown_incep == 0, null,incep.ret_incep_a \ dd_incep.drawdown_incep) AS calmarratio_incep
|
|
|
+ iif(dd_incep.drawdown_incep.round(4) == 0 || incep.ret_incep_a > 1000, NULL, incep.ret_incep_a \ dd_incep.drawdown_incep) AS calmarratio_incep
|
|
|
FROM tb_last_return a
|
|
|
LEFT JOIN tb_1d d1 ON a.entity_id = d1.entity_id
|
|
|
LEFT JOIN tb_1w w1 ON a.entity_id = w1.entity_id
|