dataSaver.dos 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. module fundit::dataSaver
  2. use fundit::sqlUtilities
  3. /*
  4. * 存数据表到mySQL或本地dolphindb,原数据表会被TRUNCATE
  5. *
  6. * save_table(tb_fund_performance, "raw_db.fund_performance", false)
  7. */
  8. def save_table(tb, table_name, isToMySQL) {
  9. if(isToMySQL == true) {
  10. conn = connect_mysql('raw_db');
  11. odbc::execute(conn, "TRUNCATE TABLE " + table_name + "_dolphin");
  12. odbc::append(conn, tb, table_name + "_dolphin", false);
  13. conn.close();
  14. } else {
  15. db = get_local_database("fundit", table_name.split(".")[0]);
  16. //local_table = loadTable(db, table_name.split(".")[1]);
  17. saveTable(db, tb, table_name.split(".")[1]);
  18. }
  19. }
  20. /*
  21. * 【临时】 用于将dolphin table 存到 mysql
  22. *
  23. */
  24. def save_table2(tb, table_name, isCreateTable) {
  25. tb.addColumn(['creatorid', 'createtime', 'updaterid', 'updatetime'], [INT, DATETIME, INT, DATETIME]);
  26. conn = connect_mysql('raw_db');
  27. odbc::append(conn, tb, table_name , isCreateTable, false);
  28. conn.close()
  29. }
  30. /*
  31. * 存私募基金净值到本地dolphindb
  32. *
  33. * save_hedge_fund_nav_to_local(tb_nav)
  34. */
  35. def save_hedge_fund_nav_to_local(tb_nav) {
  36. save_table(tb_nav, "mfdb.nav", false)
  37. }
  38. /*
  39. * 将数据存到本地,之后传回MySQL并同步至正式表
  40. *
  41. *
  42. */
  43. def save_and_sync(table, source_table_name, target_table_name) {
  44. save_table(table, source_table_name, true);
  45. t_table_name = iif(target_table_name.isNothing(), source_table_name, target_table_name);
  46. s_query = "CALL raw_db.sp_sync_table_from_dolphin('" + source_table_name + "_dolphin', '" + t_table_name + "');"
  47. conn = connect_mysql('raw_db');
  48. odbc::execute(conn, s_query);
  49. conn.close();
  50. }
  51. /*
  52. * 建表 XXXX_nav
  53. */
  54. def create_entity_nav(is_id_integer=false) {
  55. return table(1000:0,
  56. ['entity_id', 'price_date', 'cumulative_nav'],
  57. [iif(is_id_integer, INT, SYMBOL), DATE, DOUBLE]);
  58. }
  59. /*
  60. * 建公司/经理净值表 XXXX_fitted_curve
  61. */
  62. def create_mc_fitted_curve() {
  63. return table(1000:0,
  64. ['entity_id', 'curve_type', 'strategy', 'end_date', 'cumulative_nav', 'fund_num'],
  65. [SYMBOL, INT, INT, STRING, DOUBLE, INT]);
  66. }
  67. /*
  68. * 建公司/经理业绩表 xxx_performance
  69. *
  70. */
  71. def create_mc_performance() {
  72. return table(1000:0,
  73. ['entity_id', 'curve_type', 'strategy', 'end_date', 'price_date', 'cumulative_nav',
  74. 'ret_1m', 'ret_1m_a', 'ret_3m', 'ret_3m_a', 'ret_6m', 'ret_6m_a',
  75. 'ret_1y', 'ret_1y_a', 'ret_2y', 'ret_2y_a', 'ret_3y', 'ret_3y_a', 'ret_4y', 'ret_4y_a',
  76. 'ret_5y', 'ret_5y_a', 'ret_10y', 'ret_10y_a', 'ret_ytd', 'ret_ytd_a', 'ret_incep', 'ret_incep_a'],
  77. [SYMBOL, INT, INT, MONTH, DATE, DOUBLE,
  78. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  79. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  80. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  81. }
  82. /*
  83. * 建表 XXXX_performance
  84. */
  85. def create_entity_performance(is_id_integer=false) {
  86. return table(1000:0,
  87. ['entity_id', 'end_date', 'price_date', 'cumulative_nav',
  88. 'ret_1m', 'ret_1m_a', 'ret_3m', 'ret_3m_a', 'ret_6m', 'ret_6m_a',
  89. 'ret_1y', 'ret_1y_a', 'ret_2y', 'ret_2y_a', 'ret_3y', 'ret_3y_a', 'ret_4y', 'ret_4y_a',
  90. 'ret_5y', 'ret_5y_a', 'ret_10y', 'ret_10y_a', 'ret_ytd', 'ret_ytd_a', 'ret_incep', 'ret_incep_a'],
  91. [iif(is_id_integer, INT, SYMBOL), MONTH, DATE, DOUBLE,
  92. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  93. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  94. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  95. }
  96. /*
  97. * 建表 XXX_indicator
  98. */
  99. def create_entity_indicator(is_id_integer=false) {
  100. return table(1000:0,
  101. ['entity_id', 'end_date',
  102. 'info_ratio_6m', 'm2_6m', 'tracking_error_6m',
  103. 'info_ratio_1y', 'm2_1y', 'tracking_error_1y',
  104. 'info_ratio_2y', 'm2_2y', 'tracking_error_2y', 'var_2y', 'cvar_2y',
  105. 'info_ratio_3y', 'm2_3y', 'tracking_error_3y', 'var_3y', 'cvar_3y',
  106. 'info_ratio_4y', 'm2_4y', 'tracking_error_4y', 'var_4y', 'cvar_4y',
  107. 'info_ratio_5y', 'm2_5y', 'tracking_error_5y', 'var_5y', 'cvar_5y',
  108. 'info_ratio_10y', 'm2_10y', 'tracking_error_10y', 'var_10y', 'cvar_10y',
  109. 'info_ratio_ytd', 'm2_ytd', 'tracking_error_ytd',
  110. 'info_ratio_incep', 'm2_incep','tracking_error_incep', 'var_incep', 'cvar_incep'],
  111. [iif(is_id_integer, INT, SYMBOL), MONTH,
  112. DOUBLE, DOUBLE, DOUBLE,
  113. DOUBLE, DOUBLE, DOUBLE,
  114. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  115. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  116. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  117. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  118. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  119. DOUBLE, DOUBLE, DOUBLE,
  120. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  121. }
  122. /*
  123. * 建公司/经理表 XXX_indicator
  124. */
  125. def create_mc_indicator() {
  126. return table(1000:0,
  127. ['entity_id', 'curve_type', 'strategy', 'end_date',
  128. 'info_ratio_6m', 'm2_6m', 'tracking_error_6m',
  129. 'info_ratio_1y', 'm2_1y', 'tracking_error_1y',
  130. 'info_ratio_2y', 'm2_2y', 'tracking_error_2y', 'var_2y', 'cvar_2y',
  131. 'info_ratio_3y', 'm2_3y', 'tracking_error_3y', 'var_3y', 'cvar_3y',
  132. 'info_ratio_4y', 'm2_4y', 'tracking_error_4y', 'var_4y', 'cvar_4y',
  133. 'info_ratio_5y', 'm2_5y', 'tracking_error_5y', 'var_5y', 'cvar_5y',
  134. 'info_ratio_10y', 'm2_10y', 'tracking_error_10y', 'var_10y', 'cvar_10y',
  135. 'info_ratio_ytd', 'm2_ytd', 'tracking_error_ytd',
  136. 'info_ratio_incep', 'm2_incep','tracking_error_incep', 'var_incep', 'cvar_incep'],
  137. [SYMBOL, INT, INT, MONTH,
  138. DOUBLE, DOUBLE, DOUBLE,
  139. DOUBLE, DOUBLE, DOUBLE,
  140. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  141. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  142. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  143. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  144. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  145. DOUBLE, DOUBLE, DOUBLE,
  146. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  147. }
  148. /*
  149. * 建表 XXX_risk_stats
  150. *
  151. * NOTE: mfdb.fund_risk_stats 中 maxdrawdown_6m 和 maxdrawdown_ytd 因不明原因分别是 6m_maxdrawdown 和 ytd_maxdrawdown 的虚拟列!
  152. */
  153. def create_entity_risk_stats(is_id_integer=false) {
  154. return table(1000:0,
  155. ['entity_id', 'end_date',
  156. 'stddev_6m', 'downsidedev_6m', 'alpha_6m', 'winrate_6m', 'beta_6m', 'skewness_6m', 'kurtosis_6m', 'worstmonth_6m', 'maxdrawdown_6m',
  157. 'stddev_1y', 'downsidedev_1y', 'alpha_1y', 'winrate_1y', 'beta_1y', 'skewness_1y', 'kurtosis_1y', 'worstmonth_1y', 'maxdrawdown_1y',
  158. 'stddev_2y', 'downsidedev_2y', 'alpha_2y', 'winrate_2y', 'beta_2y', 'skewness_2y', 'kurtosis_2y', 'worstmonth_2y', 'maxdrawdown_2y',
  159. 'stddev_3y', 'downsidedev_3y', 'alpha_3y', 'winrate_3y', 'beta_3y', 'skewness_3y', 'kurtosis_3y', 'worstmonth_3y', 'maxdrawdown_3y',
  160. 'stddev_4y', 'downsidedev_4y', 'alpha_4y', 'winrate_4y', 'beta_4y', 'skewness_4y', 'kurtosis_4y', 'worstmonth_4y', 'maxdrawdown_4y',
  161. 'stddev_5y', 'downsidedev_5y', 'alpha_5y', 'winrate_5y', 'beta_5y', 'skewness_5y', 'kurtosis_5y', 'worstmonth_5y', 'maxdrawdown_5y',
  162. 'stddev_10y', 'downsidedev_10y','alpha_10y', 'winrate_10y', 'beta_10y', 'skewness_10y', 'kurtosis_10y', 'worstmonth_10y', 'maxdrawdown_10y',
  163. 'stddev_ytd', 'downsidedev_ytd', 'alpha_ytd', 'winrate_ytd', 'beta_ytd', 'skewness_ytd', 'kurtosis_ytd', 'worstmonth_ytd', 'maxdrawdown_ytd',
  164. 'stddev_incep', 'downsidedev_incep', 'alpha_incep', 'winrate_incep', 'beta_incep', 'skewness_incep', 'kurtosis_incep', 'worstmonth_incep', 'maxdrawdown_incep'],
  165. [iif(is_id_integer, INT, SYMBOL), MONTH,
  166. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  167. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  168. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  169. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  170. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  171. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  172. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  173. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  174. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  175. }
  176. /*
  177. * 建基金经理/公司表 XXX_risk_stats
  178. *
  179. */
  180. def create_mc_risk_stats() {
  181. return table(1000:0,
  182. ['entity_id', 'curve_type', 'strategy', 'end_date',
  183. 'stddev_6m', 'downsidedev_6m', 'alpha_6m', 'winrate_6m', 'beta_6m', 'skewness_6m', 'kurtosis_6m', 'worstmonth_6m', 'maxdrawdown_6m',
  184. 'stddev_1y', 'downsidedev_1y', 'alpha_1y', 'winrate_1y', 'beta_1y', 'skewness_1y', 'kurtosis_1y', 'worstmonth_1y', 'maxdrawdown_1y',
  185. 'stddev_2y', 'downsidedev_2y', 'alpha_2y', 'winrate_2y', 'beta_2y', 'skewness_2y', 'kurtosis_2y', 'worstmonth_2y', 'maxdrawdown_2y',
  186. 'stddev_3y', 'downsidedev_3y', 'alpha_3y', 'winrate_3y', 'beta_3y', 'skewness_3y', 'kurtosis_3y', 'worstmonth_3y', 'maxdrawdown_3y',
  187. 'stddev_4y', 'downsidedev_4y', 'alpha_4y', 'winrate_4y', 'beta_4y', 'skewness_4y', 'kurtosis_4y', 'worstmonth_4y', 'maxdrawdown_4y',
  188. 'stddev_5y', 'downsidedev_5y', 'alpha_5y', 'winrate_5y', 'beta_5y', 'skewness_5y', 'kurtosis_5y', 'worstmonth_5y', 'maxdrawdown_5y',
  189. 'stddev_10y', 'downsidedev_10y','alpha_10y', 'winrate_10y', 'beta_10y', 'skewness_10y', 'kurtosis_10y', 'worstmonth_10y', 'maxdrawdown_10y',
  190. 'stddev_ytd', 'downsidedev_ytd', 'alpha_ytd', 'winrate_ytd', 'beta_ytd', 'skewness_ytd', 'kurtosis_ytd', 'worstmonth_ytd', 'maxdrawdown_ytd',
  191. 'stddev_incep', 'downsidedev_incep', 'alpha_incep', 'winrate_incep', 'beta_incep', 'skewness_incep', 'kurtosis_incep', 'worstmonth_incep', 'maxdrawdown_incep'],
  192. [SYMBOL, INT, INT, MONTH,
  193. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  194. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  195. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  196. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  197. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  198. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  199. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  200. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  201. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  202. }
  203. /*
  204. * 建表 XXX_riskadjret_stats
  205. */
  206. def create_entity_riskadjret_stats(is_id_integer=false) {
  207. return table(1000:0,
  208. ['entity_id', 'end_date',
  209. 'sharperatio_6m', 'sortinoratio_6m', 'treynorratio_6m', 'jensen_6m', 'calmarratio_6m', 'omegaratio_6m', 'kapparatio_6m',
  210. 'sharperatio_1y', 'sortinoratio_1y', 'treynorratio_1y', 'jensen_1y', 'calmarratio_1y', 'omegaratio_1y', 'kapparatio_1y',
  211. 'sharperatio_2y', 'sortinoratio_2y', 'treynorratio_2y', 'jensen_2y', 'calmarratio_2y', 'omegaratio_2y', 'kapparatio_2y',
  212. 'sharperatio_3y', 'sortinoratio_3y', 'treynorratio_3y', 'jensen_3y', 'calmarratio_3y', 'omegaratio_3y', 'kapparatio_3y',
  213. 'sharperatio_4y', 'sortinoratio_4y', 'treynorratio_4y', 'jensen_4y', 'calmarratio_4y', 'omegaratio_4y', 'kapparatio_4y',
  214. 'sharperatio_5y', 'sortinoratio_5y', 'treynorratio_5y', 'jensen_5y', 'calmarratio_5y', 'omegaratio_5y', 'kapparatio_5y',
  215. 'sharperatio_10y', 'sortinoratio_10y', 'treynorratio_10y', 'jensen_10y', 'calmarratio_10y', 'omegaratio_10y', 'kapparatio_10y',
  216. 'sharperatio_ytd', 'sortinoratio_ytd', 'treynorratio_ytd', 'jensen_ytd', 'calmarratio_ytd', 'omegaratio_ytd', 'kapparatio_ytd',
  217. 'sharperatio_incep', 'sortinoratio_incep', 'treynorratio_incep', 'jensen_incep', 'calmarratio_incep', 'omegaratio_incep', 'kapparatio_incep'],
  218. [iif(is_id_integer, INT, SYMBOL), MONTH,
  219. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  220. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  221. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  222. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  223. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  224. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  225. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  226. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  227. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  228. }
  229. /*
  230. * 建基金经理/公司表 XXX_riskadjret_stats
  231. */
  232. def create_mc_riskadjret_stats() {
  233. return table(1000:0,
  234. ['entity_id', 'curve_type', 'strategy', 'end_date',
  235. 'sharperatio_6m', 'sortinoratio_6m', 'treynorratio_6m', 'jensen_6m', 'calmarratio_6m', 'omegaratio_6m', 'kapparatio_6m',
  236. 'sharperatio_1y', 'sortinoratio_1y', 'treynorratio_1y', 'jensen_1y', 'calmarratio_1y', 'omegaratio_1y', 'kapparatio_1y',
  237. 'sharperatio_2y', 'sortinoratio_2y', 'treynorratio_2y', 'jensen_2y', 'calmarratio_2y', 'omegaratio_2y', 'kapparatio_2y',
  238. 'sharperatio_3y', 'sortinoratio_3y', 'treynorratio_3y', 'jensen_3y', 'calmarratio_3y', 'omegaratio_3y', 'kapparatio_3y',
  239. 'sharperatio_4y', 'sortinoratio_4y', 'treynorratio_4y', 'jensen_4y', 'calmarratio_4y', 'omegaratio_4y', 'kapparatio_4y',
  240. 'sharperatio_5y', 'sortinoratio_5y', 'treynorratio_5y', 'jensen_5y', 'calmarratio_5y', 'omegaratio_5y', 'kapparatio_5y',
  241. 'sharperatio_10y', 'sortinoratio_10y', 'treynorratio_10y', 'jensen_10y', 'calmarratio_10y', 'omegaratio_10y', 'kapparatio_10y',
  242. 'sharperatio_ytd', 'sortinoratio_ytd', 'treynorratio_ytd', 'jensen_ytd', 'calmarratio_ytd', 'omegaratio_ytd', 'kapparatio_ytd',
  243. 'sharperatio_incep', 'sortinoratio_incep', 'treynorratio_incep', 'jensen_incep', 'calmarratio_incep', 'omegaratio_incep', 'kapparatio_incep'],
  244. [SYMBOL, INT, INT, MONTH,
  245. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  246. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  247. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  248. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  249. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  250. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  251. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  252. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  253. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  254. }
  255. /*
  256. * 建表 XXX_style_stats
  257. */
  258. def create_entity_style_stats(is_id_integer=false) {
  259. return table(1000:0,
  260. ['entity_id', 'end_date',
  261. 'upsidecapture_ret_6m', 'downsidecapture_ret_6m', 'upsidecapture_ratio_6m', 'downsidecapture_ratio_6m',
  262. 'upsidecapture_ret_1y', 'downsidecapture_ret_1y', 'upsidecapture_ratio_1y', 'downsidecapture_ratio_1y',
  263. 'upsidecapture_ret_2y', 'downsidecapture_ret_2y', 'upsidecapture_ratio_2y', 'downsidecapture_ratio_2y',
  264. 'upsidecapture_ret_3y', 'downsidecapture_ret_3y', 'upsidecapture_ratio_3y', 'downsidecapture_ratio_3y',
  265. 'upsidecapture_ret_4y', 'downsidecapture_ret_4y', 'upsidecapture_ratio_4y', 'downsidecapture_ratio_4y',
  266. 'upsidecapture_ret_5y', 'downsidecapture_ret_5y', 'upsidecapture_ratio_5y', 'downsidecapture_ratio_5y',
  267. 'upsidecapture_ret_10y', 'downsidecapture_ret_10y', 'upsidecapture_ratio_10y', 'downsidecapture_ratio_10y',
  268. 'upsidecapture_ret_ytd', 'downsidecapture_ret_ytd', 'upsidecapture_ratio_ytd', 'downsidecapture_ratio_ytd',
  269. 'upsidecapture_ret_incep', 'downsidecapture_ret_incep', 'upsidecapture_ratio_incep', 'downsidecapture_ratio_incep'],
  270. [iif(is_id_integer, INT, SYMBOL), MONTH,
  271. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  272. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  273. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  274. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  275. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  276. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  277. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  278. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  279. DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  280. }
  281. /*
  282. * 建基金经理/公司表 XXX_style_stats
  283. */
  284. def create_mc_style_stats() {
  285. return table(1000:0,
  286. ['entity_id', 'curve_type', 'strategy', 'end_date',
  287. 'upsidecapture_ret_6m', 'downsidecapture_ret_6m', 'upsidecapture_ratio_6m', 'downsidecapture_ratio_6m',
  288. 'upsidecapture_ret_1y', 'downsidecapture_ret_1y', 'upsidecapture_ratio_1y', 'downsidecapture_ratio_1y',
  289. 'upsidecapture_ret_2y', 'downsidecapture_ret_2y', 'upsidecapture_ratio_2y', 'downsidecapture_ratio_2y',
  290. 'upsidecapture_ret_3y', 'downsidecapture_ret_3y', 'upsidecapture_ratio_3y', 'downsidecapture_ratio_3y',
  291. 'upsidecapture_ret_4y', 'downsidecapture_ret_4y', 'upsidecapture_ratio_4y', 'downsidecapture_ratio_4y',
  292. 'upsidecapture_ret_5y', 'downsidecapture_ret_5y', 'upsidecapture_ratio_5y', 'downsidecapture_ratio_5y',
  293. 'upsidecapture_ret_10y', 'downsidecapture_ret_10y', 'upsidecapture_ratio_10y', 'downsidecapture_ratio_10y',
  294. 'upsidecapture_ret_ytd', 'downsidecapture_ret_ytd', 'upsidecapture_ratio_ytd', 'downsidecapture_ratio_ytd',
  295. 'upsidecapture_ret_incep', 'downsidecapture_ret_incep', 'upsidecapture_ratio_incep', 'downsidecapture_ratio_incep'],
  296. [SYMBOL, INT, INT, MONTH,
  297. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  298. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  299. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  300. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  301. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  302. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  303. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  304. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  305. DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  306. }
  307. /*
  308. * 建表 XXX_bfi_bm_indicator
  309. */
  310. def create_entity_bfi_indicator(is_id_integer=false) {
  311. return table(1000:0,
  312. ['entity_id', 'end_date', 'factor_id',
  313. 'upsidecapture_ret_6m', 'downsidecapture_ret_6m', 'upsidecapture_ratio_6m', 'downsidecapture_ratio_6m',
  314. 'alpha_6m', 'winrate_6m', 'beta_6m', 'info_ratio_6m', 'tracking_error_6m', 'jensen_6m',
  315. 'upsidecapture_ret_1y', 'downsidecapture_ret_1y', 'upsidecapture_ratio_1y', 'downsidecapture_ratio_1y',
  316. 'alpha_1y', 'winrate_1y', 'beta_1y', 'info_ratio_1y', 'tracking_error_1y', 'jensen_1y',
  317. 'upsidecapture_ret_2y', 'downsidecapture_ret_2y', 'upsidecapture_ratio_2y', 'downsidecapture_ratio_2y',
  318. 'alpha_2y', 'winrate_2y', 'beta_2y', 'info_ratio_2y', 'tracking_error_2y', 'jensen_2y',
  319. 'upsidecapture_ret_3y', 'downsidecapture_ret_3y', 'upsidecapture_ratio_3y', 'downsidecapture_ratio_3y',
  320. 'alpha_3y', 'winrate_3y', 'beta_3y', 'info_ratio_3y', 'tracking_error_3y', 'jensen_3y',
  321. 'upsidecapture_ret_4y', 'downsidecapture_ret_4y', 'upsidecapture_ratio_4y', 'downsidecapture_ratio_4y',
  322. 'alpha_4y', 'winrate_4y', 'beta_4y', 'info_ratio_4y', 'tracking_error_4y', 'jensen_4y',
  323. 'upsidecapture_ret_5y', 'downsidecapture_ret_5y', 'upsidecapture_ratio_5y', 'downsidecapture_ratio_5y',
  324. 'alpha_5y', 'winrate_5y', 'beta_5y', 'info_ratio_5y', 'tracking_error_5y', 'jensen_5y',
  325. 'upsidecapture_ret_10y', 'downsidecapture_ret_10y', 'upsidecapture_ratio_10y', 'downsidecapture_ratio_10y',
  326. 'alpha_10y', 'winrate_10y', 'beta_10y', 'info_ratio_10y', 'tracking_error_10y', 'jensen_10y',
  327. 'upsidecapture_ret_ytd', 'downsidecapture_ret_ytd', 'upsidecapture_ratio_ytd', 'downsidecapture_ratio_ytd',
  328. 'alpha_ytd', 'winrate_ytd', 'beta_ytd', 'info_ratio_ytd', 'tracking_error_ytd', 'jensen_ytd',
  329. 'upsidecapture_ret_incep', 'downsidecapture_ret_incep', 'upsidecapture_ratio_incep', 'downsidecapture_ratio_incep',
  330. 'alpha_incep', 'winrate_incep', 'beta_incep', 'info_ratio_incep', 'tracking_error_incep', 'jensen_incep'],
  331. [iif(is_id_integer, INT, SYMBOL), MONTH, SYMBOL,
  332. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  333. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  334. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  335. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  336. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  337. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  338. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  339. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  340. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  341. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  342. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  343. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  344. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  345. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  346. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  347. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  348. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  349. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE] );
  350. }
  351. /*
  352. * 建基金经理/公司表 XXX_bfi_bm_indicator
  353. */
  354. def create_mc_bfi_indicator() {
  355. return table(1000:0,
  356. ['entity_id', 'curve_type', 'strategy', 'end_date', 'factor_id',
  357. 'upsidecapture_ret_6m', 'downsidecapture_ret_6m', 'upsidecapture_ratio_6m', 'downsidecapture_ratio_6m',
  358. 'alpha_6m', 'winrate_6m', 'beta_6m', 'info_ratio_6m', 'tracking_error_6m', 'jensen_6m',
  359. 'upsidecapture_ret_1y', 'downsidecapture_ret_1y', 'upsidecapture_ratio_1y', 'downsidecapture_ratio_1y',
  360. 'alpha_1y', 'winrate_1y', 'beta_1y', 'info_ratio_1y', 'tracking_error_1y', 'jensen_1y',
  361. 'upsidecapture_ret_2y', 'downsidecapture_ret_2y', 'upsidecapture_ratio_2y', 'downsidecapture_ratio_2y',
  362. 'alpha_2y', 'winrate_2y', 'beta_2y', 'info_ratio_2y', 'tracking_error_2y', 'jensen_2y',
  363. 'upsidecapture_ret_3y', 'downsidecapture_ret_3y', 'upsidecapture_ratio_3y', 'downsidecapture_ratio_3y',
  364. 'alpha_3y', 'winrate_3y', 'beta_3y', 'info_ratio_3y', 'tracking_error_3y', 'jensen_3y',
  365. 'upsidecapture_ret_4y', 'downsidecapture_ret_4y', 'upsidecapture_ratio_4y', 'downsidecapture_ratio_4y',
  366. 'alpha_4y', 'winrate_4y', 'beta_4y', 'info_ratio_4y', 'tracking_error_4y', 'jensen_4y',
  367. 'upsidecapture_ret_5y', 'downsidecapture_ret_5y', 'upsidecapture_ratio_5y', 'downsidecapture_ratio_5y',
  368. 'alpha_5y', 'winrate_5y', 'beta_5y', 'info_ratio_5y', 'tracking_error_5y', 'jensen_5y',
  369. 'upsidecapture_ret_10y', 'downsidecapture_ret_10y', 'upsidecapture_ratio_10y', 'downsidecapture_ratio_10y',
  370. 'alpha_10y', 'winrate_10y', 'beta_10y', 'info_ratio_10y', 'tracking_error_10y', 'jensen_10y',
  371. 'upsidecapture_ret_ytd', 'downsidecapture_ret_ytd', 'upsidecapture_ratio_ytd', 'downsidecapture_ratio_ytd',
  372. 'alpha_ytd', 'winrate_ytd', 'beta_ytd', 'info_ratio_ytd', 'tracking_error_ytd', 'jensen_ytd',
  373. 'upsidecapture_ret_incep', 'downsidecapture_ret_incep', 'upsidecapture_ratio_incep', 'downsidecapture_ratio_incep',
  374. 'alpha_incep', 'winrate_incep', 'beta_incep', 'info_ratio_incep', 'tracking_error_incep', 'jensen_incep'],
  375. [SYMBOL, INT, INT, MONTH, SYMBOL,
  376. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  377. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  378. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  379. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  380. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  381. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  382. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  383. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  384. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  385. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  386. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  387. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  388. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  389. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  390. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  391. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  392. DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  393. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE] );
  394. }
  395. /*
  396. * 建表 xxx_performance_weekly
  397. */
  398. def create_entity_performance_weekly(is_id_integer=false) {
  399. return table(1000:0,
  400. ['entity_id', 'year_week', 'end_year', 'week_of_year', 'price_date', 'cumulative_nav', 'ret_1w'],
  401. [iif(is_id_integer, INT, SYMBOL), STRING, STRING, SHORT, DATE, DOUBLE, DOUBLE]);
  402. }
  403. /*
  404. * 建表 xxx_latest_performance
  405. */
  406. def create_entity_latest_performance(is_id_integer=false) {
  407. return table(1000:0,
  408. ['entity_id', 'end_date', 'price_date', 'pre_price_date', 'nav', 'cumulative_nav',
  409. 'net_value_change', 'ret_1d', 'ret_1w', 'ret_1m', 'ret_3m', 'ret_6m',
  410. 'ret_1y', 'ret_2y', 'ret_3y', 'ret_4y', 'ret_5y', 'ret_10y', 'ret_ytd', 'ret_incep', 'ret_incep_a', 'ret_incep_a_all', 'ret_incep_a_gips',
  411. 'maxdrawdown_1m', 'maxdrawdown_3m', 'maxdrawdown_1y', 'maxdrawdown_incep', 'calmarratio_incep',
  412. 'ret_1y_a', 'ret_2y_a', 'ret_3y_a', 'ret_4y_a', 'ret_5y_a', 'ret_10y_a'],
  413. [iif(is_id_integer, INT, SYMBOL), STRING, DATE, DATE, DOUBLE, DOUBLE,
  414. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  415. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  416. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  417. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  418. }
  419. /*
  420. * 建表 xxx_index_coe
  421. *
  422. */
  423. def create_entity_index_coe(is_id_integer=false) {
  424. return table(1000:0,
  425. ['entity_id', 'end_date', 'index_id',
  426. 'coe_1y', 'coe_3y', 'coe_5y', //'info_ratio_1y', 'info_ratio_3y', 'info_ratio_5y',
  427. 't_value_1y', 't_value_3y', 't_value_5y', 'beta_1y', 'beta_3y', 'beta_5y'],
  428. [iif(is_id_integer, INT, SYMBOL), MONTH, SYMBOL,
  429. DOUBLE, DOUBLE, DOUBLE, //DOUBLE, DOUBLE, DOUBLE,
  430. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  431. }
  432. /*
  433. * 建表 xxx_index_coe
  434. *
  435. */
  436. def create_mc_index_coe(is_id_integer=false) {
  437. return table(1000:0,
  438. ['entity_id', 'curve_type', 'strategy', 'end_date', 'index_id',
  439. 'coe_1y', 'coe_3y', 'coe_5y', //'info_ratio_1y', 'info_ratio_3y', 'info_ratio_5y',
  440. 't_value_1y', 't_value_3y', 't_value_5y', 'beta_1y', 'beta_3y', 'beta_5y'],
  441. [SYMBOL, INT, INT, MONTH, SYMBOL,
  442. DOUBLE, DOUBLE, DOUBLE, //DOUBLE, DOUBLE, DOUBLE,
  443. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  444. }
  445. /*
  446. * 建表 xxx_factor_bfi_max_r2
  447. *
  448. */
  449. def create_entity_bfi_max_r2(is_id_integer=false) {
  450. return table(1000:0,
  451. ['entity_id', 'end_date', 'factor_id', 'coe', 'r2', 'performance_flag', 'rz_portrait'],
  452. [iif(is_id_integer, INT, SYMBOL), MONTH, SYMBOL, DOUBLE, DOUBLE, STRING, STRING]);
  453. }
  454. /*
  455. * 建表 xxx_factor_bfi
  456. *
  457. */
  458. def create_entity_factor_bfi(is_id_integer=false) {
  459. return table(1000:0,
  460. ['entity_id', 'end_date', 'factor_id',
  461. 'coe', 'r2', 'performance_flag', 't_value_1y', 'beta_1y'],
  462. [iif(is_id_integer, INT, SYMBOL), MONTH, SYMBOL,
  463. DOUBLE, DOUBLE, STRING, DOUBLE, DOUBLE]);
  464. }
  465. /*
  466. * 建基金经理/公司 bfi连接表 xxx_factor_bfi
  467. *
  468. */
  469. def create_mc_factor_bfi(is_id_integer=false) {
  470. return table(1000:0,
  471. ['entity_id', 'curve_type', 'strategy', 'end_date', 'factor_id',
  472. 'coe', 'r2', 'performance_flag', 't_value_1y', 'beta_1y'],
  473. [SYMBOL, INT, INT, MONTH, SYMBOL,
  474. DOUBLE, DOUBLE, STRING, DOUBLE, DOUBLE]);
  475. }
  476. /*
  477. * 建表 XXXX_indicator_ranking
  478. */
  479. def create_entity_indicator_ranking(is_id_integer=false) {
  480. return table(1000:0,
  481. ['entity_id', 'end_date', 'category_id', 'indicator_id',
  482. 'indicator_1m', 'absrank_1m', 'perrank_1m', 'indicator_3m', 'absrank_3m', 'perrank_3m',
  483. 'indicator_6m', 'absrank_6m', 'perrank_6m', 'indicator_1y', 'absrank_1y', 'perrank_1y',
  484. 'indicator_2y', 'absrank_2y', 'perrank_2y', 'indicator_3y', 'absrank_3y', 'perrank_3y',
  485. 'indicator_5y', 'absrank_5y', 'perrank_5y',
  486. 'indicator_10y', 'absrank_10y', 'perrank_10y', 'indicator_ytd', 'absrank_ytd', 'perrank_ytd'],
  487. [iif(is_id_integer, INT, SYMBOL), STRING, SYMBOL, INT,
  488. DOUBLE, INT, INT, DOUBLE, INT, INT,
  489. DOUBLE, INT, INT, DOUBLE, INT, INT,
  490. DOUBLE, INT, INT, DOUBLE, INT, INT,
  491. DOUBLE, INT, INT,
  492. DOUBLE, INT, INT, DOUBLE, INT, INT]);
  493. }
  494. /*
  495. * 建表 XXXX_indicator_ranking_num, raise_type 没有用
  496. */
  497. def create_entity_indicator_ranking_num() {
  498. return table(1000:0,
  499. ['end_date', 'category_id', 'raise_type', 'indicator_id',
  500. 'avg_1m', 'avg_1m_cnt', 'perrank_percent_5_1m', 'perrank_percent_10_1m', 'perrank_percent_25_1m', 'perrank_percent_50_1m',
  501. 'perrank_percent_75_1m', 'perrank_percent_90_1m', 'perrank_percent_95_1m', 'best_1m', 'worst_1m',
  502. 'avg_3m', 'avg_3m_cnt', 'perrank_percent_5_3m', 'perrank_percent_10_3m', 'perrank_percent_25_3m', 'perrank_percent_50_3m',
  503. 'perrank_percent_75_3m', 'perrank_percent_90_3m', 'perrank_percent_95_3m', 'best_3m', 'worst_3m',
  504. 'avg_6m', 'avg_6m_cnt', 'perrank_percent_5_6m', 'perrank_percent_10_6m', 'perrank_percent_25_6m', 'perrank_percent_50_6m',
  505. 'perrank_percent_75_6m', 'perrank_percent_90_6m', 'perrank_percent_95_6m', 'best_6m', 'worst_6m',
  506. 'avg_1y', 'avg_1y_cnt', 'perrank_percent_5_1y', 'perrank_percent_10_1y', 'perrank_percent_25_1y', 'perrank_percent_50_1y',
  507. 'perrank_percent_75_1y', 'perrank_percent_90_1y', 'perrank_percent_95_1y', 'best_1y', 'worst_1y',
  508. 'avg_2y', 'avg_2y_cnt', 'perrank_percent_5_2y', 'perrank_percent_10_2y', 'perrank_percent_25_2y', 'perrank_percent_50_2y',
  509. 'perrank_percent_75_2y', 'perrank_percent_90_2y', 'perrank_percent_95_2y', 'best_2y', 'worst_2y',
  510. 'avg_3y', 'avg_3y_cnt', 'perrank_percent_5_3y', 'perrank_percent_10_3y', 'perrank_percent_25_3y', 'perrank_percent_50_3y',
  511. 'perrank_percent_75_3y', 'perrank_percent_90_3y', 'perrank_percent_95_3y', 'best_3y', 'worst_3y',
  512. 'avg_5y', 'avg_5y_cnt', 'perrank_percent_5_5y', 'perrank_percent_10_5y', 'perrank_percent_25_5y', 'perrank_percent_50_5y',
  513. 'perrank_percent_75_5y', 'perrank_percent_90_5y', 'perrank_percent_95_5y', 'best_5y', 'worst_5y',
  514. 'avg_10y', 'avg_10y_cnt', 'perrank_percent_5_10y', 'perrank_percent_10_10y', 'perrank_percent_25_10y', 'perrank_percent_50_10y',
  515. 'perrank_percent_75_10y', 'perrank_percent_90_10y', 'perrank_percent_95_10y', 'best_10y', 'worst_10y',
  516. 'avg_ytd', 'avg_ytd_cnt', 'perrank_percent_5_ytd', 'perrank_percent_10_ytd', 'perrank_percent_25_ytd', 'perrank_percent_50_ytd',
  517. 'perrank_percent_75_ytd', 'perrank_percent_90_ytd', 'perrank_percent_95_ytd', 'best_ytd', 'worst_ytd'],
  518. [STRING, SYMBOL, INT, INT,
  519. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  520. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  521. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  522. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  523. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  524. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  525. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  526. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  527. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  528. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  529. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  530. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  531. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  532. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  533. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  534. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  535. DOUBLE, INT, DOUBLE, DOUBLE, DOUBLE, DOUBLE,
  536. DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE ]);
  537. }
  538. /*
  539. * 根据 mysql 表改动某些字段
  540. */
  541. def chg_columns_for_mysql(mutable tb_mysql, id_col_name) {
  542. tb_mysql.rename!('entity_id', id_col_name);
  543. // 将 dolphinDB 的 MONTH 换成 MySQL 的 YYYY-MM 格式
  544. v_end_date = EXEC end_date.temporalFormat('yyyy-MM') FROM tb_mysql;
  545. tb_mysql.replaceColumn!('end_date', v_end_date);
  546. }
  547. /*
  548. * 按照 XXX_performance 表结构准备数据记录
  549. *
  550. * @param entity_info <TABLE>: [COLUMNS] entity_id, end_date (用于筛掉不必要的老记录), [curve_type, strategy]
  551. * @param indicators <DICT>: 指标类型-区间:数据表
  552. * @param entity_performance <TABLE>: 被更新的数据表
  553. * @param extra_keys <VECTOR>: 只有基金经理和公司会用到,对应 [curve_type, strategy]
  554. *
  555. * TODO: price_date is NULL for some records
  556. */
  557. def generate_entity_performance(entity_info, indicators, isToMySQL, mutable entity_performance, extra_keys=[]) {
  558. t = null;
  559. if(extra_keys.isNothing() || extra_keys.isVoid()) v_extra_keys = array(STRING);
  560. else v_extra_keys = extra_keys;
  561. if(isToMySQL) {
  562. if(indicators['PBI-3M'].isVoid() || indicators['PBI-3M'].size() == 0) return;
  563. t = sql(select =(sqlCol('entity_id'),
  564. sqlCol(extra_keys.join('end_date')),
  565. sqlCol('price_date'),
  566. sqlCol(['nav', 'ret', 'ret', 'trailing_ret', 'trailing_ret_a'], , ['cumulative_nav', 'ret_1m', 'ret_1m_a', 'ret_3m', 'ret_3m_a'])
  567. ),
  568. from = ej(indicators['PBI-3M'] AS a, entity_info AS fi, ['entity_id'].join(v_extra_keys)),
  569. where = < end_date >= fi_price_date.month()> // 过滤掉不必更新的旧记录, 这里用系统字段的别名 fi_price_date 有点脏,但目前没办法
  570. ).eval();
  571. v_trailing = ['6m', '1y', '2y', '3y', '4y', '5y', '10y', 'ytd', 'incep'];
  572. for(tr in v_trailing) {
  573. col_name = 'ret_' + tr;
  574. col_a_name = 'ret_' + tr + '_a';
  575. t.addColumn([col_name, col_a_name], [DOUBLE, DOUBLE]);
  576. if(!indicators['PBI-'+tr.upper()].isVoid()) {
  577. sqlUpdate(table = t,
  578. updates = [<trailing_ret as _$col_name>, <trailing_ret_a as _$col_a_name>],
  579. from = <ej(t, indicators['PBI-'+tr.upper()], ['entity_id'].join(v_extra_keys).join(['end_date']))>
  580. ).eval();
  581. }
  582. }
  583. INSERT INTO entity_performance SELECT * FROM t;
  584. } else {
  585. }
  586. }
  587. /*
  588. * 按照 XXX_risk_stats 表结构准备数据记录
  589. *
  590. *
  591. */
  592. def generate_entity_risk_stats(entity_info, indicators, isToMySQL, mutable entity_risk_stats, extra_keys=[]) {
  593. t = null;
  594. if(extra_keys.isNothing() || extra_keys.isVoid()) v_extra_keys = array(STRING);
  595. else v_extra_keys = extra_keys;
  596. if(indicators['PBI-6M'].isVoid() || indicators['PBI-6M'].size() == 0) return;
  597. if(isToMySQL) {
  598. t = sql(select =(sqlCol('entity_id'),
  599. sqlCol(extra_keys.join('end_date')),
  600. sqlCol(['std_dev_a', 'ds_dev_a', 'alpha_a', 'winrate', 'beta', 'skewness', 'kurtosis', 'wrst_month', 'drawdown'],
  601. , ['stddev_6m', 'downsidedev_6m', 'alpha_6m', 'winrate_6m', 'beta_6m', 'skewness_6m', 'kurtosis_6m', 'worstmonth_6m', 'maxdrawdown_6m'])
  602. ),
  603. from = ej(indicators['PBI-6M'] AS a, entity_info AS fi, ['entity_id'].join(v_extra_keys)),
  604. where = < end_date >= fi_price_date.month()> // 过滤掉不必更新的旧记录
  605. ).eval();
  606. v_trailing = ['1y', '2y', '3y', '4y', '5y', '10y', 'ytd', 'incep'];
  607. for(tr in v_trailing) {
  608. col_std_dev = 'stddev_' + tr;
  609. col_ds_dev = 'downsidedev_' + tr;
  610. col_alpha = 'alpha_' + tr;
  611. col_winrate = 'winrate_' + tr;
  612. col_beta = 'beta_' + tr;
  613. col_skewness = 'skewness_' + tr;
  614. col_kurtosis = 'kurtosis_' + tr;
  615. col_wrst_month = 'worstmonth_' + tr;
  616. col_drawdown = 'maxdrawdown_' + tr;
  617. t.addColumn([col_std_dev, col_ds_dev, col_alpha, col_winrate, col_beta, col_skewness, col_kurtosis, col_wrst_month, col_drawdown],
  618. [DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  619. if(!indicators['PBI-'+tr.upper()].isVoid()) {
  620. sqlUpdate(table = t,
  621. updates = [<std_dev_a as _$col_std_dev>, <ds_dev_a as _$col_ds_dev>, <alpha_a as _$col_alpha>,
  622. <winrate as _$col_winrate>, <beta as _$col_beta>, <skewness as _$col_skewness>,
  623. <kurtosis as _$col_kurtosis>, <wrst_month as _$col_wrst_month>, <drawdown as _$col_drawdown>],
  624. from = <ej(t, indicators['PBI-'+tr.upper()], ['entity_id'].join(v_extra_keys).join(['end_date']))>
  625. ).eval();
  626. }
  627. }
  628. INSERT INTO entity_risk_stats SELECT * FROM t;
  629. } else {
  630. }
  631. }
  632. /*
  633. * 按照 XXX_riskadjret_stats 表结构准备数据记录
  634. *
  635. *
  636. */
  637. def generate_entity_riskadjret_stats(entity_info, indicators, isToMySQL, mutable entity_riskadjret_stats, extra_keys=[]) {
  638. t = null;
  639. if(extra_keys.isNothing() || extra_keys.isVoid()) v_extra_keys = array(STRING);
  640. else v_extra_keys = extra_keys;
  641. if(indicators['PBI-6M'].isVoid() || indicators['PBI-6M'].size() == 0) return;
  642. if(isToMySQL) {
  643. t = sql(select =(sqlCol('entity_id'),
  644. sqlCol(extra_keys.join('end_date')),
  645. sqlCol(['sharpe_a', 'sortino_a', 'treynor', 'jensen_a', 'calmar', 'omega', 'kappa'],
  646. , ['sharperatio_6m', 'sortinoratio_6m', 'treynorratio_6m', 'jensen_6m', 'calmarratio_6m', 'omegaratio_6m', 'kapparatio_6m'])
  647. ),
  648. from = ej(indicators['PBI-6M'] AS a, entity_info AS fi, ['entity_id'].join(v_extra_keys)),
  649. where = < end_date >= fi_price_date.month()> // 过滤掉不必更新的旧记录
  650. ).eval();
  651. v_trailing = ['1y', '2y', '3y', '4y', '5y', '10y', 'ytd', 'incep'];
  652. for(tr in v_trailing) {
  653. col_sharpe = 'sharperatio_' + tr;
  654. col_sortino = 'sortinoratio_' + tr;
  655. col_treynor = 'treynorratio_' + tr;
  656. col_jensen = 'jensen_' + tr;
  657. col_calmar = 'calmarratio_' + tr;
  658. col_omega = 'omegaratio_' + tr;
  659. col_kappa = 'kapparatio_' + tr;
  660. t.addColumn([col_sharpe, col_sortino, col_treynor, col_jensen, col_calmar, col_omega, col_kappa],
  661. [DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  662. if(!indicators['PBI-'+tr.upper()].isVoid()) {
  663. sqlUpdate(table = t,
  664. updates = [<sharpe_a as _$col_sharpe>, <sortino_a as _$col_sortino>, <treynor as _$col_treynor>,
  665. <jensen_a as _$col_jensen>, <calmar as _$col_calmar>, <omega as _$col_omega>,
  666. <kappa as _$col_kappa>],
  667. from = <ej(t, indicators['PBI-'+tr.upper()], ['entity_id'].join(v_extra_keys).join(['end_date']))>
  668. ).eval();
  669. }
  670. }
  671. INSERT INTO entity_riskadjret_stats SELECT * FROM t;
  672. } else {
  673. }
  674. }
  675. /*
  676. * 按照 XXX_indicator 表结构准备数据记录
  677. *
  678. *
  679. */
  680. def generate_entity_indicator(entity_info, indicators, isToMySQL, mutable entity_indicator, extra_keys=[]) {
  681. t = null;
  682. if(extra_keys.isNothing() || extra_keys.isVoid()) v_extra_keys = array(STRING);
  683. else v_extra_keys = extra_keys;
  684. if(indicators['PBI-6M'].isVoid() || indicators['PBI-6M'].size() == 0) return;
  685. if(isToMySQL) {
  686. t = sql(select =(sqlCol('entity_id'),
  687. sqlCol(extra_keys.join('end_date')),
  688. sqlCol(['info_a', 'm2_a', 'track_error_a'],
  689. , ['info_ratio_6m', 'm2_6m', 'tracking_error_6m'])
  690. ),
  691. from = ej(indicators['PBI-6M'] AS a, entity_info AS fi, ['entity_id'].join(v_extra_keys)),
  692. where = < end_date >= fi_price_date.month()> // 过滤掉不必更新的旧记录
  693. ).eval();
  694. v_trailing = ['1y', '2y', '3y', '4y', '5y', '10y', 'ytd', 'incep'];
  695. for(tr in v_trailing) {
  696. col_info = 'info_ratio_' + tr;
  697. col_m2 = 'm2_' + tr;
  698. col_track_error = 'tracking_error_' + tr;
  699. col_var = 'var_' + tr;
  700. col_cvar = 'cvar_' + tr;
  701. t.addColumn([col_info, col_m2, col_track_error],
  702. [DOUBLE, DOUBLE, DOUBLE]);
  703. if(tr != 'ytd') // YTD 没有 VAR, CVAR
  704. t.addColumn([col_var, col_cvar], [DOUBLE, DOUBLE]);
  705. if(!indicators['PBI-'+tr.upper()].isVoid()) {
  706. sqlUpdate(table = t,
  707. updates = iif(tr != 'ytd', [<info_a as _$col_info>, <m2_a as _$col_m2>, <track_error_a as _$col_track_error>,
  708. <var as _$col_var>, <cvar as _$col_cvar>], [<info_a as _$col_info>, <m2_a as _$col_m2>, <track_error_a as _$col_track_error>]),
  709. from = <ej(t, indicators['PBI-'+tr.upper()], ['entity_id'].join(v_extra_keys).join(['end_date']))>
  710. ).eval();
  711. }
  712. }
  713. // var, cvar 只有2年及更长时间才计算
  714. t.dropColumns!(['var_1y', 'cvar_1y']);
  715. INSERT INTO entity_indicator SELECT * FROM t;
  716. } else {
  717. }
  718. }
  719. /*
  720. * 按照 XXX_style_stats 表结构准备数据记录
  721. *
  722. *
  723. */
  724. def generate_entity_style_stats(entity_info, indicators, isToMySQL, mutable entity_style_stats, extra_keys=[]) {
  725. t = null;
  726. if(extra_keys.isNothing() || extra_keys.isVoid()) v_extra_keys = array(STRING);
  727. else v_extra_keys = extra_keys;
  728. if(indicators['PBI-6M'].isVoid() || indicators['PBI-6M'].size() == 0) return;
  729. if(isToMySQL) {
  730. t = sql(select =(sqlCol('entity_id'),
  731. sqlCol(extra_keys.join('end_date')),
  732. sqlCol(['upside_capture_ret', 'downside_capture_ret', 'upside_capture_ratio', 'downside_capture_ratio'],
  733. , ['upsidecapture_ret_6m', 'downsidecapture_ret_6m', 'upsidecapture_ratio_6m', 'downsidecapture_ratio_6m'])
  734. ),
  735. from = ej(indicators['PBI-6M'] AS a, entity_info AS fi, ['entity_id'].join(v_extra_keys)),
  736. where = < end_date >= fi_price_date.month()> // 过滤掉不必更新的旧记录
  737. ).eval();
  738. v_trailing = ['1y', '2y', '3y', '4y', '5y', '10y', 'ytd', 'incep'];
  739. for(tr in v_trailing) {
  740. col_upside_capture_ret = 'upsidecapture_ret_' + tr;
  741. col_downside_capture_ret = 'downsidecapture_ret_' + tr;
  742. col_upside_capture_ratio = 'upsidecapture_ratio_' + tr;
  743. col_downside_capture_ratio = 'downsidecapture_ratio_' + tr;
  744. t.addColumn([col_upside_capture_ret, col_downside_capture_ret, col_upside_capture_ratio, col_downside_capture_ratio],
  745. [DOUBLE, DOUBLE, DOUBLE, DOUBLE]);
  746. if(!indicators['PBI-'+tr.upper()].isVoid()) {
  747. sqlUpdate(table = t,
  748. updates = [<upside_capture_ret as _$col_upside_capture_ret>, <downside_capture_ret as _$col_downside_capture_ret>,
  749. <upside_capture_ratio as _$col_upside_capture_ratio>, <downside_capture_ratio as _$col_downside_capture_ratio>],
  750. from = <ej(t, indicators['PBI-'+tr.upper()], ['entity_id'].join(v_extra_keys).join(['end_date']))>
  751. ).eval();
  752. }
  753. }
  754. INSERT INTO entity_style_stats SELECT * FROM t;
  755. } else {
  756. }
  757. }
  758. /*
  759. * 按照 XXX_bfi_bm_indicator 表结构准备数据记录
  760. *
  761. * TODO: why we need isToMySQL here?
  762. * 其它的指标恐怕也要按这个改,因为私募可能会有近6月没有数据但近2年之类的周期有数据的情况!
  763. */
  764. def generate_entity_bfi_indicator(entity_info, indicators, isToMySQL, mutable entity_bfi_indicator, extra_keys=[]) {
  765. t = null;
  766. if(extra_keys.isNothing() || extra_keys.isVoid()) v_extra_keys = array(STRING);
  767. else v_extra_keys = extra_keys;
  768. v_cols_from = ['upside_capture_ret', 'downside_capture_ret', 'upside_capture_ratio', 'downside_capture_ratio', 'alpha_a', 'winrate', 'beta', 'info_a', 'track_error_a', 'jensen_a'];
  769. v_cols_to = ['upsidecapture_ret', 'downsidecapture_ret', 'upsidecapture_ratio', 'downsidecapture_ratio', 'alpha', 'winrate', 'beta', 'info_ratio', 'tracking_error', 'jensen'];
  770. v_cols_useless = ['track_error', 'info', 'alpha', 'treynor', 'jensen', 'm2', 'm2_a']; // 标准指标中不被当前表覆盖的数据点
  771. v_join_key = ['entity_id', 'benchmark_id', 'end_date'].join(v_extra_keys);
  772. if(isToMySQL) {
  773. t = lj(
  774. lj(
  775. lj(
  776. lj(
  777. lj(
  778. lj(
  779. lj(
  780. lj(
  781. lj(entity_info,
  782. indicators['BFI-6M'] AS t_6m, v_join_key).dropColumns!(v_cols_useless),
  783. indicators['BFI-1Y'] AS t_1y, v_join_key).dropColumns!(v_cols_useless),
  784. indicators['BFI-2Y'] AS t_2y, v_join_key).dropColumns!(v_cols_useless),
  785. indicators['BFI-3Y'] AS t_3y, v_join_key).dropColumns!(v_cols_useless),
  786. indicators['BFI-4Y'] AS t_4y, v_join_key).dropColumns!(v_cols_useless),
  787. indicators['BFI-5Y'] AS t_5y, v_join_key).dropColumns!(v_cols_useless),
  788. indicators['BFI-10Y'] AS t_10y, v_join_key).dropColumns!(v_cols_useless),
  789. indicators['BFI-YTD'] AS t_ytd, v_join_key).dropColumns!(v_cols_useless),
  790. indicators['BFI-INCEP'] AS t_incep, v_join_key).dropColumns!(v_cols_useless);
  791. t.rename!(v_cols_from, v_cols_to + '_6m');
  792. t.rename!('t_1y_' + v_cols_from, v_cols_to + '_1y');
  793. t.rename!('t_2y_' + v_cols_from, v_cols_to + '_2y');
  794. t.rename!('t_3y_' + v_cols_from, v_cols_to + '_3y');
  795. t.rename!('t_4y_' + v_cols_from, v_cols_to + '_4y');
  796. t.rename!('t_5y_' + v_cols_from, v_cols_to + '_5y');
  797. t.rename!('t_10y_' + v_cols_from, v_cols_to + '_10y');
  798. t.rename!('t_ytd_' + v_cols_from, v_cols_to + '_ytd');
  799. t.rename!('t_incep_' + v_cols_from, v_cols_to + '_incep');
  800. t.dropColumns!(['inception_date', 'ini_value']).rename!('benchmark_id', 'factor_id');
  801. entity_bfi_indicator.tableInsert(t.reorderColumns!(entity_bfi_indicator.colNames()));
  802. } else {
  803. }
  804. }
  805. /*
  806. * 按照 XXX_performance_weekly 表结构准备数据记录
  807. *
  808. *
  809. */
  810. def generate_entity_performance_weekly(entity_info, ret_w, isToMySQL, mutable entity_performance_weekly) {
  811. t = null;
  812. if(ret_w.isVoid() || ret_w.size() == 0) return;
  813. if(isToMySQL) {
  814. t = SELECT entity_id, year_week, year_week.left(4)$INT AS end_year, year_week.right(2)$INT AS week_of_year, price_date,
  815. cumulative_nav, ret_1w
  816. FROM ret_w r
  817. INNER JOIN entity_info fi ON r.entity_id = fi.entity_id
  818. WHERE r.price_date >= fi.price_date; // 过滤掉不必更新的旧记录
  819. INSERT INTO entity_performance_weekly SELECT * FROM t;
  820. } else {
  821. }
  822. }
  823. /*
  824. * 按照 XXX_latest_performance 表结构准备数据记录
  825. *
  826. *
  827. */
  828. def generate_entity_latest_performance(entity_info, perf_latest, isToMySQL, mutable entity_latest_performance) {
  829. t = null;
  830. if(perf_latest.isVoid() || perf_latest.size() == 0) return;
  831. if(isToMySQL) {
  832. t = SELECT r.*
  833. FROM perf_latest r
  834. INNER JOIN entity_info fi ON r.entity_id = fi.entity_id
  835. WHERE r.price_date >= fi.price_date; // 过滤掉不必更新的旧记录
  836. INSERT INTO entity_latest_performance SELECT * FROM t;
  837. } else {
  838. }
  839. }