소스 검색

小修小补,<TAB>变空格

Joey 1 주 전
부모
커밋
178ccd50b1
1개의 변경된 파일81개의 추가작업 그리고 40개의 파일을 삭제
  1. 81 40
      modules/dataPuller.dos

+ 81 - 40
modules/dataPuller.dos

@@ -97,28 +97,30 @@ def get_portfolio_weekly_rets(portfolio_ids, start_date, end_date, isFromMySQL)
     return t
 }
 
-/*
- *  取公私募基金月收益
- *
- *  get_fund_monthly_ret("'MF00003PW1','MF00003PW1'", 1990.01.01, today(), true)
- */
+def get_monthly_ret(entity_type, entity_ids, start_date, end_date, isFromMySQL) {
 
-def get_fund_monthly_ret(fund_ids, start_date, end_date, isFromMySQL) {
+    s_entity_ids = '';
+    
+    // 判断输入的 fund_ids 是字符串标量还是向量
+    if ( entity_ids.form() == 0 ) {
+        s_entity_ids = entity_ids;
+    } else {
+        s_entity_ids = "'" + entity_ids.concat("','") + "'";
+    }
+
+    tmp = get_performance_table_description(entity_type);
 
     yyyymm_start = start_date.temporalFormat("yyyy-MM")
     yyyymm_end = end_date.temporalFormat("yyyy-MM")
 
     if(isFromMySQL == true) {
 
-        ret_table_name = "mfdb.fund_performance"
-        
-        s_query = "SELECT fund_id, end_date, price_date, ret_1m AS ret, cumulative_nav AS nav, ret_ytd_a, ret_incep_a
-                   FROM " + ret_table_name + "
-                   WHERE fund_id IN (" + fund_ids + ")
+        s_query = "SELECT " + tmp.sec_id_col[0] + ", end_date, price_date, ret_1m AS ret, cumulative_nav AS nav, ret_ytd_a, ret_incep_a
+                   FROM " + tmp.table_name[0] + "
+                   WHERE " + tmp.sec_id_col[0] + " IN (" + s_entity_ids + ")
                       AND isvalid = 1
-                      AND cumulative_nav > 0
                       AND end_date BETWEEN '" + yyyymm_start + "' AND '" + yyyymm_end + "'
-                   ORDER BY fund_id, end_date"
+                   ORDER BY " + tmp.sec_id_col[0] + ", end_date";
      
         conn = connect_mysql()
      
@@ -128,11 +130,11 @@ def get_fund_monthly_ret(fund_ids, start_date, end_date, isFromMySQL) {
 
     } else {
         
-        tb_local = load_table_from_local("fundit", "mfdb.fund_performance")
-
-        s_col = (sqlCol("fund_id"), sqlCol("end_date"), sqlColAlias(<ret_1m>, "ret"), sqlColAlias(<cumulative_nav>, "nav"), sqlCol("ret_ytd_a"), sqlCol("ret_incep_a"))
+        tb_local = load_table_from_local("fundit", tmp.table_name[0])
 
-        s_where = expr(<fund_id>, in, fund_ids.strReplace("'", "").split(","))
+        s_col = (sqlCol(tmp.sec_id_col[0]), sqlCol("end_date"), sqlColAlias(<ret_1m>, "ret"), sqlColAlias(<cumulative_nav>, "nav"), sqlCol("ret_ytd_a"), sqlCol("ret_incep_a"))
+        // TODO: how to make the "fund_id" dynamicly decided by tmp.sec_id_col[0]?
+        s_where = expr(<fund_id>, in, s_entity_ids.strReplace("'", "").split(","))
         
         t = sql(s_col, tb_local, s_where).eval()
     
@@ -141,14 +143,26 @@ def get_fund_monthly_ret(fund_ids, start_date, end_date, isFromMySQL) {
     return t
 }
 
+
+/*
+ *  取公私募基金月收益
+ *
+ *  get_fund_monthly_ret("'MF00003PW1','MF00003PW1'", 1990.01.01, today(), true)
+ */
+
+def get_fund_monthly_ret(fund_ids, start_date, end_date, isFromMySQL) {
+
+    return get_monthly_ret('FD', fund_ids, start_date, end_date, isFromMySQL);
+}
+
 /*
  * 取无风险月度利率
  *
- * get_risk_free_rate("IN0000000M", 1990.01.01, today())
+ * get_risk_free_rate(1990.01.01, today())
  */
-def get_risk_free_rate(index_id, start_date, end_date) {
+def get_risk_free_rate(start_date, end_date) {
     
-    return get_fund_monthly_ret(index_id, start_date, end_date, true)
+    return get_monthly_ret('IX', "'IN0000000M'", start_date, end_date, true);
 }
 
 
@@ -193,49 +207,51 @@ def get_fund_latest_nav_performance(fund_ids, isFromMySQL) {
  * 取私募基金净值
  * 
  * 
- * 
  * Create: 202408                                                    Joey
  *                 TODO: add isvalid and nav > 0 for local version
  * 
  *
- * Example: get_hedge_fund_nav_by_price_date("'HF000004KN','HF00018WXG'", 2024.05.01, true)
+ * Example: get_nav_by_price_date('HF', "'HF000004KN','HF00018WXG'", 2024.05.01, true)
  */
-def get_hedge_fund_nav_by_price_date(fund_ids, price_date, isFromMySQL) {
+def get_nav_by_price_date(entity_type, entity_ids, price_date, isFromMySQL) {
 
-    s_fund_ids = '';
+    s_entity_ids = '';
     
     // 判断输入的 fund_ids 是字符串标量还是向量
-    if ( fund_ids.form() == 0 ) {
-    	s_fund_ids = fund_ids;
+    if ( entity_ids.form() == 0 ) {
+        s_entity_ids = entity_ids;
     } else {
-    	s_fund_ids = "'" + fund_ids.concat("','") + "'";
+        s_entity_ids = "'" + entity_ids.concat("','") + "'";
     }
 
+    tmp = get_nav_table_description(entity_type);
 
     if(isFromMySQL == true) {
 
         nav_table_name = "mfdb.nav"
     
-        s_query = "SELECT fund_id, price_date, cumulative_nav
-                   FROM " + nav_table_name + "
-                   WHERE fund_id IN (" + s_fund_ids + ")
+        s_query = "SELECT " + tmp.sec_id_col[0] + ", price_date, " + tmp.cumulative_nav_col[0] + ", " + tmp.nav_col[0] + "
+                   FROM " + tmp.table_name[0] + "
+                   WHERE " + tmp.sec_id_col[0] + " IN (" + s_entity_ids + ")
                      AND isvalid = 1
-                     AND cumulative_nav > 0
+                     AND " + tmp.cumulative_nav_col[0] + " > 0
                      AND price_date >= '" + price_date$STRING + "'
-                   ORDER BY fund_id, price_date"
+                   ORDER BY " + tmp.sec_id_col[0] + ", price_date";
     
-        conn = connect_mysql()
+        conn = connect_mysql();
     
-        t = odbc::query(conn, s_query)
+        t = odbc::query(conn, s_query);
     
-        conn.close()
+        conn.close();
+
     } else {
     
-        tb_local = load_table_from_local("fundit", "mfdb.nav")
+        tb_local = load_table_from_local("fundit", tmp.table_name[0])
 
         s_col = sqlCol("*")
 
-        s_where = [expr(<fund_id>, in, fund_ids.strReplace("'", "").split(",")), <price_date >= price_date>]
+        // TODO: how to make the "fund_id" dynamicly decided by tmp.sec_id_col[0]?
+        s_where = [expr(<fund_id>, in, s_entity_ids.strReplace("'", "").split(",")), <price_date >= price_date>]
         
         t = sql(s_col, tb_local, s_where).eval()
     
@@ -289,7 +305,8 @@ def get_index_nav_by_price_date(index_ids, price_date) {
 /*
  * 取有效基金基本信息
  *
- * get_fund_info("'HF000004KN','HF00018WXG'")
+ * Example: get_fund_info("'HF000004KN','HF00018WXG'")
+ * 
  */
 def get_fund_info(fund_ids) {
 
@@ -310,6 +327,30 @@ def get_fund_info(fund_ids) {
 
 }
 
+/*
+ *  取组合有效信息
+ * 
+ *  Example: get_portfolio_info('166002,166114');
+ *  
+ */
+def get_portfolio_info(portfolio_ids) {
+
+    s_query = "SELECT cpm.id AS portfolio_id, cpm.userid, cpm.customer_id, cpm.inception_date, cpm.portfolio_source, cpm.portfolio_type
+               FROM pfdb.`pf_customer_portfolio_map` cpm
+               INNER JOIN pfdb.cm_user u ON cpm.userid = u.userid
+               WHERE cpm.id IN (" + portfolio_ids + ")
+                 AND cpm.isvalid = 1
+                 AND u.isvalid = 1
+               ORDER BY cpm.id"
+
+    conn = connect_mysql()
+
+    t = odbc::query(conn, s_query)
+
+    conn.close()
+
+    return t
+}
 
 /*
  * 取私募基金净值更新信息, 返回基金及其净值更新的最早净值日期
@@ -325,8 +366,8 @@ def get_fund_list_by_nav_updatetime(fund_ids, updatetime) {
     s_fund_sql = '';
     // 这里要用 isVoid, 因为 isNull对向量返回的是布尔向量
     if (! isVoid(fund_ids)){
-    	s_fund_ids = fund_ids.concat("','");
-    	s_fund_sql = " AND fi.fund_id IN ('" + s_fund_ids + "')";
+        s_fund_ids = fund_ids.concat("','");
+        s_fund_sql = " AND fi.fund_id IN ('" + s_fund_ids + "')";
     }
     
     s_query = "SELECT fi.fund_id, MIN(nav.price_date) AS price_date,