{"description":"实验创建于2021/12/21","graph":{"edges":[{"to_node_id":"-419:features","from_node_id":"-406:data"},{"to_node_id":"-419:instruments","from_node_id":"-410:data"},{"to_node_id":"-173:input_1","from_node_id":"-419:data"}],"nodes":[{"node_id":"-173","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3, SW_type, SW_name):\n basic_data = input_1.read()\n start_date = str(basic_data.date.min())\n end_date = str(basic_data.date.max())\n SW_data = DataSource('basic_info_IndustrySw').read()\n SW_data['code'] = SW_data.code.astype('int')\n SW_data_2014_1 = SW_data[(SW_data.version==2014)&(SW_data.industry_sw_level==1)][['code','name']].rename(columns={'code':'industry_sw_level1_0','name':'name_SW1'})\n SW_data_2014_2 = SW_data[(SW_data.version==2014)&(SW_data.industry_sw_level==2)][['code','name']].rename(columns={'code':'industry_sw_level2_0','name':'name_SW2'})\n SW_data_2014_3 = SW_data[(SW_data.version==2014)&(SW_data.industry_sw_level==3)][['code','name']].rename(columns={'code':'industry_sw_level3_0','name':'name_SW3'})\n SW_data_2021_1 = SW_data[(SW_data.version==2021)&(SW_data.industry_sw_level==1)][['code','name']].rename(columns={'code':'industry_sw_level1_0','name':'name_SW1'})\n SW_data_2021_2 = SW_data[(SW_data.version==2021)&(SW_data.industry_sw_level==2)][['code','name']].rename(columns={'code':'industry_sw_level2_0','name':'name_SW2'})\n SW_data_2021_3 = SW_data[(SW_data.version==2021)&(SW_data.industry_sw_level==3)][['code','name']].rename(columns={'code':'industry_sw_level3_0','name':'name_SW3'})\n # 提取所需数据\n# basic_data = DataSource('features_CN_STOCK_A_G300').read(start_date=start_date,end_date=end_date,fields=['industry_sw_level1_0','industry_sw_level2_0','industry_sw_level3_0','market_cap_float_0','daily_return_0'])\n# basic_data = basic_data[basic_data.industry_sw_level1_0 !=0]\n basic_data['daily_return_0'] = basic_data['daily_return_0']-1\n\n if end_date < '2021-12-13':\n basic_data = basic_data.merge(SW_data_2014_1,how='left',on='industry_sw_level1_0')\n basic_data = basic_data.merge(SW_data_2014_2,how='left',on='industry_sw_level2_0')\n basic_data = basic_data.merge(SW_data_2014_3,how='left',on='industry_sw_level3_0')\n else:\n basic_data_2014 = basic_data[basic_data.date < '2021-12-13']\n basic_data_2014 = basic_data_2014.merge(SW_data_2014_1,how='left',on='industry_sw_level1_0')\n basic_data_2014 = basic_data_2014.merge(SW_data_2014_2,how='left',on='industry_sw_level2_0')\n basic_data_2014 = basic_data_2014.merge(SW_data_2014_3,how='left',on='industry_sw_level3_0')\n basic_data_2021 = basic_data[basic_data.date >= '2021-12-13']\n basic_data_2021 = basic_data_2021.merge(SW_data_2021_1,how='left',on='industry_sw_level1_0')\n basic_data_2021 = basic_data_2021.merge(SW_data_2021_2,how='left',on='industry_sw_level2_0')\n basic_data_2021 = basic_data_2021.merge(SW_data_2021_3,how='left',on='industry_sw_level3_0')\n basic_data = pd.concat([basic_data_2014,basic_data_2021])\n \n def calculate_daily_ret(df):\n df['ret'] = df['daily_return_0'] * (df['market_cap_float_0']/df['market_cap_float_0'].sum())\n return df\n \n SW_type = SW_type\n SW_name = SW_name\n \n SW_daily_ret = basic_data.groupby([SW_type,'date']).apply(calculate_daily_ret)\n \n SW_daily_ret = SW_daily_ret[SW_daily_ret[SW_type]==SW_name]\n\n SW_daily_ret = SW_daily_ret[['date','ret']].groupby('date').sum()\n \n #第一天收益为0\n SW_daily_ret['ret'][0:1]=0\n \n SW_daily_ret['cum_ret'] = (SW_daily_ret['ret']+1).cumprod()-1\n \n SW_index_dict = {'SW_type':SW_type,'SW_name':SW_name}\n \n data_1 = DataSource.write_df(SW_daily_ret)\n data_2 = DataSource.write_pickle(SW_index_dict)\n return Outputs(data_1=data_1, data_2=data_2, data_3=None)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n daily_ret = outputs.data_1.read()\n index_info = outputs.data_2.read()\n# daily_ret.set_index(\"date\", inplace=True)\n # 画图\n options={\"series\": [{\"color\": \"#FF0000\"}]}\n T.plot(df=daily_ret[[\"cum_ret\"]], title=index_info['SW_name']+\"行业指数\", options=options, double_precision=6)\n \n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{\n 'SW_type':'name_SW1','SW_name':'基础化工'\n}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"data_1,data_2","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-173"},{"name":"input_2","node_id":"-173"},{"name":"input_3","node_id":"-173"}],"output_ports":[{"name":"data_1","node_id":"-173"},{"name":"data_2","node_id":"-173"},{"name":"data_3","node_id":"-173"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-406","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"industry_sw_level1_0\nindustry_sw_level2_0\nindustry_sw_level3_0\nmarket_cap_float_0\ndaily_return_0\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-406"}],"output_ports":[{"name":"data","node_id":"-406"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-410","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-12-20","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-410"}],"output_ports":[{"name":"data","node_id":"-410"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-419","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":90,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-419"},{"name":"features","node_id":"-419"}],"output_ports":[{"name":"data","node_id":"-419"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-173' Position='196.55307006835938,175.4047555923462,200,200'/><node_position Node='-406' Position='422.133056640625,-126.18618774414062,200,200'/><node_position Node='-410' Position='-1.664825439453125,-122.78453063964844,200,200'/><node_position Node='-419' Position='178.91815185546875,16.959073066711426,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2021-12-22 10:10:32.820168] INFO: moduleinvoker: input_features.v1 开始运行..
[2021-12-22 10:10:32.831493] INFO: moduleinvoker: 命中缓存
[2021-12-22 10:10:32.834069] INFO: moduleinvoker: input_features.v1 运行完成[0.013907s].
[2021-12-22 10:10:32.841171] INFO: moduleinvoker: instruments.v2 开始运行..
[2021-12-22 10:10:32.850406] INFO: moduleinvoker: 命中缓存
[2021-12-22 10:10:32.853108] INFO: moduleinvoker: instruments.v2 运行完成[0.011935s].
[2021-12-22 10:10:32.870687] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2021-12-22 10:10:32.882217] INFO: moduleinvoker: 命中缓存
[2021-12-22 10:10:32.885078] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[0.014416s].
[2021-12-22 10:10:32.908717] INFO: moduleinvoker: cached.v3 开始运行..
[2021-12-22 10:11:13.432571] INFO: moduleinvoker: cached.v3 运行完成[40.523864s].