|
@@ -4,6 +4,39 @@ use fundit::sqlUtilities
|
|
|
use fundit::dataPuller
|
|
|
use fundit::dataSaver
|
|
|
|
|
|
+/*
|
|
|
+ * 汇集所有参与排名的指标信息
|
|
|
+ *
|
|
|
+ */
|
|
|
+def get_indicator_info() {
|
|
|
+
|
|
|
+ ids = [1,
|
|
|
+ 2, 6, 9, 10, 11, 12, 21, 50, 52, 59,
|
|
|
+ 14, 15, 16, 17, 18, 19, 40, 58,
|
|
|
+ 37, 38, 41, 42, 43, 44, 45, 46, 47, 48, 49,
|
|
|
+ 33, 34, 35, 36,
|
|
|
+ 66, 53, 54, 55, 56, 57
|
|
|
+ ];
|
|
|
+
|
|
|
+ names = ['ret',
|
|
|
+ 'maxdrawdown', 'kurtosis', 'skewness', 'stddev', 'alpha', 'beta', 'downsidedev', 'maxdrawdown_months', 'maxdrawdown_recoverymonths', 'winrate',
|
|
|
+ 'kapparatio', 'treynorratio', 'jensen', 'omegaratio', 'sharperatio', 'sortinoratio_MAR', 'calmarratio', 'sortinoratio',
|
|
|
+ 'per_con', 'info_ratio', 'var', 'cvar', 'smddvar', 'smddcvar', 'smdd_lpm1', 'smdd_lpm2', 'smdd_downside_dev', 'tracking_error', 'm2',
|
|
|
+ 'upsidecapture_ret', 'downsidecapture_ret', 'upsidecapture_ratio', 'downsidecapture_ratio',
|
|
|
+ 'stability', 'jc_stddev', 'gzstyle_stddev', 'gzstrategy_stddev', 'zz_stddev', 'zx_stddev'
|
|
|
+ ];
|
|
|
+
|
|
|
+ is_ASCs = [false,
|
|
|
+ true, true, false, true, false, false, true, true, true, false,
|
|
|
+ false, false, false, false, false, false, false, false,
|
|
|
+ false, false, true, true, true, true, true, true, true, true, false,
|
|
|
+ false, false, false, true,
|
|
|
+ true, true, true, true, true, true
|
|
|
+ ];
|
|
|
+
|
|
|
+ return table(names AS name, ids AS id, is_ASCs AS is_ASC);
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
/*
|
|
|
* 计算收益率排名
|
|
@@ -12,6 +45,9 @@ use fundit::dataSaver
|
|
|
*/
|
|
|
def cal_ret_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
|
|
|
+ // 当前只对基金做排名, 其它类型参考基金排名做相对排名
|
|
|
+ if(!(entity_type in ['MF', 'HF'])) return null;
|
|
|
+
|
|
|
table_desc = get_performance_table_description(entity_type);
|
|
|
|
|
|
tb_data = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
@@ -178,162 +214,255 @@ defg perRank(x, is_ASC) {
|
|
|
* @param indicator_name <STRING>: 指标字段名
|
|
|
* @param indicator_id <INT>:指标ID
|
|
|
* @param is_ASC <BOOL>: 是否排正序
|
|
|
- * @param ranking_by <STRING>: 'strategy', 'substrategy', 'factor', 'catavg'
|
|
|
+ * @param ranking_by <STRING>: 'strategy', 'substrategy', 'factor_id', 'catavg'
|
|
|
+ *
|
|
|
+ * TODO: portfolio, cf, manager, company,
|
|
|
+ * TODO: bfi & category
|
|
|
+ *
|
|
|
+ */
|
|
|
+def gen_ranking_sql0(data_table, indicator_table, ranking_by) {
|
|
|
+
|
|
|
+ for(indicator in indicator_table) {
|
|
|
+
|
|
|
+ // 近1月和近3月排名仅对收益有效,为了满足表结构的要求,需要建立几个”假”字段,并用NULL赋值
|
|
|
+ t_tmp = table(1000:0, ['indicator_id', 'indicator_1m', 'absrank_1m', 'perrank_1m',
|
|
|
+ 'indicator_3m', 'absrank_3m', 'perrank_3m'],
|
|
|
+ [INT, DOUBLE, INT, INT, DOUBLE, INT, INT]);
|
|
|
+ INSERT INTO t_tmp VALUES (indicator.id, double(NULL), int(NULL), int(NULL), double(NULL), int(NULL), int(NULL));
|
|
|
+
|
|
|
+ t_ranking = sql(select = (sqlCol('entity_id'), sqlCol('end_date'), sqlCol(ranking_by), sqlCol('indicator_id'),
|
|
|
+ sqlCol('indicator_1m'), sqlCol('absrank_1m'), sqlCol('perrank_1m'),
|
|
|
+ sqlCol('indicator_3m'), sqlCol('absrank_3m'), sqlCol('perrank_3m'),
|
|
|
+ // 与 MySQL 不同,这里统一把近4年和成立以来的排名去掉
|
|
|
+ sqlCol(indicator.name + '_6m',,'indicator_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', rank{, indicator.is_ASC}, 'absrank_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', perRank{, indicator.is_ASC}, 'perrank_6m'),
|
|
|
+ sqlCol(indicator.name + '_1y',,'indicator_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', rank{, indicator.is_ASC}, 'absrank_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', perRank{, indicator.is_ASC}, 'perrank_1y'),
|
|
|
+ sqlCol(indicator.name + '_2y',,'indicator_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', rank{, indicator.is_ASC}, 'absrank_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', perRank{, indicator.is_ASC}, 'perrank_2y'),
|
|
|
+ sqlCol(indicator.name + '_3y',,'indicator_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', rank{, indicator.is_ASC}, 'absrank_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', perRank{, indicator.is_ASC}, 'perrank_3y'),
|
|
|
+ sqlCol(indicator.name + '_5y',,'indicator_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', rank{, indicator.is_ASC}, 'absrank_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', perRank{, indicator.is_ASC}, 'perrank_5y'),
|
|
|
+ sqlCol(indicator.name + '_10y',,'indicator_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', rank{, indicator.is_ASC}, 'absrank_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', perRank{, indicator.is_ASC}, 'perrank_10y'),
|
|
|
+ sqlCol(indicator.name + '_ytd',,'indicator_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', rank{, indicator.is_ASC}, 'absrank_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', perRank{, indicator.is_ASC}, 'perrank_ytd')
|
|
|
+ ),
|
|
|
+ from = cj(data_table, t_tmp),
|
|
|
+ where = <_$ranking_by IS NOT NULL>,
|
|
|
+ groupBy = (sqlCol(ranking_by), sqlCol('end_date')),
|
|
|
+ groupFlag = 0 ).eval(); // context by
|
|
|
+
|
|
|
+
|
|
|
+ // 近1月和近3月排名仅对收益有效,为了满足表结构的要求,需要建立几个”假”字段,并用NULL赋值
|
|
|
+ t_tmp = table(1000:0, ['indicator_id', 'avg_1m', 'avg_1m_cnt', 'perrank_percent_5_1m', 'perrank_percent_10_1m', 'perrank_percent_25_1m',
|
|
|
+ 'perrank_percent_50_1m', 'perrank_percent_75_1m', 'perrank_percent_90_1m', 'perrank_percent_95_1m', 'best_1m', 'worst_1m',
|
|
|
+ 'avg_3m', 'avg_3m_cnt', 'perrank_percent_5_3m', 'perrank_percent_10_3m', 'perrank_percent_25_3m',
|
|
|
+ 'perrank_percent_50_3m', 'perrank_percent_75_3m', 'perrank_percent_90_3m', 'perrank_percent_95_3m', 'best_3m', 'worst_3m'],
|
|
|
+ [INT, DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE,
|
|
|
+ DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
|
|
|
+ DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE,
|
|
|
+ DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
|
|
|
+
|
|
|
+ INSERT INTO t_tmp VALUES (indicator.id, double(NULL), int(NULL), double(NULL), double(NULL), double(NULL),
|
|
|
+ double(NULL), double(NULL), double(NULL), double(NULL), double(NULL), double(NULL),
|
|
|
+ double(NULL), int(NULL), double(NULL), double(NULL), double(NULL),
|
|
|
+ double(NULL), double(NULL), double(NULL), double(NULL), double(NULL), double(NULL));
|
|
|
+
|
|
|
+ t_ranking_num = sql(select = (sqlCol('end_date'), sqlCol(ranking_by), sqlCol('raise_type', mean, 'raise_type'), sqlCol('indicator_id', mean,'indicator_id'),
|
|
|
+ sqlCol('avg_1m', mean, 'avg_1m'), sqlCol('avg_1m_cnt', mean, 'avg_1m_cnt'),
|
|
|
+ sqlCol('perrank_percent_5_1m', mean, 'perrank_percent_5_1m'),
|
|
|
+ sqlCol('perrank_percent_10_1m', mean, 'perrank_percent_10_1m'),
|
|
|
+ sqlCol('perrank_percent_25_1m', mean, 'perrank_percent_25_1m'),
|
|
|
+ sqlCol('perrank_percent_50_1m', mean, 'perrank_percent_50_1m'),
|
|
|
+ sqlCol('perrank_percent_75_1m', mean, 'perrank_percent_75_1m'),
|
|
|
+ sqlCol('perrank_percent_90_1m', mean, 'perrank_percent_90_1m'),
|
|
|
+ sqlCol('perrank_percent_95_1m', mean, 'perrank_percent_95_1m'),
|
|
|
+ sqlCol('best_1m', mean, 'best_1m'), sqlCol('worst_1m', mean, 'worst_1m'),
|
|
|
+ sqlCol('avg_3m', mean, 'avg_3m'), sqlCol('avg_3m_cnt', mean, 'avg_3m_cnt'),
|
|
|
+ sqlCol('perrank_percent_5_3m', mean, 'perrank_percent_5_3m'),
|
|
|
+ sqlCol('perrank_percent_10_3m', mean, 'perrank_percent_10_3m'),
|
|
|
+ sqlCol('perrank_percent_25_3m', mean, 'perrank_percent_25_3m'),
|
|
|
+ sqlCol('perrank_percent_50_3m', mean, 'perrank_percent_50_3m'),
|
|
|
+ sqlCol('perrank_percent_75_3m', mean, 'perrank_percent_75_3m'),
|
|
|
+ sqlCol('perrank_percent_90_3m', mean, 'perrank_percent_90_3m'),
|
|
|
+ sqlCol('perrank_percent_95_3m', mean, 'perrank_percent_95_3m'),
|
|
|
+ sqlCol('best_3m', mean, 'best_3m'), sqlCol('worst_3m', mean, 'worst_3m'),
|
|
|
+ // 与 MySQL 不同,这里统一把近4年和成立以来的排名去掉
|
|
|
+ sqlCol(indicator.name + '_6m', mean, 'avg_6m'), sqlCol(indicator.name + '_6m', count, 'avg_6m_cnt'),
|
|
|
+ sqlCol(indicator.name + '_6m', percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', iif(indicator.is_ASC, min, max), 'best_6m'),
|
|
|
+ sqlCol(indicator.name + '_6m', iif(indicator.is_ASC, max, min), 'worst_6m'),
|
|
|
+ sqlCol(indicator.name + '_1y', mean, 'avg_1y'), sqlCol(indicator.name + '_1y', count, 'avg_1y_cnt'),
|
|
|
+ sqlCol(indicator.name + '_1y', percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', iif(indicator.is_ASC, min, max), 'best_1y'),
|
|
|
+ sqlCol(indicator.name + '_1y', iif(indicator.is_ASC, max, min), 'worst_1y'),
|
|
|
+ sqlCol(indicator.name + '_2y', mean, 'avg_2y'), sqlCol(indicator.name + '_2y', count, 'avg_2y_cnt'),
|
|
|
+ sqlCol(indicator.name + '_2y', percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', iif(indicator.is_ASC, min, max), 'best_2y'),
|
|
|
+ sqlCol(indicator.name + '_2y', iif(indicator.is_ASC, max, min), 'worst_2y'),
|
|
|
+ sqlCol(indicator.name + '_3y', mean, 'avg_3y'), sqlCol(indicator.name + '_3y', count, 'avg_3y_cnt'),
|
|
|
+ sqlCol(indicator.name + '_3y', percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', iif(indicator.is_ASC, min, max), 'best_3y'),
|
|
|
+ sqlCol(indicator.name + '_3y', iif(indicator.is_ASC, max, min), 'worst_3y'),
|
|
|
+ sqlCol(indicator.name + '_5y', mean, 'avg_5y'), sqlCol(indicator.name + '_5y', count, 'avg_5y_cnt'),
|
|
|
+ sqlCol(indicator.name + '_5y', percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', iif(indicator.is_ASC, min, max), 'best_5y'),
|
|
|
+ sqlCol(indicator.name + '_5y', iif(indicator.is_ASC, max, min), 'worst_5y'),
|
|
|
+ sqlCol(indicator.name + '_10y', mean, 'avg_10y'), sqlCol(indicator.name + '_10y', count, 'avg_10y_cnt'),
|
|
|
+ sqlCol(indicator.name + '_10y', percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', iif(indicator.is_ASC, min, max), 'best_10y'),
|
|
|
+ sqlCol(indicator.name + '_10y', iif(indicator.is_ASC, max, min), 'worst_10y'),
|
|
|
+ sqlCol(indicator.name + '_ytd', mean, 'avg_ytd'), sqlCol(indicator.name + '_ytd', count, 'avg_ytd_cnt'),
|
|
|
+ sqlCol(indicator.name + '_ytd', percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', iif(indicator.is_ASC, min, max), 'best_ytd'),
|
|
|
+ sqlCol(indicator.name + '_ytd', iif(indicator.is_ASC, max, min), 'worst_ytd')
|
|
|
+ ),
|
|
|
+ from = cj(data_table, t_tmp),
|
|
|
+ where = <_$ranking_by IS NOT NULL>,
|
|
|
+ groupBy = (sqlCol(ranking_by), sqlCol('end_date')),
|
|
|
+ groupFlag = 1).eval(); // group by
|
|
|
+ }
|
|
|
+
|
|
|
+ return t_ranking, t_ranking_num;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+ * 动态生成用于排序的SQL脚本
|
|
|
+ *
|
|
|
+ * @param indicator_name <STRING>: 指标字段名
|
|
|
+ * @param indicator_id <INT>:指标ID
|
|
|
+ * @param is_ASC <BOOL>: 是否排正序
|
|
|
+ * @param ranking_by <STRING>: 'strategy', 'substrategy', 'factor_id', 'catavg'
|
|
|
*
|
|
|
+ * TODO: portfolio, cf, manager, company,
|
|
|
* TODO: bfi & category
|
|
|
*
|
|
|
*/
|
|
|
-def gen_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, ranking_by) {
|
|
|
-
|
|
|
- // 近1月和近3月排名仅对收益有效,为了满足表结构的要求,需要建立几个”假”字段,并用NULL赋值
|
|
|
- t_tmp = table(1000:0, ['indicator_id', 'indicator_1m', 'absrank_1m', 'perrank_1m',
|
|
|
- 'indicator_3m', 'absrank_3m', 'perrank_3m'],
|
|
|
- [INT, DOUBLE, INT, INT, DOUBLE, INT, INT]);
|
|
|
- INSERT INTO t_tmp VALUES (indicator_id, double(NULL), int(NULL), int(NULL), double(NULL), int(NULL), int(NULL));
|
|
|
-
|
|
|
- // 因为 parseExpr 没法将表 data_table 传入,所以用 sql()
|
|
|
- t_ranking = sql(select = (sqlCol('entity_id'), sqlCol('end_date'), sqlCol(ranking_by), sqlCol('indicator_id'),
|
|
|
- sqlCol('indicator_1m'), sqlCol('absrank_1m'), sqlCol('perrank_1m'),
|
|
|
- sqlCol('indicator_3m'), sqlCol('absrank_3m'), sqlCol('perrank_3m'),
|
|
|
- // 与 MySQL 不同,这里统一把近4年和成立以来的排名去掉
|
|
|
- sqlCol(indicator_name + '_6m',,'indicator_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', rank{, is_ASC}, 'absrank_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', perRank{, is_ASC}, 'perrank_6m'),
|
|
|
- sqlCol(indicator_name + '_1y',,'indicator_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', rank{, is_ASC}, 'absrank_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', perRank{, is_ASC}, 'perrank_1y'),
|
|
|
- sqlCol(indicator_name + '_2y',,'indicator_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', rank{, is_ASC}, 'absrank_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', perRank{, is_ASC}, 'perrank_2y'),
|
|
|
- sqlCol(indicator_name + '_3y',,'indicator_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', rank{, is_ASC}, 'absrank_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', perRank{, is_ASC}, 'perrank_3y'),
|
|
|
- sqlCol(indicator_name + '_5y',,'indicator_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', rank{, is_ASC}, 'absrank_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', perRank{, is_ASC}, 'perrank_5y'),
|
|
|
- sqlCol(indicator_name + '_10y',,'indicator_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', rank{, is_ASC}, 'absrank_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', perRank{, is_ASC}, 'perrank_10y'),
|
|
|
- sqlCol(indicator_name + '_ytd',,'indicator_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', rank{, is_ASC}, 'absrank_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', perRank{, is_ASC}, 'perrank_ytd')
|
|
|
- ),
|
|
|
- from = cj(data_table, t_tmp),
|
|
|
- where = <_$ranking_by IS NOT NULL>,
|
|
|
- groupBy = (sqlCol(ranking_by), sqlCol('end_date')),
|
|
|
- groupFlag = 0 ).eval(); // context by
|
|
|
-
|
|
|
-
|
|
|
- // 近1月和近3月排名仅对收益有效,为了满足表结构的要求,需要建立几个”假”字段,并用NULL赋值
|
|
|
- t_tmp = table(1000:0, ['indicator_id', 'avg_1m', 'avg_1m_cnt', 'perrank_percent_5_1m', 'perrank_percent_10_1m', 'perrank_percent_25_1m',
|
|
|
- 'perrank_percent_50_1m', 'perrank_percent_75_1m', 'perrank_percent_90_1m', 'perrank_percent_95_1m', 'best_1m', 'worst_1m',
|
|
|
- 'avg_3m', 'avg_3m_cnt', 'perrank_percent_5_3m', 'perrank_percent_10_3m', 'perrank_percent_25_3m',
|
|
|
- 'perrank_percent_50_3m', 'perrank_percent_75_3m', 'perrank_percent_90_3m', 'perrank_percent_95_3m', 'best_3m', 'worst_3m'],
|
|
|
- [INT, DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE,
|
|
|
- DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
|
|
|
- DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE,
|
|
|
- DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
|
|
|
-
|
|
|
- INSERT INTO t_tmp VALUES (indicator_id, double(NULL), int(NULL), double(NULL), double(NULL), double(NULL),
|
|
|
- double(NULL), double(NULL), double(NULL), double(NULL), double(NULL), double(NULL),
|
|
|
- double(NULL), int(NULL), double(NULL), double(NULL), double(NULL),
|
|
|
- double(NULL), double(NULL), double(NULL), double(NULL), double(NULL), double(NULL));
|
|
|
-
|
|
|
- t_ranking_num = sql(select = (sqlCol('end_date'), sqlCol(ranking_by), sqlCol('raise_type', mean, 'raise_type'), sqlCol('indicator_id', mean,'indicator_id'),
|
|
|
- sqlCol('avg_1m', mean, 'avg_1m'), sqlCol('avg_1m_cnt', mean, 'avg_1m_cnt'),
|
|
|
- sqlCol('perrank_percent_5_1m', mean, 'perrank_percent_5_1m'),
|
|
|
- sqlCol('perrank_percent_10_1m', mean, 'perrank_percent_10_1m'),
|
|
|
- sqlCol('perrank_percent_25_1m', mean, 'perrank_percent_25_1m'),
|
|
|
- sqlCol('perrank_percent_50_1m', mean, 'perrank_percent_50_1m'),
|
|
|
- sqlCol('perrank_percent_75_1m', mean, 'perrank_percent_75_1m'),
|
|
|
- sqlCol('perrank_percent_90_1m', mean, 'perrank_percent_90_1m'),
|
|
|
- sqlCol('perrank_percent_95_1m', mean, 'perrank_percent_95_1m'),
|
|
|
- sqlCol('best_1m', mean, 'best_1m'), sqlCol('worst_1m', mean, 'worst_1m'),
|
|
|
- sqlCol('avg_3m', mean, 'avg_3m'), sqlCol('avg_3m_cnt', mean, 'avg_3m_cnt'),
|
|
|
- sqlCol('perrank_percent_5_3m', mean, 'perrank_percent_5_3m'),
|
|
|
- sqlCol('perrank_percent_10_3m', mean, 'perrank_percent_10_3m'),
|
|
|
- sqlCol('perrank_percent_25_3m', mean, 'perrank_percent_25_3m'),
|
|
|
- sqlCol('perrank_percent_50_3m', mean, 'perrank_percent_50_3m'),
|
|
|
- sqlCol('perrank_percent_75_3m', mean, 'perrank_percent_75_3m'),
|
|
|
- sqlCol('perrank_percent_90_3m', mean, 'perrank_percent_90_3m'),
|
|
|
- sqlCol('perrank_percent_95_3m', mean, 'perrank_percent_95_3m'),
|
|
|
- sqlCol('best_3m', mean, 'best_3m'), sqlCol('worst_3m', mean, 'worst_3m'),
|
|
|
- // 与 MySQL 不同,这里统一把近4年和成立以来的排名去掉
|
|
|
- sqlCol(indicator_name + '_6m', mean, 'avg_6m'), sqlCol(indicator_name + '_6m', count, 'avg_6m_cnt'),
|
|
|
- sqlCol(indicator_name + '_6m', percentile{, iif(is_ASC, 5, 95)}, 'perrank_percent_5_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', percentile{, iif(is_ASC, 10, 90)}, 'perrank_percent_10_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', percentile{, iif(is_ASC, 25, 75)}, 'perrank_percent_25_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', percentile{, iif(is_ASC, 50, 50)}, 'perrank_percent_50_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', percentile{, iif(is_ASC, 75, 25)}, 'perrank_percent_75_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', percentile{, iif(is_ASC, 90, 10)}, 'perrank_percent_90_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', percentile{, iif(is_ASC, 95, 5)}, 'perrank_percent_95_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', iif(is_ASC, min, max), 'best_6m'),
|
|
|
- sqlCol(indicator_name + '_6m', iif(is_ASC, max, min), 'worst_6m'),
|
|
|
- sqlCol(indicator_name + '_1y', mean, 'avg_1y'), sqlCol(indicator_name + '_1y', count, 'avg_1y_cnt'),
|
|
|
- sqlCol(indicator_name + '_1y', percentile{, iif(is_ASC, 5, 95)}, 'perrank_percent_5_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', percentile{, iif(is_ASC, 10, 90)}, 'perrank_percent_10_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', percentile{, iif(is_ASC, 25, 75)}, 'perrank_percent_25_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', percentile{, iif(is_ASC, 50, 50)}, 'perrank_percent_50_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', percentile{, iif(is_ASC, 75, 25)}, 'perrank_percent_75_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', percentile{, iif(is_ASC, 90, 10)}, 'perrank_percent_90_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', percentile{, iif(is_ASC, 95, 5)}, 'perrank_percent_95_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', iif(is_ASC, min, max), 'best_1y'),
|
|
|
- sqlCol(indicator_name + '_1y', iif(is_ASC, max, min), 'worst_1y'),
|
|
|
- sqlCol(indicator_name + '_2y', mean, 'avg_2y'), sqlCol(indicator_name + '_2y', count, 'avg_2y_cnt'),
|
|
|
- sqlCol(indicator_name + '_2y', percentile{, iif(is_ASC, 5, 95)}, 'perrank_percent_5_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', percentile{, iif(is_ASC, 10, 90)}, 'perrank_percent_10_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', percentile{, iif(is_ASC, 25, 75)}, 'perrank_percent_25_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', percentile{, iif(is_ASC, 50, 50)}, 'perrank_percent_50_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', percentile{, iif(is_ASC, 75, 25)}, 'perrank_percent_75_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', percentile{, iif(is_ASC, 90, 10)}, 'perrank_percent_90_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', percentile{, iif(is_ASC, 95, 5)}, 'perrank_percent_95_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', iif(is_ASC, min, max), 'best_2y'),
|
|
|
- sqlCol(indicator_name + '_2y', iif(is_ASC, max, min), 'worst_2y'),
|
|
|
- sqlCol(indicator_name + '_3y', mean, 'avg_3y'), sqlCol(indicator_name + '_3y', count, 'avg_3y_cnt'),
|
|
|
- sqlCol(indicator_name + '_3y', percentile{, iif(is_ASC, 5, 95)}, 'perrank_percent_5_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', percentile{, iif(is_ASC, 10, 90)}, 'perrank_percent_10_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', percentile{, iif(is_ASC, 25, 75)}, 'perrank_percent_25_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', percentile{, iif(is_ASC, 50, 50)}, 'perrank_percent_50_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', percentile{, iif(is_ASC, 75, 25)}, 'perrank_percent_75_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', percentile{, iif(is_ASC, 90, 10)}, 'perrank_percent_90_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', percentile{, iif(is_ASC, 95, 5)}, 'perrank_percent_95_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', iif(is_ASC, min, max), 'best_3y'),
|
|
|
- sqlCol(indicator_name + '_3y', iif(is_ASC, max, min), 'worst_3y'),
|
|
|
- sqlCol(indicator_name + '_5y', mean, 'avg_5y'), sqlCol(indicator_name + '_5y', count, 'avg_5y_cnt'),
|
|
|
- sqlCol(indicator_name + '_5y', percentile{, iif(is_ASC, 5, 95)}, 'perrank_percent_5_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', percentile{, iif(is_ASC, 10, 90)}, 'perrank_percent_10_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', percentile{, iif(is_ASC, 25, 75)}, 'perrank_percent_25_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', percentile{, iif(is_ASC, 50, 50)}, 'perrank_percent_50_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', percentile{, iif(is_ASC, 75, 25)}, 'perrank_percent_75_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', percentile{, iif(is_ASC, 90, 10)}, 'perrank_percent_90_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', percentile{, iif(is_ASC, 95, 5)}, 'perrank_percent_95_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', iif(is_ASC, min, max), 'best_5y'),
|
|
|
- sqlCol(indicator_name + '_5y', iif(is_ASC, max, min), 'worst_5y'),
|
|
|
- sqlCol(indicator_name + '_10y', mean, 'avg_10y'), sqlCol(indicator_name + '_10y', count, 'avg_10y_cnt'),
|
|
|
- sqlCol(indicator_name + '_10y', percentile{, iif(is_ASC, 5, 95)}, 'perrank_percent_5_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', percentile{, iif(is_ASC, 10, 90)}, 'perrank_percent_10_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', percentile{, iif(is_ASC, 25, 75)}, 'perrank_percent_25_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', percentile{, iif(is_ASC, 50, 50)}, 'perrank_percent_50_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', percentile{, iif(is_ASC, 75, 25)}, 'perrank_percent_75_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', percentile{, iif(is_ASC, 90, 10)}, 'perrank_percent_90_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', percentile{, iif(is_ASC, 95, 5)}, 'perrank_percent_95_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', iif(is_ASC, min, max), 'best_10y'),
|
|
|
- sqlCol(indicator_name + '_10y', iif(is_ASC, max, min), 'worst_10y'),
|
|
|
- sqlCol(indicator_name + '_ytd', mean, 'avg_ytd'), sqlCol(indicator_name + '_ytd', count, 'avg_ytd_cnt'),
|
|
|
- sqlCol(indicator_name + '_ytd', percentile{, iif(is_ASC, 5, 95)}, 'perrank_percent_5_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', percentile{, iif(is_ASC, 10, 90)}, 'perrank_percent_10_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', percentile{, iif(is_ASC, 25, 75)}, 'perrank_percent_25_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', percentile{, iif(is_ASC, 50, 50)}, 'perrank_percent_50_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', percentile{, iif(is_ASC, 75, 25)}, 'perrank_percent_75_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', percentile{, iif(is_ASC, 90, 10)}, 'perrank_percent_90_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', percentile{, iif(is_ASC, 95, 5)}, 'perrank_percent_95_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', iif(is_ASC, min, max), 'best_ytd'),
|
|
|
- sqlCol(indicator_name + '_ytd', iif(is_ASC, max, min), 'worst_ytd')
|
|
|
- ),
|
|
|
- from = cj(data_table, t_tmp),
|
|
|
- where = <_$ranking_by IS NOT NULL>,
|
|
|
- groupBy = (sqlCol(ranking_by), sqlCol('end_date')),
|
|
|
- groupFlag = 1).eval(); // group by
|
|
|
+def gen_ranking_sql(data_table, indicator_table, ranking_by) {
|
|
|
+
|
|
|
+ for(indicator in indicator_table) {
|
|
|
+
|
|
|
+ // 与 MySQL 不同,这里统一把近4年和成立以来的排名去掉
|
|
|
+ if(indicator.id == 1)
|
|
|
+ v_trailing = ['1m', '3m', '6m', '1y', '2y', '3y', '5y', '10y', 'ytd'];
|
|
|
+ else {
|
|
|
+ v_trailing = ['6m', '1y', '2y', '3y', '5y', '10y', 'ytd'];
|
|
|
+ v_missing_trailing = ['1m', '3m'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绝对排名和百分位排名
|
|
|
+ t_ranking = sql(select = (sqlCol(['entity_id', 'end_date', 'category_id']), <indicator.id as indicator_id>,
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing,, 'indicator_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, rank{, indicator.is_ASC}, 'absrank_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, perRank{, indicator.is_ASC}, 'perrank_' + v_trailing)
|
|
|
+ ),
|
|
|
+ from = data_table,
|
|
|
+ where = < category_id IS NOT NULL>,
|
|
|
+ groupBy = sqlCol(['category_id', 'end_date']),
|
|
|
+ groupFlag = 0 ).eval(); // context by
|
|
|
+
|
|
|
+ // 为了满足表结构的要求, 非收益的指标要补上1m和3m的字段,虽然都是NULL
|
|
|
+ if(indicator.id != 1) {
|
|
|
+
|
|
|
+ t_tmp = table(1000:0,
|
|
|
+ ['indicator_' + v_missing_trailing, 'absrank_' + v_missing_trailing, 'perrank_' + v_missing_trailing].flatten(),
|
|
|
+ [take(DOUBLE, v_missing_trailing.size()), take(INT, v_missing_trailing.size()), take(INT, v_missing_trailing.size())].flatten()
|
|
|
+ );
|
|
|
+
|
|
|
+ t_ranking = SELECT * FROM cj(t_ranking, t_tmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 平均值、集合数量、各分位的阈值
|
|
|
+ t_ranking_num = sql(select =(sqlCol(['end_date', 'category_id']),
|
|
|
+ sqlCol('raise_type', mean, 'raise_type'), <indicator.id as indicator_id>,
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, mean, 'avg_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, count, 'avg_' + v_trailing + '_cnt'),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, percentile{, iif(indicator.is_ASC, 5, 95)}, 'perrank_percent_5_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, percentile{, iif(indicator.is_ASC, 10, 90)}, 'perrank_percent_10_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, percentile{, iif(indicator.is_ASC, 25, 75)}, 'perrank_percent_25_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, percentile{, iif(indicator.is_ASC, 50, 50)}, 'perrank_percent_50_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, percentile{, iif(indicator.is_ASC, 75, 25)}, 'perrank_percent_75_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, percentile{, iif(indicator.is_ASC, 90, 10)}, 'perrank_percent_90_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, percentile{, iif(indicator.is_ASC, 95, 5)}, 'perrank_percent_95_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, iif(indicator.is_ASC, min, max), 'best_' + v_trailing),
|
|
|
+ sqlCol(indicator.name + '_' + v_trailing, iif(indicator.is_ASC, max, min), 'worst_' + v_trailing)
|
|
|
+ ),
|
|
|
+ from = data_table,
|
|
|
+ where = < category_id IS NOT NULL>,
|
|
|
+ groupBy = sqlCol(['category_id', 'end_date']),
|
|
|
+ groupFlag = 1).eval(); // group by
|
|
|
+
|
|
|
+ // 为了满足表结构的要求, 非收益的指标要补上1m和3m的字段,虽然都是NULL
|
|
|
+ if(indicator.id != 1) {
|
|
|
+
|
|
|
+ t_tmp = table(1000:0,
|
|
|
+ ['avg_' + v_missing_trailing, 'avg_' + v_missing_trailing + '_cnt', 'perrank_percent_5_' + v_missing_trailing,
|
|
|
+ 'perrank_percent_10_' + v_missing_trailing, 'perrank_percent_25_' + v_missing_trailing,
|
|
|
+ 'perrank_percent_50_' + v_missing_trailing, 'perrank_percent_75_' + v_missing_trailing,
|
|
|
+ 'perrank_percent_90_' + v_missing_trailing, 'perrank_percent_95_' + v_missing_trailing,
|
|
|
+ 'best_' + v_missing_trailing, 'worst_' + v_missing_trailing ].flatten(),
|
|
|
+ [take(DOUBLE, v_missing_trailing.size()), take(INT, v_missing_trailing.size()), take(DOUBLE, v_missing_trailing.size()),
|
|
|
+ take(DOUBLE, v_missing_trailing.size()), take(DOUBLE, v_missing_trailing.size()),
|
|
|
+ take(DOUBLE, v_missing_trailing.size()), take(DOUBLE, v_missing_trailing.size()),
|
|
|
+ take(DOUBLE, v_missing_trailing.size()), take(DOUBLE, v_missing_trailing.size()),
|
|
|
+ take(DOUBLE, v_missing_trailing.size()),take(DOUBLE, v_missing_trailing.size())].flatten()
|
|
|
+ );
|
|
|
+
|
|
|
+ t_ranking = SELECT * FROM cj(t_ranking, t_tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return t_ranking, t_ranking_num;
|
|
|
}
|
|
@@ -343,18 +472,18 @@ def gen_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, ranking_by
|
|
|
*
|
|
|
* NOTE: 没有用 parseExpr 来生成动态脚本的原因是数据表无法传入
|
|
|
*/
|
|
|
-def run_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, mutable v_tables) {
|
|
|
+def run_ranking_sql(data_table, indicator_table, mutable v_tables) {
|
|
|
|
|
|
- tb_strategy_ranking = gen_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, 'strategy')[0];
|
|
|
+ tb_strategy_ranking = gen_ranking_sql(data_table, indicator_table, 'strategy')[0];
|
|
|
v_tables[0].tableInsert(tb_strategy_ranking);
|
|
|
|
|
|
- tb_strategy_ranking_num = gen_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, 'strategy')[1];
|
|
|
+ tb_strategy_ranking_num = gen_ranking_sql(data_table, indicator_table, 'strategy')[1];
|
|
|
v_tables[1].tableInsert(tb_strategy_ranking_num);
|
|
|
|
|
|
- tb_substrategy_ranking = gen_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, 'substrategy')[0];
|
|
|
+ tb_substrategy_ranking = gen_ranking_sql(data_table, indicator_table, 'substrategy')[0];
|
|
|
v_tables[2].tableInsert(tb_substrategy_ranking);
|
|
|
|
|
|
- tb_substrategy_ranking_num = gen_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, 'substrategy')[1];
|
|
|
+ tb_substrategy_ranking_num = gen_ranking_sql(data_table, indicator_table, 'substrategy')[1];
|
|
|
v_tables[3].tableInsert(tb_substrategy_ranking_num);
|
|
|
|
|
|
}
|
|
@@ -366,6 +495,9 @@ def run_ranking_sql(data_table, indicator_name, indicator_id, is_ASC, mutable v_
|
|
|
*/
|
|
|
def cal_risk_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
|
|
|
+ // 当前只对基金做排名, 其它类型参考基金排名做相对排名
|
|
|
+ if(!(entity_type in ['MF', 'HF'])) return null;
|
|
|
+
|
|
|
table_desc = get_risk_stats_table_description(entity_type);
|
|
|
|
|
|
tb_data = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
@@ -385,35 +517,10 @@ def cal_risk_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
|
|
|
v_ranking_tables = [t_s, t_s_num, t_ss, t_ss_num];
|
|
|
|
|
|
- // 最大回撤
|
|
|
- run_ranking_sql(t, 'maxdrawdown', 2, true, v_ranking_tables);
|
|
|
-
|
|
|
- // 峰度
|
|
|
- run_ranking_sql(t, 'kurtosis', 6, true, v_ranking_tables);
|
|
|
+ // 50, 52 dolphin 未计算
|
|
|
+ indicator_table = SELECT * FROM get_indicator_info() WHERE id in [2, 6, 9, 10, 11, 12, 21, 59];
|
|
|
|
|
|
- // 偏度
|
|
|
- run_ranking_sql(t, 'skewness', 9, false, v_ranking_tables);
|
|
|
-
|
|
|
- // 标准差
|
|
|
- run_ranking_sql(t, 'stddev', 10, true, v_ranking_tables);
|
|
|
-
|
|
|
- // Alpha
|
|
|
- run_ranking_sql(t, 'alpha', 11, false, v_ranking_tables);
|
|
|
-
|
|
|
- // Beta
|
|
|
- run_ranking_sql(t, 'beta', 12, false, v_ranking_tables);
|
|
|
-
|
|
|
- // 下行标准差
|
|
|
- run_ranking_sql(t, 'downsidedev', 21, true, v_ranking_tables);
|
|
|
-
|
|
|
- // 月最大回撤 dolphin 未计算
|
|
|
- // run_ranking_sql(t, 'maxdrawdown_months', 50, true, v_ranking_tables);
|
|
|
-
|
|
|
- // 最大回撤修复月份数 dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'maxdrawdown_recoverymonths', 52, true, v_ranking_tables);
|
|
|
-
|
|
|
- // 胜率
|
|
|
- run_ranking_sql(t, 'winrate', 59, false, v_ranking_tables);
|
|
|
+ run_ranking_sql(t, indicator_table, v_ranking_tables);
|
|
|
|
|
|
return v_ranking_tables;
|
|
|
}
|
|
@@ -426,6 +533,9 @@ def cal_risk_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
*/
|
|
|
def cal_risk_adj_return_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
|
|
|
+ // 当前只对基金做排名, 其它类型参考基金排名做相对排名
|
|
|
+ if(!(entity_type in ['MF', 'HF'])) return null;
|
|
|
+
|
|
|
table_desc = get_riskadjret_stats_table_description(entity_type);
|
|
|
|
|
|
tb_data = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
@@ -445,42 +555,64 @@ def cal_risk_adj_return_ranking(entity_type, entity_info, end_date, isFromMySQL)
|
|
|
|
|
|
v_ranking_tables = [t_s, t_s_num, t_ss, t_ss_num];
|
|
|
|
|
|
- // Kappa ratio
|
|
|
- run_ranking_sql(t, 'kapparatio', 14, false, v_ranking_tables);
|
|
|
+ // 19 (MAR Sortino ratio) dolphin 未计算
|
|
|
+ indicator_table = SELECT * FROM get_indicator_info() WHERE id in [14, 15, 16, 17, 18, 40, 58];
|
|
|
|
|
|
- // Treynor ratio
|
|
|
- run_ranking_sql(t, 'treynorratio', 15, false, v_ranking_tables);
|
|
|
+ run_ranking_sql(t, indicator_table, v_ranking_tables);
|
|
|
|
|
|
- // Jensen
|
|
|
- run_ranking_sql(t, 'jensen', 16, false, v_ranking_tables);
|
|
|
+ return v_ranking_tables;
|
|
|
+}
|
|
|
|
|
|
- // Omega ratio
|
|
|
- run_ranking_sql(t, 'omegaratio', 17, false, v_ranking_tables);
|
|
|
|
|
|
- // Sharpe ratio
|
|
|
- run_ranking_sql(t, 'sharperatio', 18, false, v_ranking_tables);
|
|
|
+/*
|
|
|
+ * 计算杂项指标排名
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+def cal_other_indicator_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
+
|
|
|
+ // 当前只对基金做排名, 其它类型参考基金排名做相对排名
|
|
|
+ if(!(entity_type in ['MF', 'HF'])) return null;
|
|
|
|
|
|
- // MAR Sortino ratio dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'sortinoratio_MAR', 19, false, v_ranking_tables);
|
|
|
+ table_desc = get_indicator_table_description(entity_type);
|
|
|
|
|
|
- // Calmar ratio
|
|
|
- run_ranking_sql(t, 'calmarratio', 40, false, v_ranking_tables);
|
|
|
+ tb_data = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
+ sec_id_col = table_desc.sec_id_col[0];
|
|
|
+ tb_data.rename!(sec_id_col, 'entity_id');
|
|
|
|
|
|
- // Sortino ratio
|
|
|
- run_ranking_sql(t, 'sortinoratio', 58, false, v_ranking_tables);
|
|
|
+ t = SELECT *
|
|
|
+ FROM entity_info en
|
|
|
+ INNER JOIN tb_data d ON en.entity_id = d.entity_id
|
|
|
+ WHERE en.strategy IS NOT NULL;
|
|
|
+
|
|
|
+ // 按照 MySQL 字段建表
|
|
|
+ t_s = create_entity_indicator_ranking(false);
|
|
|
+ t_s_num = create_entity_indicator_ranking_num(false);
|
|
|
+ t_ss = create_entity_indicator_substrategy_ranking(false);
|
|
|
+ t_ss_num = create_entity_indicator_substrategy_ranking_num(false);
|
|
|
+
|
|
|
+ v_ranking_tables = [t_s, t_s_num, t_ss, t_ss_num];
|
|
|
+
|
|
|
+ // 37 (per_con), 43, 44, 45, 46, 47 (smdd模型) dolphin 未计算
|
|
|
+ indicator_table = SELECT * FROM get_indicator_info() WHERE id in [38, 41, 42, 48, 49];
|
|
|
+
|
|
|
+ run_ranking_sql(t, indicator_table, v_ranking_tables);
|
|
|
|
|
|
return v_ranking_tables;
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
- * 计算杂项指标排名
|
|
|
+ * 计算上下行指标排名
|
|
|
*
|
|
|
*
|
|
|
*/
|
|
|
-def cal_other_indicator_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
+def cal_capture_style_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
|
|
|
- table_desc = get_indicator_table_description(entity_type);
|
|
|
+ // 当前只对基金做排名, 其它类型参考基金排名做相对排名
|
|
|
+ if(!(entity_type in ['MF', 'HF'])) return null;
|
|
|
+
|
|
|
+ table_desc = get_capture_style_table_description(entity_type);
|
|
|
|
|
|
tb_data = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
sec_id_col = table_desc.sec_id_col[0];
|
|
@@ -499,43 +631,73 @@ def cal_other_indicator_ranking(entity_type, entity_info, end_date, isFromMySQL)
|
|
|
|
|
|
v_ranking_tables = [t_s, t_s_num, t_ss, t_ss_num];
|
|
|
|
|
|
- // 风格一致性 dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'per_con', 37, false, v_ranking_tables);
|
|
|
+ indicator_table = SELECT * FROM get_indicator_info() WHERE id in [33, 34, 35, 36];
|
|
|
|
|
|
- // Information ratio
|
|
|
- run_ranking_sql(t, 'info_ratio', 38, false, v_ranking_tables);
|
|
|
+ run_ranking_sql(t, indicator_table, v_ranking_tables);
|
|
|
|
|
|
- // Value at Risk
|
|
|
- run_ranking_sql(t, 'var', 41, true, v_ranking_tables);
|
|
|
+ return v_ranking_tables;
|
|
|
+}
|
|
|
|
|
|
- // Conditional Value at Risk
|
|
|
- run_ranking_sql(t, 'cvar', 42, true, v_ranking_tables);
|
|
|
|
|
|
- // SMDD 模型下的 VaR dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'smddvar', 43, true, v_ranking_tables);
|
|
|
+/*
|
|
|
+ * 计算BFI指标排名
|
|
|
+ *
|
|
|
+ * TODO: return
|
|
|
+ */
|
|
|
+def cal_bfi_indicator_ranking(entity_type, entity_info, end_date, isFromMySQL) {
|
|
|
|
|
|
- // SMDD 模型下的 CVaR dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'smddcvar', 44, true, v_ranking_tables);
|
|
|
+ // 当前只对基金做排名, 其它类型参考基金排名做相对排名
|
|
|
+ if(!(entity_type in ['MF', 'HF'])) return null;
|
|
|
|
|
|
- // SMDD 模型下的 LPM1 dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'smdd_lpm1', 45, true, v_ranking_tables);
|
|
|
-
|
|
|
- // SMDD 模型下的 LPM2 dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'smdd_lpm2', 46, true, v_ranking_tables);
|
|
|
-
|
|
|
- // SMDD 模型下的下行风险 dolphin 未计算
|
|
|
- //run_ranking_sql(t, 'smdd_downside_dev', 47, true, v_ranking_tables);
|
|
|
+ table_desc = get_bfi_indicator_table_description(entity_type);
|
|
|
+ sec_id_col = table_desc.sec_id_col[0];
|
|
|
+ tb_data_bfi_indicator = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
+ tb_data_bfi_indicator.rename!(sec_id_col, 'entity_id');
|
|
|
+
|
|
|
+ table_desc = get_risk_stats_table_description(entity_type);
|
|
|
+ sec_id_col = table_desc.sec_id_col[0];
|
|
|
+ tb_data_risk_stats = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
+ tb_data_risk_stats.rename!(sec_id_col, 'entity_id');
|
|
|
+
|
|
|
+ table_desc = get_riskadjret_stats_table_description(entity_type);
|
|
|
+ sec_id_col = table_desc.sec_id_col[0];
|
|
|
+ tb_data_riskadjret_stats = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
+ tb_data_riskadjret_stats.rename!(sec_id_col, 'entity_id');
|
|
|
+
|
|
|
+ table_desc = get_indicator_table_description(entity_type);
|
|
|
+ sec_id_col = table_desc.sec_id_col[0];
|
|
|
+ tb_data_indicator_stats = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
+ tb_data_indicator_stats.rename!(sec_id_col, 'entity_id');
|
|
|
+
|
|
|
+ t = SELECT *
|
|
|
+ FROM entity_info en
|
|
|
+ INNER JOIN tb_data_bfi_indicator d2 ON en.entity_id = d2.entity_id
|
|
|
+ INNER JOIN tb_data_risk_stats d3 ON en.entity_id = d3.entity_id
|
|
|
+ INNER JOIN tb_data_riskadjret_stats d4 ON en.entity_id = d4.entity_id
|
|
|
+ INNER JOIN tb_data_indicator_stats d5 ON en.entity_id = d5.entity_id
|
|
|
+ WHERE en.strategy IS NOT NULL;
|
|
|
|
|
|
- // 跟踪误差
|
|
|
- run_ranking_sql(t, 'tracking_error', 48, true, v_ranking_tables);
|
|
|
+ // 按照 MySQL 字段建表
|
|
|
+ t_s = create_entity_indicator_ranking(false);
|
|
|
+ t_s_num = create_entity_indicator_ranking_num(false);
|
|
|
+ t_ss = create_entity_indicator_substrategy_ranking(false);
|
|
|
+ t_ss_num = create_entity_indicator_substrategy_ranking_num(false);
|
|
|
+
|
|
|
+ v_ranking_tables = [t_s, t_s_num, t_ss, t_ss_num];
|
|
|
|
|
|
- // M2
|
|
|
- run_ranking_sql(t, 'm2', 49, false, v_ranking_tables);
|
|
|
+ // 取消 39, 53, 54, 55, 57, 57
|
|
|
+ v_indicator_id = [11, 12, 16, 33, 34, 35, 36, 38, 48, 59,
|
|
|
+ 2, 6, 9, 10, 21, 50, 52,
|
|
|
+ 14, 15, 16, 17, 18, 19, 58, 21, 40,
|
|
|
+ 37, 41, 42, 43, 44, 45, 46, 47, 49
|
|
|
+ ];
|
|
|
+ indicator_table = SELECT * FROM get_indicator_info() WHERE id in v_indicator_id;
|
|
|
+
|
|
|
+ run_ranking_sql(t, indicator_table, v_ranking_tables);
|
|
|
|
|
|
return v_ranking_tables;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/*
|
|
|
* 将源指标表横表变竖表,以方便排名计算
|
|
|
*
|
|
@@ -543,7 +705,11 @@ def cal_other_indicator_ranking(entity_type, entity_info, end_date, isFromMySQL)
|
|
|
*/
|
|
|
def transform_data_for_ranking(entity_type, data_table, ranking_by, indicator_info) {
|
|
|
|
|
|
- v_trailing = ['6m', '1y', '2y', '3y', '5y', '10y', 'ytd'];
|
|
|
+ // 只有收益需要1m, 3m
|
|
|
+ if(indicator_info.size() == 1 && indicator_info[0].id == 1 )
|
|
|
+ v_trailing = ['1m', '3m', '6m', '1y', '2y', '3y', '5y', '10y', 'ytd'];
|
|
|
+ else
|
|
|
+ v_trailing = ['6m', '1y', '2y', '3y', '5y', '10y', 'ytd'];
|
|
|
|
|
|
// 只有 portfolio_id 是整型,其它的都是字符串
|
|
|
is_id_integer = false;
|
|
@@ -558,35 +724,38 @@ def transform_data_for_ranking(entity_type, data_table, ranking_by, indicator_in
|
|
|
|
|
|
for(indicator in indicator_info) {
|
|
|
|
|
|
- t = sql(select = (sqlCol('entity_id'), sqlCol('end_date'), sqlCol('category_id'),
|
|
|
+ t = sql(select = (sqlCol(['entity_id', 'end_date', 'category_id']), <indicator.id as indicator_id>,
|
|
|
sqlCol(indicator.name + '_' + v_trailing,, 'indicator_' + v_trailing)
|
|
|
),
|
|
|
from = data_table
|
|
|
).eval();
|
|
|
|
|
|
- t.join!(table(take(indicator.id, t.size()) AS indicator_id,
|
|
|
- take(double(NULL), t.size()) AS indicator_1m,
|
|
|
- take(int(NULL), t.size()) AS absrank_1m,
|
|
|
- take(int(NULL), t.size()) AS perrank_1m,
|
|
|
- take(double(NULL), t.size()) AS indicator_3m,
|
|
|
- take(int(NULL), t.size()) AS absrank_3m,
|
|
|
- take(int(NULL), t.size()) AS perrank_3m,
|
|
|
- take(int(NULL), t.size()) AS absrank_6m,
|
|
|
- take(int(NULL), t.size()) AS perrank_6m,
|
|
|
- take(int(NULL), t.size()) AS absrank_1y,
|
|
|
- take(int(NULL), t.size()) AS perrank_1y,
|
|
|
- take(int(NULL), t.size()) AS absrank_2y,
|
|
|
- take(int(NULL), t.size()) AS perrank_2y,
|
|
|
- take(int(NULL), t.size()) AS absrank_3y,
|
|
|
- take(int(NULL), t.size()) AS perrank_3y,
|
|
|
- take(int(NULL), t.size()) AS absrank_5y,
|
|
|
- take(int(NULL), t.size()) AS perrank_5y,
|
|
|
- take(int(NULL), t.size()) AS absrank_10y,
|
|
|
- take(int(NULL), t.size()) AS perrank_10y,
|
|
|
- take(int(NULL), t.size()) AS absrank_ytd,
|
|
|
- take(int(NULL), t.size()) AS perrank_ytd)
|
|
|
- );
|
|
|
+ if(indicator_info.size() > 1 || indicator_info[0].id <> 1 )
|
|
|
+ {
|
|
|
+ t.join!(table(take(double(NULL), t.size()) AS indicator_1m,
|
|
|
+ take(double(NULL), t.size()) AS indicator_3m) );
|
|
|
+ }
|
|
|
|
|
|
+ t.join!(table( take(int(NULL), t.size()) AS absrank_1m,
|
|
|
+ take(int(NULL), t.size()) AS perrank_1m,
|
|
|
+ take(int(NULL), t.size()) AS absrank_3m,
|
|
|
+ take(int(NULL), t.size()) AS perrank_3m,
|
|
|
+ take(int(NULL), t.size()) AS absrank_6m,
|
|
|
+ take(int(NULL), t.size()) AS perrank_6m,
|
|
|
+ take(int(NULL), t.size()) AS absrank_1y,
|
|
|
+ take(int(NULL), t.size()) AS perrank_1y,
|
|
|
+ take(int(NULL), t.size()) AS absrank_2y,
|
|
|
+ take(int(NULL), t.size()) AS perrank_2y,
|
|
|
+ take(int(NULL), t.size()) AS absrank_3y,
|
|
|
+ take(int(NULL), t.size()) AS perrank_3y,
|
|
|
+ take(int(NULL), t.size()) AS absrank_5y,
|
|
|
+ take(int(NULL), t.size()) AS perrank_5y,
|
|
|
+ take(int(NULL), t.size()) AS absrank_10y,
|
|
|
+ take(int(NULL), t.size()) AS perrank_10y,
|
|
|
+ take(int(NULL), t.size()) AS absrank_ytd,
|
|
|
+ take(int(NULL), t.size()) AS perrank_ytd )
|
|
|
+ );
|
|
|
+
|
|
|
INSERT INTO tb_ranking
|
|
|
SELECT * FROM (sql(select = sqlCol(tb_ranking.colNames()),
|
|
|
from = t).eval());
|
|
@@ -599,6 +768,39 @@ def transform_data_for_ranking(entity_type, data_table, ranking_by, indicator_in
|
|
|
/*
|
|
|
* 将源风险指标表横表变竖表,以方便排名计算
|
|
|
*
|
|
|
+ *
|
|
|
+ */
|
|
|
+def transform_return_for_ranking (entity_type, entity_info, end_date, ranking_by, isFromMySQL=true) {
|
|
|
+
|
|
|
+ table_desc = get_performance_table_description(entity_type);
|
|
|
+
|
|
|
+ tb_data = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
+ sec_id_col = table_desc.sec_id_col[0];
|
|
|
+ tb_data.rename!(sec_id_col, 'entity_id');
|
|
|
+
|
|
|
+ data_table = SELECT * FROM entity_info en
|
|
|
+ INNER JOIN tb_data d ON en.entity_id = d.entity_id
|
|
|
+ WHERE en.strategy IS NOT NULL
|
|
|
+
|
|
|
+ data_table.dropColumns!('id');
|
|
|
+ data_table.rename!(ranking_by, 'category_id');
|
|
|
+
|
|
|
+
|
|
|
+ // 目前SQL排名的指标还包含39:年化收益,与收益没有什么差别所以被取消
|
|
|
+ v_indicator_name = ['ret'];
|
|
|
+ v_indicator_id = [1];
|
|
|
+ v_is_ASC = [false];
|
|
|
+ t_indicator = table(v_indicator_name AS name, v_indicator_id AS id, v_is_ASC AS is_ASC);
|
|
|
+
|
|
|
+ tb_ranking = transform_data_for_ranking(entity_type, data_table, ranking_by, t_indicator).rename!('category_id', ranking_by);
|
|
|
+
|
|
|
+ return tb_ranking;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+ * 将源风险指标表横表变竖表,以方便排名计算
|
|
|
+ *
|
|
|
* TODO: 一直缺 portfolio bfi indicator 计算!mysql 里的 pf_fund_bfi_bm_indicator_ranking 是错的...
|
|
|
*/
|
|
|
def transform_risk_stats_for_ranking (entity_type, entity_info, end_date, ranking_by, isFromMySQL=true) {
|
|
@@ -692,6 +894,38 @@ def transform_other_indicator_for_ranking (entity_type, entity_info, end_date, r
|
|
|
return tb_ranking;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/*
|
|
|
+ * 将源杂项风险指标表横表变竖表,以方便排名计算
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+def transform_capture_style_for_ranking (entity_type, entity_info, end_date, ranking_by, isFromMySQL=true) {
|
|
|
+
|
|
|
+ table_desc = get_capture_style_table_description(entity_type);
|
|
|
+
|
|
|
+ tb_data = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
+ sec_id_col = table_desc.sec_id_col[0];
|
|
|
+ tb_data.rename!(sec_id_col, 'entity_id');
|
|
|
+
|
|
|
+ data_table = SELECT * FROM entity_info en
|
|
|
+ INNER JOIN tb_data d ON en.entity_id = d.entity_id
|
|
|
+ WHERE en.strategy IS NOT NULL
|
|
|
+
|
|
|
+ data_table.dropColumns!('id');
|
|
|
+ data_table.rename!(ranking_by, 'category_id');
|
|
|
+
|
|
|
+ // 目前SQL排名的指标
|
|
|
+ v_indicator_name = ['upsidecapture_ret', 'downsidecapture_ret', 'upsidecapture_ratio', 'downsidecapture_ratio'];
|
|
|
+ v_indicator_id = [33, 34, 35, 36];
|
|
|
+ v_is_ASC = [false, false, false, true];
|
|
|
+ t_indicator = table(v_indicator_name AS name, v_indicator_id AS id, v_is_ASC AS is_ASC);
|
|
|
+
|
|
|
+ tb_ranking = transform_data_for_ranking(entity_type, data_table, ranking_by, t_indicator).rename!('category_id', ranking_by);
|
|
|
+
|
|
|
+ return tb_ranking;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
*
|
|
|
* 参考某指定类排名,计算相对排名
|
|
@@ -778,15 +1012,19 @@ def save_ranking_tables(entity_type, ranking_tables) {
|
|
|
|
|
|
save_and_sync(ranking_tables[1], source_table + '_num', target_table + '_num');
|
|
|
|
|
|
+ source_table = source_table.strReplace('_ranking', '_substrategy_ranking');
|
|
|
+ target_table = target_table.strReplace('_ranking', '_substrategy_ranking');
|
|
|
+
|
|
|
ranking_tables[2].rename!('entity_id', entity_id_col);
|
|
|
- save_and_sync(ranking_tables[2], source_table.replace!('_ranking', '_substrategy_ranking'), target_table.replace!('_ranking', '_substrategy_ranking'));
|
|
|
+ save_and_sync(ranking_tables[2], source_table, target_table);
|
|
|
|
|
|
save_and_sync(ranking_tables[3], source_table + '_num', target_table + '_num');
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 参考排名数据入库
|
|
|
+ * 参考排名数据入库AND a.indicator_id NOT IN (50, 52, 59, 46)
|
|
|
+
|
|
|
*
|
|
|
* @param ranking_tables <TABLE>:
|
|
|
*/
|