returnCalculator.dos 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. module fundit::returnCalculator
  2. use fundit::fundCalculator
  3. use fundit::dataPuller
  4. /*
  5. * 通用月收益计算
  6. *
  7. * @param entity_type <STRING>: MF, HF, EQ, CF, MI, TI, CI, FA, PF
  8. * @param entity_info <TABLE>: COLUMN NEED entity_id, price_date, inception_date, ini_value
  9. *
  10. */
  11. def cal_entity_monthly_returns(entity_type, entity_info) {
  12. tb_rets = null;
  13. // 取涉及到的所有基金证券最早持仓日期
  14. s_json = (SELECT entity_id AS sec_id, price_date.min() AS price_date FROM entity_info GROUP BY entity_id).toStdJson();
  15. // 取涉及到的所有基金证券有用净值(前值+某日期后所有净值)
  16. // TODO: need consider inception date nav
  17. tb_nav = get_nav_for_return_calculation(entity_type, 'm', s_json);
  18. // 填充好各基金有效期内所有月份的最后一天
  19. tb_monthly_nav = SELECT sec_id, price_date.month().last() AS end_date, price_date.last() AS price_date, cumulative_nav.last() AS cumulative_nav
  20. FROM tb_nav.sortBy!(['sec_id', 'price_date'], [1, 1])
  21. GROUP BY sec_id, price_date.month();
  22. // 删掉成立日之前的净值
  23. tb_monthly_nav = SELECT sec_id AS entity_id, end_date, price_date, cumulative_nav
  24. FROM tb_monthly_nav n // ej(tb_monthly_nav, entity_info, 'sec_id', 'entity_id')
  25. INNER JOIN entity_info ei ON n.sec_id = ei.entity_id
  26. WHERE n.price_date >= ei.inception_date
  27. ORDER BY n.sec_id, n.end_date, n.price_date;
  28. if(tb_monthly_nav.isVoid() || tb_monthly_nav.size() == 0) { return tb_rets; }
  29. // 计算月收益
  30. tb_rets = SELECT entity_id, end_date, price_date, cumulative_nav, cumulative_nav.ratios() - 1 AS ret
  31. FROM tb_monthly_nav
  32. CONTEXT BY entity_id;
  33. // the records without return calculated but do have nav are still useful for some calculations (e.g. max drawdown)
  34. return ( SELECT * FROM tb_rets WHERE cumulative_nav > 0 );
  35. }
  36. /*
  37. * 根据基金净值序列计算月收益序列(适合提供给指标运算)
  38. *
  39. * Create: 20240907 Joey
  40. * TODO: missing pulling data from local
  41. * TODO: ONLY support month return now
  42. *
  43. * @param entity_type <STRING>: NAV universe, 'HF','MF','PF','EQ'... defined in get_nav_table_description()
  44. * @param fund_ids <STRING VECTOR>: 基金ID
  45. * @param isFromMySQL <BOOL>: 净值来源 1 - 远程MySQL、 0 - 本地 DolphinDB
  46. *
  47. * Example: cal_fund_monthly_returns('HF', "'HF000004KN','HF000103EU','HF00018WXG'", true);
  48. *
  49. */
  50. def cal_fund_monthly_returns(entity_type, fund_ids, isFromMySQL){
  51. tb_rets = null;
  52. // 暂时只支持公募和私募基金
  53. if(entity_type != 'HF' && entity_type != 'MF' ) return tb_rets;
  54. // 用于保证老基金也能取到所有历史净值
  55. very_old_price_date = 1990.01.01;
  56. // 基金基本信息,包括初始净值
  57. tb_fund_info = get_fund_info(fund_ids);
  58. // 基金净值
  59. tb_nav = SELECT * FROM get_nav_by_price_date(entity_type, fund_ids, very_old_price_date, isFromMySQL);
  60. tb_month_end = table(100:0, ['fund_id', 'price_date'], [STRING, DATE]);
  61. // 填充好各基金有效期内所有月份的最后一天
  62. for( f in tb_fund_info )
  63. {
  64. INSERT INTO tb_month_end SELECT fund_id, price_date FROM table(f.fund_id.take(1) AS fund_id).cj(table(temporalSeq(f.inception_date, today(), 'M') AS price_date)) ;
  65. }
  66. UPDATE tb_month_end SET end_date = price_date.month();
  67. tb_monthly_nav = SELECT fund_id, monthEnd(price_date).month().last() AS end_date, price_date.last() AS price_date, cumulative_nav.last() AS cumulative_nav
  68. FROM tb_nav
  69. GROUP BY fund_id, monthEnd(price_date);
  70. // 完整月末日期的净值序列(包括缺失数据为NULL)
  71. tb_monthly_nav = SELECT me.fund_id, me.end_date, n.price_date, n.cumulative_nav
  72. FROM tb_month_end me
  73. LEFT JOIN tb_monthly_nav n ON me.fund_id = n.fund_id AND me.end_date = n.end_date
  74. ORDER BY me.fund_id, me.end_date;
  75. // 补一下成立日的初始净值
  76. // NOTE: DolphinDB 遇见 EXISTS 语句时,似乎主表的 alias 失效,只好用全名
  77. INSERT INTO tb_monthly_nav
  78. SELECT fund_id, inception_date.month(), inception_date, ifNull(ini_value, 1)
  79. FROM tb_fund_info fi
  80. WHERE NOT EXISTS ( SELECT * FROM tb_monthly_nav n WHERE fund_id = tb_fund_info.fund_id AND n.price_date = tb_fund_info.inception_date);
  81. if(tb_monthly_nav.isVoid() || tb_monthly_nav.size() == 0) { return tb_rets; }
  82. // 算 ratios 之前先把时间顺序排好
  83. tb_monthly_nav.sortBy!(['fund_id', 'end_date', 'price_date'], [1, 1, 1]);
  84. // 计算月收益
  85. tb_rets = SELECT fund_id, end_date, price_date, cumulative_nav, cumulative_nav.ratios() - 1 AS ret
  86. FROM tb_monthly_nav
  87. CONTEXT BY fund_id;
  88. // the records without return calculated but do have nav are still useful for some calculations
  89. return ( SELECT * FROM tb_rets WHERE cumulative_nav > 0 );
  90. }
  91. /*
  92. * 月末 fund_performance 表计算
  93. *
  94. * @param fund_ids <STRING>: 逗号分隔的ID
  95. * @param end_date <STRING>: YYYY-MM
  96. *
  97. * Example: cal_fund_performance("'HF000004KN','HF00018WXG','HF000103EU'", '2024-06', true);
  98. */
  99. def cal_fund_performance(fund_ids, month_end) {
  100. // 获取必要的基金月度净值
  101. tb_nav = get_nav_for_hedge_fund_performance(fund_ids, month_end);
  102. tb_rets = SELECT fund_id, price_date.month() AS end_date, price_date, cumulative_nav,
  103. cumulative_nav \ nav_1m - 1 AS ret_1m,
  104. cumulative_nav \ nav_3m - 1 AS ret_3m,
  105. cumulative_nav \ nav_6m - 1 AS ret_6m,
  106. cumulative_nav \ nav_1y - 1 AS ret_1y,
  107. cumulative_nav \ nav_2y - 1 AS ret_2y,
  108. cumulative_nav \ nav_3y - 1 AS ret_3y,
  109. cumulative_nav \ nav_4y - 1 AS ret_4y,
  110. cumulative_nav \ nav_5y - 1 AS ret_5y,
  111. cumulative_nav \ nav_10y - 1 AS ret_10y,
  112. cumulative_nav \ nav_ytd - 1 AS ret_ytd,
  113. cumulative_nav \ nav_incep - 1 AS ret_incep, inception_date
  114. FROM tb_nav;
  115. // NOTE: this is to keep consistance with MySQL, even it is NOT complied with GIPS standard
  116. UPDATE tb_rets SET ret_1m_a = (1 + ret_1m).pow(12\1) - 1, ret_3m_a = (1 + ret_3m).pow(12\3) - 1, ret_6m_a = (1 + ret_6m).pow(12\6) - 1,
  117. ret_1y_a= ret_1y, ret_2y_a = (1 + ret_2y).pow(12\24) - 1, ret_3y_a = (1 + ret_3y).pow(12\36) - 1,
  118. ret_4y_a = (1 + ret_4y).pow(12\48) - 1, ret_5y_a = (1 + ret_5y).pow(12\60) - 1, ret_10y_a = (1 + ret_10y).pow(12\120) - 1,
  119. ret_ytd_a = (1 + ret_ytd).pow(12\int(temporalFormat(end_date, 'MM')))-1,
  120. ret_incep_a = (1 + ret_incep).pow(12\(end_date - inception_date.month())) - 1,
  121. ret_incep_a_all = (1 + ret_incep).pow(12\(end_date - inception_date.month()))- 1,
  122. ret_incep_a_gips = iif(end_date - inception_date.month() < 12, ret_incep,
  123. (1 + ret_incep).pow(12\(end_date - inception_date.month()))- 1);
  124. return tb_rets;
  125. }
  126. /*
  127. * 批量计算公募历史基金月度收益(fund_performance)
  128. * NOTE: 任何数据频率快于或等于月度的净值数据都可以用此函数一次性计算完整历史记录。双月频、季频甚至更低频率的基金只能按月计算
  129. *
  130. * cal_mutual_fund_performance("'HF000004KN','HF00018WXG','HF000103EU'", true)
  131. *
  132. */
  133. def cal_mutual_fund_performance(fund_ids, isFromMySQL) {
  134. // 计算月收益
  135. tb_tmp = cal_fund_monthly_returns('MF', fund_ids, isFromMySQL);
  136. tb_rets = SELECT fund_id, end_date, ret_1m,
  137. (1 + ret_1m).mprod(3) - 1 AS ret_3m, (1 + ret_1m).mprod(6) - 1 AS ret_6m, (1 + ret_1m).mprod(12) - 1 AS ret_1y,
  138. (1 + ret_1m).mprod(24) - 1 AS ret_2y, (1 + ret_1m).mprod(36) - 1 AS ret_3y, (1 + ret_1m).mprod(48) - 1 AS ret_4y,
  139. (1 + ret_1m).mprod(60) - 1 AS ret_5y, (1 + ret_1m).mprod(120) - 1 AS ret_10y
  140. FROM tb_tmp
  141. CONTEXT BY fund_id;
  142. // NOTE: this is to keep consistance with MySQL, even it is NOT complied with GIPS standard
  143. UPDATE tb_rets SET ret_1m_a = (1 + ret_1m).pow(12) - 1, ret_3m_a = (1 + ret_3m).pow(4) - 1, ret_6m_a = (1 + ret_6m).pow(2) - 1, ret_1y_a= ret_1y,
  144. ret_2y_a = (1 + ret_2y).pow(1\2) - 1, ret_3y_a = (1 + ret_3y).pow(1\3) - 1, ret_4y_a = (1 + ret_4y).pow(1\4) - 1,
  145. ret_5y_a = (1 + ret_5y).pow(1\5) - 1, ret_10y_a = (1 + ret_10y).pow(1\10) - 1;
  146. // ytd 不会用上面的CONTEXT BY语句实现
  147. tb_ret_ytd = SELECT a.fund_id, a.end_date, a.price_date, a.cumulative_nav, -1 + a.cumulative_nav \ b.cumulative_nav AS ret_ytd,
  148. (a.cumulative_nav \ b.cumulative_nav).pow(12\(a.end_date - b.end_date)) - 1 AS ret_ytd_a
  149. FROM tb_rets a
  150. INNER JOIN tb_rets b ON a.fund_Id = b.fund_id
  151. AND b.end_date = a.price_date.yearEnd().datetimeAdd(-1y).month()
  152. // since inception 不会用上面的CONTEXT BY语句实现
  153. tb_ret_incep = SELECT a.fund_id, a.end_date, a.price_date, cumulative_nav, -1 + cumulative_nav \ ini_value AS ret_incep
  154. FROM tb_rets a
  155. INNER JOIN tb_fund_info fi ON a.fund_id = fi.fund_id
  156. UPDATE tb_ret_incep SET ret_incep_a = (1 + ret_incep).pow(12\(end_date - end_date.first())) - 1 CONTEXT BY fund_Id
  157. UPDATE tb_ret_incep SET ret_incep_a_gips = iif( end_date - end_date.first() < 12, ret_incep, ret_incep_a ), ret_incep_a_all = ret_incep_a CONTEXT BY fund_id
  158. // 只选需要更新的记录
  159. tb_fund_performance = SELECT a.fund_id, a.end_date.datetimeFormat("yyyy-MM") AS end_date, c.price_date, c.cumulative_nav,
  160. a.ret_1m, a.ret_1m_a, a.ret_3m, a.ret_3m_a, a.ret_6m, a.ret_6m_a,
  161. a.ret_1y, a.ret_1y_a, a.ret_2y, a.ret_2y_a, a.ret_3y, a.ret_3y_a,
  162. a.ret_4y, a.ret_4y_a, a.ret_5y, a.ret_5y_a, a.ret_10y, a.ret_10y_a,
  163. b.ret_ytd, b.ret_ytd_a, c.ret_incep, c.ret_incep_a, c.ret_incep_a_all, c.ret_incep_a_gips
  164. // , 123 AS creatorid, now() AS createtime, 123 AS updaterid, now() AS updatetime, 1 AS isvalid
  165. FROM tb_rets a
  166. LEFT JOIN tb_ret_ytd b ON a.fund_id = b.fund_id AND a.end_date = b.end_date
  167. LEFT JOIN tb_ret_incep c ON a.fund_id = c.fund_id AND a.end_date = c.end_date
  168. WHERE c.price_date IS NOT NULL
  169. ORDER BY a.fund_id, c.price_date
  170. /*
  171. // 把这些数据写回mySQL数据表
  172. save_table(tb_fund_performance, "mfdb.fund_performance", true)
  173. // 把这些数据写到本地数据表
  174. save_table(tb_fund_performance, "mfdb.fund_performance", false)
  175. */
  176. return tb_fund_performance
  177. }
  178. /*
  179. * 批量计算私募基金周收益
  180. * TODO: 需要用每周最后一个交易日?
  181. *
  182. * cal_hedge_fund_weekly_returns("'HF000004KN','HF00018WXG','HF000103EU'", true)
  183. *
  184. */
  185. def cal_hedge_fund_weekly_returns(fund_ids, isFromMySQL) {
  186. // 用于保证老基金也能取到所有历史净值
  187. very_old_price_date = 1990.01.01
  188. tb_nav = get_nav_by_price_date('HF', fund_ids, very_old_price_date, isFromMySQL)
  189. UPDATE tb_nav SET year_week = price_date.year()$STRING + (price_date.weekOfYear()$STRING).lpad(2, "0")
  190. tb_weekly_nav = SELECT fund_id, year_week, price_date.last() AS price_date, cumulative_nav.last() AS cumulative_nav
  191. FROM tb_nav
  192. GROUP BY fund_id, year_week
  193. ORDER BY fund_id, year_week
  194. // 这里选最简单的计算方式:不补任何净值空洞,净值前值日期不做任何限制
  195. // TODO: 可以考虑将月收益也改为这种方式
  196. tb_rets_1w = SELECT fund_id, year_week, price_date, cumulative_nav, cumulative_nav.ratios()-1 AS ret_1w
  197. FROM tb_weekly_nav
  198. ORDER BY fund_id, year_week
  199. return tb_rets_1w
  200. }
  201. /*
  202. * 批量计算私募基金区间收益
  203. * TODO: mySQL version 向前取4天,向后不做限制。这里的逻辑是向前取4个交易日
  204. *
  205. * get_trailing_return(tb_last_nav, tb_nav, -7d, "ret_1w")
  206. *
  207. */
  208. def get_trailing_return(table_last_nav, table_nav, duration, return_column_name) {
  209. tb = SELECT a.fund_id, a.price_date.last() AS price_date, a.cumulative_nav.last() \ b.cumulative_nav.last() - 1 AS ret
  210. FROM table_last_nav a
  211. INNER JOIN table_nav b ON a.fund_id = b.fund_id
  212. WHERE b.price_date <= a.price_date.datetimeAdd(duration)
  213. AND b.price_date >= a.price_date.datetimeAdd(duration).datetimeAdd(-4d).businessDay()
  214. GROUP by a.fund_id
  215. ORDER BY fund_id
  216. tb.rename!("ret", return_column_name)
  217. return tb
  218. }
  219. /*
  220. * 批量计算私募基金最新收益
  221. *
  222. *
  223. * cal_hedge_fund_weekly_returns("'HF000004KN','HF00018WXG','HF000103EU'", true)
  224. *
  225. */
  226. def cal_hedge_fund_latest_returns(fund_ids, isFromMySQL) {
  227. // 用于保证老基金也能取到所有历史净值
  228. very_old_price_date = 1990.01.01
  229. tb_nav = get_nav_by_price_date('HF', fund_ids, very_old_price_date, isFromMySQL)
  230. tb_last_nav = SELECT fund_id, price_date.last() AS price_date, cumulative_nav.last() AS cumulative_nav
  231. FROM tb_nav
  232. GROUP BY fund_id
  233. ORDER BY fund_id
  234. // 近1期收益,对应mySQL fund_latest_nav_performance 中的 net_value_change
  235. // 因为是倒序,所以算出来的 ratios() = n0 / n1, 要把它改换成 n1 / n0 - 1 的收益
  236. tb_last_return = SELECT TOP 2 fund_id, price_date.first() AS price_date, price_date AS pre_preice_date,
  237. cumulative_nav.first() AS cumulative_nav, 1\cumulative_nav.ratios() - 1 AS net_value_change
  238. FROM ( SELECT * FROM tb_nav ORDER BY price_date DESC )
  239. CONTEXT BY fund_id
  240. ORDER BY fund_id
  241. tb_last_return = SELECT * FROM tb_last_return WHERE net_value_change IS NOT NULL
  242. // 近1交易日收益
  243. tb_1d = SELECT a.fund_id, a.price_date, a.cumulative_nav \ b.cumulative_nav - 1 AS ret_1d
  244. FROM tb_last_nav a
  245. INNER JOIN tb_nav b ON a.fund_id = b.fund_id AND b.price_date = a.price_date.datetimeAdd(-1d).businessDay()
  246. ORDER BY fund_id
  247. // 近1周、1/3/6月、1/2/3/4/5/10年收益
  248. tb_1w = get_trailing_return(tb_last_nav, tb_nav, -7d, "ret_1w")
  249. tb_1m = get_trailing_return(tb_last_nav, tb_nav, -1M, "ret_1m")
  250. tb_3m = get_trailing_return(tb_last_nav, tb_nav, -3M, "ret_3m")
  251. tb_6m = get_trailing_return(tb_last_nav, tb_nav, -6M, "ret_6m")
  252. tb_1y = get_trailing_return(tb_last_nav, tb_nav, -1y, "ret_1y")
  253. tb_2y = get_trailing_return(tb_last_nav, tb_nav, -2y, "ret_2y")
  254. tb_3y = get_trailing_return(tb_last_nav, tb_nav, -3y, "ret_3y")
  255. tb_4y = get_trailing_return(tb_last_nav, tb_nav, -4y, "ret_4y")
  256. tb_5y = get_trailing_return(tb_last_nav, tb_nav, -5y, "ret_5y")
  257. tb_10y = get_trailing_return(tb_last_nav, tb_nav, -10y, "ret_10y")
  258. // ytd return
  259. tb_ytd = SELECT a.fund_id, a.price_date.last() AS price_date, a.cumulative_nav.last() \ b.cumulative_nav.last() - 1 AS ret_ytd
  260. FROM tb_last_nav a
  261. INNER JOIN tb_nav b ON a.fund_id = b.fund_id
  262. WHERE b.price_date < a.price_date.yearBegin()
  263. AND b.price_date >= a.price_date.yearBegin().datetimeAdd(-4d)
  264. GROUP by a.fund_id
  265. // since inception return
  266. tb_fund_info = get_fund_info(fund_ids)
  267. tb_incep = SELECT a.fund_id, a.price_date, -1 + cumulative_nav \ ini_value AS ret_incep, fi.inception_date
  268. FROM tb_last_nav a
  269. INNER JOIN tb_fund_info fi ON a.fund_id = fi.fund_id
  270. // annulized since reception return
  271. UPDATE tb_incep SET ret_incep_a = (1 + ret_incep).pow(365.25\(price_date-inception_date)) - 1
  272. UPDATE tb_incep SET ret_incep_a_all = ret_incep_a,
  273. ret_incep_a_gips = iif((price_date-inception_date)<365, ret_incep, ret_incep_a)
  274. // 最大回撤
  275. tb_drawdown_1m = SELECT a.fund_id, max( 1 - b.cumulative_nav \ b.cumulative_nav.cummax() ) AS drawdown_1m
  276. FROM tb_last_return a
  277. INNER JOIN tb_nav b ON a.fund_id = b.fund_id
  278. WHERE b.price_date >= a.price_date.datetimeAdd(-1M)
  279. GROUP BY a.fund_id
  280. tb_drawdown_3m = SELECT a.fund_id, max( 1 - b.cumulative_nav \ b.cumulative_nav.cummax() ) AS drawdown_3m
  281. FROM tb_last_return a
  282. INNER JOIN tb_nav b ON a.fund_id = b.fund_id
  283. WHERE b.price_date >= a.price_date.datetimeAdd(-3M)
  284. GROUP BY a.fund_id
  285. tb_drawdown_incep = SELECT fund_id, max( 1 - cumulative_nav \ cumulative_nav.cummax() ) AS drawdown_incep
  286. FROM tb_nav GROUP BY fund_id
  287. tb_rets = SELECT a.fund_id, a.price_date.datetimeFormat("yyyy-MM") AS end_date, a.price_date, a.pre_preice_date, a.cumulative_nav,
  288. a.net_value_change, d1.ret_1d, w1.ret_1w, m1.ret_1m, m3.ret_3m, m6.ret_6m,
  289. y1.ret_1y, y2.ret_2y, y3.ret_3y, y4.ret_4y, y5.ret_5y, y10.ret_10y,
  290. ytd.ret_ytd, incep.ret_incep, incep.ret_incep_a, incep.ret_incep_a_all, incep.ret_incep_a_gips,
  291. dd_m1.drawdown_1m AS maxdrawdown_1m, dd_m3.drawdown_3m AS maxdrawdown_3m,
  292. dd_incep.drawdown_incep AS maxdrawdown_incep,
  293. iif(dd_incep.drawdown_incep == 0, null,incep.ret_incep_a \ dd_incep.drawdown_incep) AS calmarratio_incep
  294. FROM tb_last_return a
  295. LEFT JOIN tb_1d d1 ON a.fund_id = d1.fund_id
  296. LEFT JOIN tb_1w w1 ON a.fund_id = w1.fund_id
  297. LEFT JOIN tb_1m m1 ON a.fund_id = m1.fund_id
  298. LEFT JOIN tb_3m m3 ON a.fund_id = m3.fund_id
  299. LEFT JOIN tb_6m m6 ON a.fund_id = m6.fund_id
  300. LEFT JOIN tb_1y y1 ON a.fund_id = y1.fund_id
  301. LEFT JOIN tb_2y y2 ON a.fund_id = y2.fund_id
  302. LEFT JOIN tb_3y y3 ON a.fund_id = y3.fund_id
  303. LEFT JOIN tb_4y y4 ON a.fund_id = y4.fund_id
  304. LEFT JOIN tb_5y y5 ON a.fund_id = y5.fund_id
  305. LEFT JOIN tb_10y y10 ON a.fund_id = y10.fund_id
  306. LEFT JOIN tb_ytd ytd ON a.fund_id = ytd.fund_id
  307. LEFT JOIN tb_incep incep ON a.fund_id = incep.fund_id
  308. LEFT JOIN tb_drawdown_1m dd_m1 ON a.fund_id = dd_m1.fund_id
  309. LEFT JOIN tb_drawdown_3m dd_m3 ON a.fund_id = dd_m3.fund_id
  310. LEFT JOIN tb_drawdown_incep dd_incep ON a.fund_id = dd_incep.fund_id
  311. ORDER BY a.fund_id
  312. // 忽略掉非GIPS标准的所有年化收益字段(包括ytd_a)
  313. UPDATE tb_rets SET ret_1y_a = ret_1y, ret_2y_a = (1 + ret_2y).pow(1\2) - 1, ret_3y_a = (1 + ret_3y).pow(1\3) - 1,
  314. ret_4y_a = (1 + ret_4y).pow(1\4) - 1, ret_5y_a = (1 + ret_5y).pow(1\5) - 1, ret_10y_a = (1 + ret_10y).pow(1\10) - 1
  315. return tb_rets
  316. }