|
@@ -355,6 +355,34 @@ def get_fund_info(fund_ids) {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
+ * 取有效指数基本信息
|
|
|
+ *
|
|
|
+ * Example: get_index_info("'IN00000008','IN000002GE'");
|
|
|
+ *
|
|
|
+ */
|
|
|
+def get_index_info(index_ids) {
|
|
|
+
|
|
|
+ s_entity_ids = ids_to_string(index_ids);
|
|
|
+
|
|
|
+ if(s_entity_ids == NULL || s_entity_ids == '') return null;
|
|
|
+
|
|
|
+ s_query = "SELECT fi.index_id, fi.inception_date, NULL AS benchmark_id, IFNULL(fi.index_initial_value, 1) AS ini_value, fi.index_code, fi.index_type_id
|
|
|
+ FROM mfdb.indexes_profile fi
|
|
|
+ WHERE fi.index_id IN (" + s_entity_ids + ")
|
|
|
+ AND fi.isvalid = 1
|
|
|
+ ORDER BY fi.index_id"
|
|
|
+
|
|
|
+ conn = connect_mysql()
|
|
|
+
|
|
|
+ t = odbc::query(conn, s_query)
|
|
|
+
|
|
|
+ conn.close()
|
|
|
+
|
|
|
+ return t
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
* 取组合有效信息
|
|
|
*
|
|
|
* Example: get_portfolio_info('166002,166114');
|
|
@@ -400,14 +428,18 @@ def get_entity_info(entity_type, entity_ids) {
|
|
|
if(entity_type == 'MF' || entity_type == 'HF') {
|
|
|
|
|
|
t = get_fund_info(s_entity_ids);
|
|
|
-
|
|
|
t.rename!('fund_id', 'entity_id');
|
|
|
|
|
|
} else if(entity_type == 'PF') {
|
|
|
|
|
|
t = get_portfolio_info(s_entity_ids);
|
|
|
-
|
|
|
t.rename!('portfolio_id', 'entity_id');
|
|
|
+
|
|
|
+ } else if(entity_type IN ['MI', 'FI']) {
|
|
|
+
|
|
|
+ t = get_index_info(s_entity_ids);
|
|
|
+ t.rename!('index_id', 'entity_id');
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return t;
|
|
@@ -550,13 +582,17 @@ def get_portfolio_primary_benchmark(portfolio_ids, month_start, month_end) {
|
|
|
/*
|
|
|
* 取某时间段的基金组合主基准
|
|
|
*
|
|
|
+ * NOTE: 指数和因子的”主基准”设置为沪深300
|
|
|
*
|
|
|
* Example: get_entity_primary_benchmark('MF', "'MF00003PW2', 'MF00003PW1', 'MF00003PXO'", '1990-01', '2024-06');
|
|
|
* get_entity_primary_benchmark('PF', [166002,166114], '1990-01', '2024-08');
|
|
|
+ * get_entity_primary_benchmark('MI', ['IN00000008', 'IN0000000M'], '2024-07', '2024-08');
|
|
|
*/
|
|
|
def get_entity_primary_benchmark(entity_type, entity_ids, month_start, month_end) {
|
|
|
|
|
|
- t = null;
|
|
|
+ t = table(100:0,
|
|
|
+ ['entity_id', 'end_date', 'benchmark_id'],
|
|
|
+ [iif(entity_type == 'PF', INT, SYMBOL), MONTH, SYMBOL]);
|
|
|
|
|
|
s_entity_ids = ids_to_string(entity_ids);
|
|
|
|
|
@@ -572,7 +608,13 @@ def get_entity_primary_benchmark(entity_type, entity_ids, month_start, month_end
|
|
|
|
|
|
t = get_portfolio_primary_benchmark(s_entity_ids, month_start, month_end);
|
|
|
|
|
|
- t.rename!('portfolio_id', 'entity_id');
|
|
|
+ t.rename!('portfolio_id', 'entity_id');
|
|
|
+
|
|
|
+ } else if(entity_type IN ['MI', 'FI', 'FA', 'CI', 'EQ']) {
|
|
|
+ // 对于指数、因子来说,没有什么基准。但为了指标计算不得不在这里设个假的
|
|
|
+ t = SELECT entity_id, end_date, 'IN00000008' AS benchmark_id
|
|
|
+ FROM cj(get_entity_info(entity_type, s_entity_ids), table(temporalParse(month_start, 'yyyy-MM')..temporalParse(month_end, 'yyyy-MM') AS end_date))
|
|
|
+ WHERE end_date >= iif(inception_date.isNull(), 1990.01M, inception_date.month())
|
|
|
}
|
|
|
|
|
|
return t;
|