浏览代码

小修小补

Joey 4 月之前
父节点
当前提交
c75748f3db
共有 1 个文件被更改,包括 7 次插入14 次删除
  1. 7 14
      codes/Test_indicatorCalculator.dos

+ 7 - 14
codes/Test_indicatorCalculator.dos

@@ -11,7 +11,7 @@ use fundit::indicatorCalculator
 end_day = 2024.08.31; //2024.06.28;
 fund_ids = "'MF00003PW1','MF00003RS0'"; //"'HF000004KN','HF000103EU','HF00018WXG'";
 entity_type = "MF"; //'HF';
-isFromNav = true;
+
 
 /* codes from cal_fund_indicators */
     very_old_date = 1990.01.01;
@@ -20,17 +20,10 @@ isFromNav = true;
     fund_info = get_fund_info(fund_ids);
     fund_info.rename!('fund_id', 'entity_id');
 
-    if(isFromNav == true) {
-        // 从净值开始计算收益
-        tb_ret = SELECT * FROM cal_fund_monthly_returns(entity_type, fund_ids, true) WHERE price_date <= end_day;
-        tb_ret.rename!(['fund_id', 'cumulative_nav'], ['entity_id', 'nav']);
-    } else {
-        // 从fund_performance表里读月收益
-        tb_ret = get_monthly_ret('FD', fund_ids, very_old_date, end_day, true);
-        tb_ret.rename!(['fund_id'], ['entity_id']);
-        v_end_date = tb_ret.end_date.temporalParse('yyyy-MM');
-        tb_ret.replaceColumn!('end_date', v_end_date);
-    }
+    // 从fund_performance表里读月收益
+    tb_ret = get_monthly_ret(entity_type, fund_ids, very_old_date, end_day, true);
+    v_end_date = tb_ret.end_date.temporalParse('yyyy-MM');
+    tb_ret.replaceColumn!('end_date', v_end_date);
 
     // 取基金和基准的对照表
     primary_benchmark = SELECT fund_id AS entity_id, end_date, iif(benchmark_id.isNull(), 'IN00000008', benchmark_id) AS benchmark_id 
@@ -39,7 +32,7 @@ isFromNav = true;
     // 取所有出现的基准月收益
     bmk_ret = get_benchmark_return(primary_benchmark, end_day);
 
-    risk_free_rate = SELECT fund_id, temporalParse(end_date, 'yyyy-MM') AS end_date, ret FROM get_risk_free_rate(very_old_date, end_day);
+    risk_free_rate = SELECT entity_id AS fund_id, temporalParse(end_date, 'yyyy-MM') AS end_date, ret FROM get_risk_free_rate(very_old_date, end_day);
 
 
 entity_info = fund_info;
@@ -250,7 +243,7 @@ assert (select upside_capture_ret.round(4) as upside_capture_ret
         from capture_r where entity_id in entity_ids and end_date in (2024.07M, 2024.08M)).upside_capture_ret == [-0.003743,-0.003743, 0.002156, 0.001314].round(4);
 @testing: case = 'trailing2y upside capture ratio' 
 assert (select upside_capture_ratio.round(3) as upside_capture_ratio
-        from capture_r where entity_id in entity_ids and end_date in (2024.07M, 2024.08M)).upside_capture_ratio == [-0.223084,-0.223084, 0.365611, 0.237662].round(3);
+        from capture_r where entity_id in entity_ids and end_date in (2024.07M, 2024.08M)).upside_capture_ratio.round(2) == [-0.223084,-0.223084, 0.365611, 0.237662].round(2);
 @testing: case = 'trailing2y downside capture return' 
 assert (select downside_capture_ret.round(4) as downside_capture_ret 
         from capture_r where entity_id in entity_ids and end_date in (2024.07M, 2024.08M)).downside_capture_ret == [-0.022388,-0.023754,-0.004776,-0.004776].round(4);