Joey 1 ماه پیش
والد
کامیت
b2385f75da
3فایلهای تغییر یافته به همراه11 افزوده شده و 32 حذف شده
  1. 4 11
      codes/Sample_cal_indicators.dos
  2. 2 18
      codes/sample_cal_portfolio.dos
  3. 5 3
      codes/sample_cal_return.dos

+ 4 - 11
codes/Sample_cal_indicators.dos

@@ -11,25 +11,18 @@ use fundit::indicatorCalculator
 end_day = 2024.06.28
 //end_day = today()
 
-bmk_ret = SELECT fund_id, temporalParse(end_date, 'yyyy-MM') AS end_date, ret FROM get_fund_monthly_ret("'IN00000008'", 1990.01.01, end_day, true); 
-risk_free_rate = SELECT fund_id, temporalParse(end_date, 'yyyy-MM') AS end_date, ret FROM get_risk_free_rate("'IN0000000M'", 1990.01.01, end_day);
-
-
-
 /* TEST CASE 1  */
 
-// fund_ids = "'HF000004KN','HF000103EU','HF00018WXG'";
+fund_ids = "'HF000004KN','HF000103EU','HF00018WXG'";
 
-/* TEST CASE 2 */
+/* TEST CASE 2 
 tb_updated_funds = get_fund_list_by_nav_updatetime(null, 2024.07.19T10:00:00);
 
 // take 1000 funds for testing
 fund_ids = tb_updated_funds.fund_id[0:1000].concat("','")$STRING;
 fund_ids = "'" + fund_ids + "'";
+*/
 
-tb_ret = SELECT * FROM cal_hedge_fund_returns(fund_ids, true) WHERE price_date <= end_day;
-tb_ret.rename!(['fund_id', 'cumulative_nav'], ['entity_id', 'nav']);
-
-tb_indicators = cal_all_trailing_indicators(tb_ret, end_day, bmk_ret, risk_free_rate, 'm');
+tb_indicators = cal_fund_indicators('HF', fund_ids, end_day, true);
 
 SELECT * FROM tb_indicators[0];

+ 2 - 18
codes/sample_cal_portfolio.dos

@@ -26,26 +26,10 @@ cal_method = 2;
 tb_portfolio_ret = cal_portfolio_return(portfolio_ids, very_old_date, cal_method);
 tb_portfolio_ret.sortBy!(['portfolio_id', 'price_date'], [1, 1]);
 
-select portfolio_id, price_date.month(), price_date.last(), (1+ret).prod()-1, nav.last()
-from tb_portfolio_ret 
-where price_date <= end_day
-group by portfolio_id, price_date.month()
-
 // calculate indicators
 end_day = 2024.08.31
 
-bmk_ret = SELECT fund_id, temporalParse(end_date, 'yyyy-MM') AS end_date, ret FROM get_fund_monthly_ret("'IN00000008'", 1990.01.01, end_day, true); 
-risk_free_rate = SELECT fund_id, temporalParse(end_date, 'yyyy-MM') AS end_date, ret FROM get_risk_free_rate("'IN0000000M'", 1990.01.01, end_day);
-
-// calculate monthly return
-// funky thing is you can't use "AS" for the grouping columns?
-tb_ret = SELECT portfolio_id, price_date.month(), price_date.last() AS price_date, (1+ret).prod()-1 AS ret, nav.last() AS nav
-         FROM tb_portfolio_ret
-         WHERE price_date <= end_day
-         GROUP BY portfolio_id, price_date.month();
-
-tb_ret.rename!(['portfolio_id', 'month_price_date'], ['entity_id', 'end_date']);
+tb_indicators = cal_portfolio_indicators(portfolio_ids, end_day, cal_method, true);
 
-tb_indicators = cal_all_trailing_indicators(tb_ret, end_day, bmk_ret, risk_free_rate, 'm');
+select * from tb_indicators[0]
 
-select * from tb_indicators[8]

+ 5 - 3
codes/sample_cal_return.dos

@@ -4,23 +4,25 @@ clearCachedModules()
 use fundit::fundCalculator
 use fundit::dataPuller
 use fundit::returnCalculator
+use fundit::sqlUtilities
 
 // TEST CASE 1
 fund_ids = "'HF000004KN','HF00018WXG','HF000103EU'"
 
 // TEST CASE 2 取有净值更新的所有私募基金
-tb_fund_list = get_fund_list_by_nav_updatetime(2024.07.19T10:00:00)
+tb_fund_list = get_fund_list_by_nav_updatetime(null, 2024.07.19T10:00:00);
 fund_ids = tb_fund_list.fund_id.concat("','")$STRING
 fund_ids = "'" + fund_ids$STRING + "'"
 
 // 取基金净值
-tb_nav = get_hedge_fund_nav_by_price_date(fund_ids, 1990.01.01, true)
+tb_nav = get_nav_by_price_date('HF', fund_ids, 1990.01.01, true)
 save_hedge_fund_nav_to_local(tb_nav)
 
 // 计算基金月收益
-tb_fund_performance = cal_hedge_fund_returns(fund_ids, false)
+tb_fund_performance = cal_fund_monthly_returns('HF', fund_ids, false)
 save_table(tb_fund_performance, "mfdb.fund_performance", false)
 
+
 // 计算基金周收益
 tb_fund_performance_weekly = cal_hedge_fund_weekly_returns(fund_ids, false)
 save_table(tb_fund_performance_weekly, "mfdb.fund_performance_weekly", false)