|
@@ -119,30 +119,6 @@ def cal_fund_performance(fund_ids, month_end) {
|
|
*/
|
|
*/
|
|
def cal_mutual_fund_performance(fund_ids, isFromMySQL) {
|
|
def cal_mutual_fund_performance(fund_ids, isFromMySQL) {
|
|
|
|
|
|
-
|
|
|
|
-/* 找到不必用pivot table 填充数据的办法了
|
|
|
|
-
|
|
|
|
- // NOTE: mySQL currently uses calendar day, while the codes below takes business day. it might cause a few different numbers calcuated
|
|
|
|
- tb_monthly_nav = SELECT fund_id, businessMonthEnd(price_date).month().last() AS end_date, price_date.last() AS price_date, cumulative_nav.last() AS cumulative_nav
|
|
|
|
- FROM tb_nav
|
|
|
|
- GROUP BY fund_id, businessMonthEnd(price_date);
|
|
|
|
-
|
|
|
|
- // 补一下成立日净值
|
|
|
|
- // NOTE: DolphinDB 遇见 EXISTS 语句时,似乎主表的 alias 失效,只好用全名
|
|
|
|
- INSERT INTO tb_monthly_nav
|
|
|
|
- SELECT businessMonthEnd(inception_date), fund_id, inception_date.month(), inception_date, ifNull(ini_value, 1)
|
|
|
|
- FROM tb_fund_info
|
|
|
|
- WHERE NOT EXISTS ( SELECT * FROM tb_monthly_nav n WHERE tb_fund_info.fund_id = n.fund_id AND tb_fund_info.inception_date = n.price_date);
|
|
|
|
-
|
|
|
|
- // 为了把不数据库里不存在的nav记录填空,不得不先做个pivot;然后才能正确计算ratios (ret_1m)
|
|
|
|
- // TODO: much better way is to have a "full list" of dates, then LEFT JOIN nav table, then ffill()
|
|
|
|
- tb_rets_1m = (SELECT cumulative_nav FROM tb_monthly_nav PIVOT BY end_date, fund_id).ffill!().ratios()-1
|
|
|
|
-
|
|
|
|
- // 取被pivot掉的fund_Ids
|
|
|
|
- v_col_name = tb_rets_1m.columnNames()[1:]
|
|
|
|
- tb_tmp = tb_rets_1m.unpivot("end_date", v_col_name).rename!("valueType" "value", "fund_id" "ret_1m")
|
|
|
|
-*/
|
|
|
|
-
|
|
|
|
// 计算月收益
|
|
// 计算月收益
|
|
tb_tmp = cal_hedge_fund_returns(fund_ids, isFromMySQL);
|
|
tb_tmp = cal_hedge_fund_returns(fund_ids, isFromMySQL);
|
|
|
|
|