task_portfolioPerformance.dos 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. module fundit::task_portfolioPerformance
  2. use fundit::sqlUtilities;
  3. use fundit::operationDataPuller;
  4. use fundit::performanceDataPuller;
  5. use fundit::portfolioDataPuller;
  6. use fundit::dataSaver;
  7. use fundit::navCalculator;
  8. use fundit::returnCalculator;
  9. use fundit::indicatorCalculator;
  10. /*
  11. * 计算组合历史净值(不存数据库)
  12. *
  13. * @param portfolio_ids <STRING|VECTOR>: 组合IDS,为空时跑全集(但不建议,因为可能会很吃内存)
  14. * @param updatetime <DATETIME>: 持仓证券净值更新时间,忽略时跑全历史
  15. *
  16. * @return <TABLE>: portfolio_id, price_date, ret, nav
  17. *
  18. * Example:calPortfolioNAV([143109, 145041]);
  19. * calPortfolioNAV([143109, 145041], 2024.10.28);
  20. */
  21. def calPortfolioNAV(portfolio_ids, updatetime=1900.01.01) {
  22. // portfolio_ids=[364743, 364744];
  23. // updatetime=1900.01.01;
  24. port_info = get_portfolio_list_by_fund_nav_updatetime(portfolio_ids, updatetime, true);
  25. tb_nav = cal_portfolio_nav(port_info);
  26. return tb_nav;
  27. }
  28. /*
  29. * 计算组合历史收益和指标(不存数据库)
  30. *
  31. * @param navs <TABLE>: NEED COLUMNS portfolio_id, price_date, ret, nav
  32. *
  33. * @return <DICTIONARY>:
  34. *
  35. * Example:calPortfolioPerformance(calPortfolioNAV([143109, 145041]));
  36. */
  37. def calPortfolioPerformance(navs) {
  38. if(navs.isVoid() || navs.size() == 0) return;
  39. tb_navs = navs;
  40. tb_navs.rename!(['portfolio_id'], ['entity_id']);
  41. port_ids = EXEC DISTINCT entity_id from tb_navs;
  42. port_info = get_entity_info('PF', port_ids);
  43. // 这个函数会根据情况加入成立日当月的初始净值,比直接用navs表中可能带的ret更方便
  44. tb_navs.rename!('nav', 'cumulative_nav');
  45. tb_month_ret = cal_monthly_returns_by_nav(port_info, tb_navs);
  46. tb_month_ret.rename!('cumulative_nav', 'nav');
  47. indicators = cal_monthly_indicators('PF', 'PBI', tb_month_ret);
  48. return indicators;
  49. }
  50. /*
  51. * 计算组合历史收益和指标(不存数据库)
  52. *
  53. * @param navs <TABLE>: NEED COLUMNS entity_id, price_date, ret, nav
  54. *
  55. * @return <DICTIONARY>:
  56. *
  57. * Example:calEntityPerformance('PF', calPortfolioNAV([143109, 145041]));
  58. */
  59. def calEntityPerformance(entity_type, navs) {
  60. if(navs.isVoid() || navs.size() == 0) return;
  61. tb_navs = navs;
  62. //tb_navs.rename!(['portfolio_id'], ['entity_id']);
  63. entity_ids = EXEC DISTINCT entity_id from tb_navs;
  64. entity_info = get_entity_info(entity_type, entity_ids);
  65. // 这个函数会根据情况加入成立日当月的初始净值,比直接用navs表中可能带的ret更方便
  66. tb_navs.rename!('nav', 'cumulative_nav');
  67. tb_month_ret = cal_monthly_returns_by_nav(entity_info, tb_navs);
  68. tb_month_ret.rename!('cumulative_nav', 'nav');
  69. indicators = cal_monthly_indicators(entity_type, 'PBI', tb_month_ret);
  70. return indicators;
  71. }
  72. /*
  73. * 计算组合净值并存入数据库
  74. *
  75. * TODO: release 时改变同步目标表为正式表
  76. */
  77. def cal_and_save_portfolio_nav(cal_portfolio_info, is_save_local) {
  78. rt = '';
  79. // 准备类似MySQL结构的数据表
  80. tb_portfolio_nav = create_entity_nav(true);
  81. // 分批跑
  82. i = 0;
  83. batch_size = 1000;
  84. all_portfolio_id = EXEC DISTINCT portfolio_id FROM cal_portfolio_info;
  85. do { // 先把净值算出来存入数据库,落袋为安
  86. portfolio_info = SELECT * FROM cal_portfolio_info
  87. WHERE portfolio_id IN all_portfolio_id[i : min(all_portfolio_id.size(), i+batch_size)];
  88. if(portfolio_info.isVoid() || portfolio_info.size() == 0) break;
  89. // 30 sec per 1000 portfolios
  90. tb_ret = cal_portfolio_nav(portfolio_info);
  91. INSERT INTO tb_portfolio_nav SELECT entity_id, price_date, nav FROM tb_ret;
  92. i += batch_size;
  93. } while (i <= cal_portfolio_info.size());
  94. if(! tb_portfolio_nav.isVoid() && tb_portfolio_nav.size() > 0) {
  95. // save data to MySQL (12 sec)
  96. try {
  97. tb_portfolio_nav.rename!('entity_id', 'portfolio_id');
  98. save_and_sync(tb_portfolio_nav, 'raw_db.pf_portfolio_nav', 'raw_db.pf_portfolio_nav');
  99. // 数据初始化时将指标存入本地
  100. if(is_save_local == true) {
  101. save_table(tb_portfolio_nav, 'pfdb.pf_portfolio_nav', false);
  102. }
  103. } catch(ex) {
  104. //TODO: Log errors
  105. rt = ex;
  106. }
  107. }
  108. return rt;
  109. }
  110. /*
  111. * 计算组合标准指标并存入数据库
  112. *
  113. * TODO: release 时改变同步目标表为正式表
  114. */
  115. def cal_and_save_portfolio_indicators(cal_portfolio_info, is_save_local) {
  116. rt = '';
  117. // 准备类似MySQL结构的数据表
  118. tb_portfolio_performance = create_entity_performance(true);
  119. tb_portfolio_indicator = create_entity_indicator(true);
  120. tb_portfolio_risk_stats = create_entity_risk_stats(true);
  121. tb_portfolio_riskadjret_stats = create_entity_riskadjret_stats(true);
  122. tb_portfolio_style_stats = create_entity_style_stats(true);
  123. tb_portfolio_performance_weekly = create_entity_performance_weekly(true);
  124. tb_portfolio_latest_performance = create_entity_latest_performance(true);
  125. // 分批跑
  126. i = 0;
  127. batch_size = 1000;
  128. all_portfolio_id = EXEC DISTINCT portfolio_id FROM cal_portfolio_info;
  129. do {
  130. cal_port = SELECT * FROM cal_portfolio_info
  131. WHERE portfolio_id IN all_portfolio_id[i : min(all_portfolio_id.size(), i+batch_size)];
  132. if(cal_port.isVoid() || cal_port.size() == 0) break;
  133. // 取数据库月度净值及前值 5 sec
  134. s_json = (SELECT portfolio_id, 1900.01.01 AS price_date FROM cal_port GROUP BY portfolio_id).rename!('portfolio_id', 'sec_id').toStdJson();
  135. tb_monthly_nav = get_nav_for_return_calculation('PF', 'm', s_json);
  136. // 把 portfolio id 字段从字符串换回整型,不然后面Join table的时候会出错
  137. v_portfolio_id = tb_monthly_nav.sec_id$INT;
  138. tb_monthly_nav.replaceColumn!('sec_id', v_portfolio_id);
  139. tb_monthly_nav.dropColumns!('nav').rename!(['sec_id', 'cumulative_nav'], ['portfolio_id', 'nav']);
  140. // 计算各标准指标
  141. indicators = calPortfolioPerformance(tb_monthly_nav);
  142. // 仿照MySQL的表结构准备好记录 (1s)
  143. port_info = (SELECT portfolio_id, start_cal_date.min() AS price_date FROM cal_port GROUP BY portfolio_id).rename!('portfolio_id', 'entity_id');
  144. generate_entity_performance(port_info, indicators, true, tb_portfolio_performance);
  145. generate_entity_indicator(port_info, indicators, true, tb_portfolio_indicator);
  146. generate_entity_risk_stats(port_info, indicators, true, tb_portfolio_risk_stats);
  147. generate_entity_riskadjret_stats(port_info, indicators, true, tb_portfolio_riskadjret_stats);
  148. generate_entity_style_stats(port_info, indicators, true, tb_portfolio_style_stats);
  149. // 计算周收益 (49s)
  150. port_info = SELECT * FROM ej(port_info, get_entity_info('PF', all_portfolio_id[i : min(all_portfolio_id.size(), i+batch_size)]), 'entity_id')
  151. rets_w = cal_weekly_returns('PF', port_info);
  152. if(! rets_w.isVoid() && rets_w.size() > 0) {
  153. // 把 portfolio id 字段从字符串换回整型,不然后面Join table的时候会出错
  154. v_portfolio_id = rets_w.entity_id$INT;
  155. rets_w.replaceColumn!('entity_id', v_portfolio_id);
  156. generate_entity_performance_weekly(port_info, rets_w, true, tb_portfolio_performance_weekly);
  157. }
  158. // 计算最新收益 (23s)
  159. perf_latest = cal_latest_performance('PF', port_info, true);
  160. if(! perf_latest.isVoid() && perf_latest.size() > 0) {
  161. generate_entity_latest_performance(port_info, perf_latest, true, tb_portfolio_latest_performance);
  162. }
  163. i += batch_size;
  164. } while (i <= cal_portfolio_info.size());
  165. if(! tb_portfolio_performance.isVoid() && tb_portfolio_performance.size() > 0) {
  166. // save data to MySQL
  167. try {
  168. chg_columns_for_mysql(tb_portfolio_performance, 'portfolio_id');
  169. save_and_sync(tb_portfolio_performance, 'raw_db.pf_portfolio_performance', 'raw_db.pf_portfolio_performance');
  170. chg_columns_for_mysql(tb_portfolio_indicator, 'portfolio_id');
  171. save_and_sync(tb_portfolio_indicator, 'raw_db.pf_portfolio_indicator', 'raw_db.pf_portfolio_indicator');
  172. chg_columns_for_mysql(tb_portfolio_risk_stats, 'portfolio_id');
  173. save_and_sync(tb_portfolio_risk_stats, 'raw_db.pf_portfolio_risk_stats', 'raw_db.pf_portfolio_risk_stats');
  174. chg_columns_for_mysql(tb_portfolio_riskadjret_stats, 'portfolio_id');
  175. save_and_sync(tb_portfolio_riskadjret_stats, 'raw_db.pf_portfolio_riskadjret_stats', 'raw_db.pf_portfolio_riskadjret_stats');
  176. chg_columns_for_mysql(tb_portfolio_style_stats, 'portfolio_id');
  177. save_and_sync(tb_portfolio_style_stats, 'raw_db.pf_portfolio_style_stats', 'raw_db.pf_portfolio_style_stats');
  178. save_and_sync(tb_portfolio_performance_weekly, 'raw_db.pf_portfolio_performance_weekly', 'raw_db.pf_portfolio_performance_weekly');
  179. save_and_sync(tb_portfolio_latest_performance, 'raw_db.pf_portfolio_latest_performance', 'raw_db.pf_portfolio_latest_performance');
  180. // 数据初始化时将指标存入本地
  181. if(is_save_local == true) {
  182. save_table(tb_portfolio_performance, 'pfdb.pf_portfolio_performance', false);
  183. save_table(tb_portfolio_indicator, 'pfdb.pf_portfolio_indicator', false);
  184. save_table(tb_portfolio_risk_stats, 'pfdb.pf_portfolio_risk_stats', false);
  185. save_table(tb_portfolio_riskadjret_stats, 'pfdb.pf_portfolio_riskadjret_stats', false);
  186. save_table(tb_portfolio_style_stats, 'pfdb.pf_portfolio_style_stats', false);
  187. save_table(tb_portfolio_performance_weekly, 'pfdb.pf_portfolio_performance_weekly', false);
  188. save_table(tb_portfolio_latest_performance, 'pfdb.pf_portfolio_latest_performance', false);
  189. }
  190. } catch(ex) {
  191. //TODO: Log errors
  192. rt = ex;
  193. }
  194. }
  195. return rt;
  196. }
  197. /*
  198. * 通用计算标准指标并存入数据库
  199. *
  200. * TODO: release 时改变同步目标表为正式表
  201. */
  202. def cal_and_save_entity_indicators(entity_type, cal_entity_info, is_save_local) {
  203. // cal_entity_info = tb_cal_factors
  204. // entity_type = 'FA'
  205. rt = '';
  206. is_id_interger = iif(entity_type == 'PF', true, false);
  207. // 准备类似MySQL结构的数据表
  208. tb_entity_performance = create_entity_performance(is_id_interger);
  209. tb_entity_indicator = create_entity_indicator(is_id_interger);
  210. tb_entity_risk_stats = create_entity_risk_stats(is_id_interger);
  211. tb_entity_riskadjret_stats = create_entity_riskadjret_stats(is_id_interger);
  212. tb_entity_style_stats = create_entity_style_stats(is_id_interger);
  213. tb_entity_performance_weekly = create_entity_performance_weekly(is_id_interger);
  214. tb_entity_latest_performance = create_entity_latest_performance(is_id_interger);
  215. // 分批跑
  216. i = 0;
  217. batch_size = 1000;
  218. all_entity_id = EXEC DISTINCT entity_id FROM cal_entity_info;
  219. do {
  220. cal_entity = SELECT * FROM cal_entity_info
  221. WHERE entity_id IN all_entity_id[i : min(all_entity_id.size(), i+batch_size)];
  222. if(cal_entity.isVoid() || cal_entity.size() == 0) break;
  223. // 取数据库月度净值及前值 5 sec
  224. s_json = (SELECT entity_id, 1900.01.01 AS price_date FROM cal_entity GROUP BY entity_id).rename!('entity_id', 'sec_id').toStdJson();
  225. tb_monthly_nav = get_nav_for_return_calculation(entity_type, 'm', s_json);
  226. // 把组合 entity id 字段从字符串换回整型,不然后面Join table的时候会出错
  227. if(entity_type=='PF') {
  228. v_entity_id = tb_monthly_nav.sec_id$INT;
  229. tb_monthly_nav.replaceColumn!('sec_id', v_entity_id);
  230. }
  231. tb_monthly_nav.dropColumns!('nav').rename!(['sec_id', 'cumulative_nav'], ['entity_id', 'nav']);
  232. // 计算各标准指标
  233. indicators = calEntityPerformance(entity_type, tb_monthly_nav);
  234. // 仿照MySQL的表结构准备好记录 (1s)
  235. entity_info = (SELECT entity_id, start_cal_date.min() AS price_date FROM cal_entity GROUP BY entity_id);
  236. generate_entity_performance(entity_info, indicators, true, tb_entity_performance);
  237. generate_entity_indicator(entity_info, indicators, true, tb_entity_indicator);
  238. generate_entity_risk_stats(entity_info, indicators, true, tb_entity_risk_stats);
  239. generate_entity_riskadjret_stats(entity_info, indicators, true, tb_entity_riskadjret_stats);
  240. generate_entity_style_stats(entity_info, indicators, true, tb_entity_style_stats);
  241. // 计算周收益 (49s)
  242. entity_info = SELECT * FROM ej(entity_info, get_entity_info(entity_type, all_entity_id[i : min(all_entity_id.size(), i+batch_size)]), 'entity_id')
  243. rets_w = cal_weekly_returns(entity_type, entity_info);
  244. if(! rets_w.isVoid() && rets_w.size() > 0) {
  245. // 把 entity id 字段从字符串换回整型,不然后面Join table的时候会出错
  246. if(entity_type == 'PF') {
  247. v_entity_id = rets_w.entity_id$INT;
  248. rets_w.replaceColumn!('entity_id', v_entity_id);
  249. }
  250. generate_entity_performance_weekly(entity_info, rets_w, true, tb_entity_performance_weekly);
  251. }
  252. // 计算最新收益 (23s)
  253. perf_latest = cal_latest_performance(entity_type, entity_info, true);
  254. if(! perf_latest.isVoid() && perf_latest.size() > 0) {
  255. generate_entity_latest_performance(entity_info, perf_latest, true, tb_entity_latest_performance);
  256. }
  257. i += batch_size;
  258. } while (i <= cal_entity_info.size());
  259. if(! tb_entity_performance.isVoid() && tb_entity_performance.size() > 0) {
  260. // save data to MySQL
  261. try {
  262. des = get_performance_table_description(entity_type)[0];
  263. chg_columns_for_mysql(tb_entity_performance, des.sec_id_col);
  264. tb_entity_performance.rename!('cumulative_nav', des.cumulative_nav_col);
  265. save_and_sync(tb_entity_performance, des.table_name.strReplace('pfdb', 'raw_db').strReplace('mfdb', 'raw_db'), );
  266. if(is_save_local == true) save_table(tb_entity_performance, des.table_name, false);
  267. des = get_indicator_table_description(entity_type)[0];
  268. chg_columns_for_mysql(tb_entity_indicator, des.sec_id_col);
  269. save_and_sync(tb_entity_indicator, des.table_name.strReplace('pfdb', 'raw_db').strReplace('mfdb', 'raw_db'), );
  270. if(is_save_local == true) save_table(tb_entity_indicator, des.table_name, false);
  271. des = get_risk_stats_table_description(entity_type)[0];
  272. chg_columns_for_mysql(tb_entity_risk_stats, des.sec_id_col);
  273. save_and_sync(tb_entity_risk_stats, des.table_name.strReplace('pfdb', 'raw_db').strReplace('mfdb', 'raw_db'), );
  274. if(is_save_local == true) save_table(tb_entity_risk_stats, des.table_name, false);
  275. des = get_riskadjret_stats_table_description(entity_type)[0];
  276. chg_columns_for_mysql(tb_entity_riskadjret_stats, des.sec_id_col);
  277. save_and_sync(tb_entity_riskadjret_stats, des.table_name.strReplace('pfdb', 'raw_db').strReplace('mfdb', 'raw_db'), );
  278. if(is_save_local == true) save_table(tb_entity_riskadjret_stats, des.table_name, false);
  279. des = get_capture_style_table_description(entity_type)[0];
  280. chg_columns_for_mysql(tb_entity_style_stats, des.sec_id_col);
  281. save_and_sync(tb_entity_style_stats, des.table_name.strReplace('pfdb', 'raw_db').strReplace('mfdb', 'raw_db'), );
  282. if(is_save_local == true) save_table(tb_entity_style_stats, des.table_name, false);
  283. des = get_performance_weekly_table_description(entity_type)[0];
  284. tb_entity_performance_weekly.rename!('cumulative_nav', des.cumulative_nav_col);
  285. save_and_sync(tb_entity_performance_weekly, des.table_name.strReplace('pfdb', 'raw_db').strReplace('mfdb', 'raw_db'), );
  286. if(is_save_local == true) save_table(tb_entity_performance_weekly, des.table_name, false);
  287. des = get_latest_performance_table_description(entity_type)[0];
  288. tb_entity_latest_performance.rename!('cumulative_nav', des.cumulative_nav_col);
  289. save_and_sync(tb_entity_latest_performance, des.table_name.strReplace('pfdb', 'raw_db').strReplace('mfdb', 'raw_db'), );
  290. if(is_save_local == true) save_table(tb_entity_latest_performance, des.table_name, false);
  291. } catch(ex) {
  292. //TODO: Log errors
  293. rt = ex;
  294. }
  295. }
  296. return rt;
  297. }
  298. /*
  299. * [定时任务]批量计算组合净值、收益及指标
  300. *
  301. * @param updatetime <DATETIME>: 持仓证券净值更新时间,忽略或传入1989.01.01及更早的日期被认为在做数据初始化
  302. *
  303. *
  304. * Example: CalPortfolioPerformanceTask(2024.10.28);
  305. * CalPortfolioPerformanceTask(1989.01.01); -- 【初始化专用】 (45min)
  306. */
  307. def CalPortfolioPerformanceTask(updatetime) {
  308. rt = '';
  309. // 3 min
  310. tb_cal_ports = get_portfolio_list_by_fund_nav_updatetime(NULL, updatetime, true);
  311. if(tb_cal_ports.isVoid() || tb_cal_ports.size() == 0) return;
  312. is_save_local = iif(updatetime <= get_ini_data_const()['date'], true, false);
  313. // 26 min
  314. rt = cal_and_save_portfolio_nav(tb_cal_ports, is_save_local);
  315. // 9 min
  316. rt = rt + '; ' + cal_and_save_entity_indicators('PF', tb_cal_ports, is_save_local);
  317. return rt;
  318. }
  319. /*
  320. * 批量计算BFI因子净值
  321. *
  322. * Example: cal_and_save_factor_nav(get_bfi_factor_list_by_index_nav_updatetime(['FA00000VMJ'], updatetime, true);, false);
  323. *
  324. */
  325. def cal_and_save_factor_nav(cal_factor_info, is_save_local) {
  326. ret = ''
  327. t_factor_value = table(100:0, ['factor_id', 'price_date', 'factor_value'], [SYMBOL, DATE, DOUBLE]);
  328. // 因子个数有限,用循环更简便
  329. for(factor in cal_factor_info) {
  330. v_factor_id = array(STRING, 0).append!(factor.factor_id);
  331. // 取因子成分指数
  332. tb_holdings = get_fixed_weight_portfolio_holding('FA', v_factor_id);
  333. UPDATE tb_holdings SET first_cal_date = first_cal_date, latest_cal_date = latest_cal_date
  334. FROM ej(tb_holdings, cal_factor_info, 'entity_id', 'factor_id');
  335. s_json = (SELECT sec_id, first_cal_date.min() AS price_date FROM tb_holdings GROUP BY sec_id).toStdJson();
  336. // 取含前值的成分指数点位
  337. tb_nav = get_nav_for_return_calculation('MI', 'd', s_json).sortBy!(['sec_id', 'price_date'], [1, 1]);
  338. // 计算每期收益
  339. UPDATE tb_nav SET ret = cumulative_nav.ratios() - 1 CONTEXT BY sec_id;
  340. t = SELECT h.entity_id, n.price_date, h.sec_id, n.ret, h.weight/100 AS weight
  341. FROM tb_holdings AS h
  342. INNER JOIN tb_nav AS n ON h.sec_id = n.sec_id
  343. ORDER BY h.entity_id, h.sec_id, n.price_date;
  344. t_factor = SELECT factor_id AS entity_id, first_cal_date, latest_cal_date FROM cal_factor_info WHERE factor_id = factor.factor_id;
  345. t_tmp = cal_nav_by_return('FA', t_factor, t);
  346. if(!t_tmp.isVoid() && t_tmp.size() > 0) {
  347. INSERT INTO t_factor_value
  348. SELECT entity_id AS factor_id, price_date, nav AS factor_value FROM cal_nav_by_return('FA', t_factor, t);
  349. }
  350. }
  351. if(! t_factor_value.isVoid() && t_factor_value.size() > 0) {
  352. save_and_sync(t_factor_value, 'raw_db.cm_factor_value', 'raw_db.cm_factor_value');
  353. if(is_save_local == true) {
  354. save_table(t_factor_value, 'pfdb.cm_factor_value', false);
  355. }
  356. }
  357. }
  358. /*
  359. * [定时任务]批量计算bfi因子净值、收益及指标
  360. *
  361. * @param updatetime <DATETIME>: 成分指数净值更新时间,忽略或传入1989.01.01及更早的日期被认为在做数据初始化
  362. *
  363. *
  364. * Example: CalFactorPerformanceTask(2024.10.28);
  365. * CalFactorPerformanceTask(1989.01.01); -- 【初始化专用】 (1.3 min)
  366. */
  367. def CalFactorPerformanceTask(updatetime) {
  368. rt = '';
  369. // 根据成分指数净值更新日期,取有影响的因子
  370. tb_cal_factors = get_bfi_factor_list_by_index_nav_updatetime(NULL, updatetime, true);
  371. if(tb_cal_factors.isVoid() || tb_cal_factors.size() == 0) return rt;
  372. is_save_local = iif(updatetime <= get_ini_data_const()['date'], true, false);
  373. // 26 min
  374. rt = cal_and_save_factor_nav(tb_cal_factors, is_save_local);
  375. // 9 min
  376. tb_cal_factors.rename!(['factor_id', 'first_cal_date', 'latest_cal_date'], ['entity_id', 'start_cal_date', 'end_cal_date']);
  377. rt = rt + '; ' + cal_and_save_entity_indicators('FA', tb_cal_factors, is_save_local);
  378. return rt;
  379. }