训练出错了“max() arg is an empty sequence”

策略分享
用户成长系列
标签: #<Tag:0x00007efe9d51f598> #<Tag:0x00007efe9d51f430>

(zacharyhu) #1

ValueError Traceback (most recent call last)
in ()
354 data_row_fraction=1,
355 ndcg_discount_base=1,
–> 356 m_lazy_run=False
357 )
358

ValueError: max() arg is an empty sequence

克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-274:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:data"},{"DestinationInputPortId":"-274:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-281:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-288:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-295:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-123:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-6060:options_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"-288:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-6060:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-123:training_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"DestinationInputPortId":"-3776:input_1","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-281:input_data","SourceOutputPortId":"-274:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-281:data"},{"DestinationInputPortId":"-295:input_data","SourceOutputPortId":"-288:data"},{"DestinationInputPortId":"-3780:input_1","SourceOutputPortId":"-295:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:data","SourceOutputPortId":"-3776:data_1"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-3780:data_1"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"-123:model"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2012-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html\n# 添加benchmark_前缀,可使用对应的benchmark数据\n# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\n#signedpower((shift(close, -5) / shift(open, -1)-1),log10(market_cap_float)/pe_ttm)\n#where((shift(close, -3) / shift(open, -1) > 0) & (correlation(close, amount, -3)>0),correlation(close, amount, -3) ,0)\n(shift(close, -2) / shift(open, -1) - 1)*100\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\nall_wbins(label, 60)\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na_label","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"Alpha_1=where(mean(amount_0,20)<volume_0,((-1*ts_rank(abs(delta(close_0,7)),60))*sign(delta(close_0,7))),-1)\n\nAlpha_2=rank(ts_argmax(signedpower(where(close_0/shift(close_0,1)-1<0,std(close_0/shift(close_0,1)-1<0,20),close_0),2),5))-0.5\n\nAlpha_3=-1*correlation(rank(delta(log(volume_0),2)),rank(((close_0-open_0)/open_0)),6)\n\nAlpha_4=-1*correlation(rank(open_0),rank(volume_0),10)\n\nAlpha_5=-1*ts_rank(rank(low_0),9)\n\nAlpha_6=rank((open_0-(sum(amount_0/volume_0*adjust_factor_0,10)/10)))*(-1*abs(rank((close_0-amount_0/volume_0*adjust_factor_0))))\n\nAlpha_7=-1*correlation(open_0,volume_0,10)\n\nAlpha_8=where(mean(amount_0,20)<volume_0,((-1*ts_rank(abs(delta(close_0,7)),60))*sign(delta(close_0,7))),-1)\n\nAlpha_9=(-1*rank(((sum(open_0,5)*sum(close_0/shift(close_0,1)-1,5))-delay((sum(open_0,5)*sum(close_0/shift(close_0,1)-1,5)),10))))\n\nAlpha_10=where(0<ts_min(delta(close_0,1),5),delta(close_0,1),where(ts_max(delta(close_0,1),5)<0,delta(close_0,1),-1*delta(close_0,1)))\n\nAlpha_11=rank(where(0<ts_min(delta(close_0,1),4),delta(close_0,1),where(ts_max(delta(close_0,1),4)<0,delta(close_0,1),-1*delta(close_0,1))))\n\nAlpha_12=(rank(ts_max((amount_0/volume_0*adjust_factor_0-close_0),3))+rank(ts_min((amount_0/volume_0*adjust_factor_0-close_0),3)))*rank(delta(volume_0,3))\n\nAlpha_13=sign(delta(volume_0,1))*(-1*delta(close_0,1))\n\nAlpha_14=-1*rank(covariance(rank(close_0),rank(volume_0),5))\n\nAlpha_15=(-1*rank(delta(close_0/shift(close_0,1)-1,3)))*correlation(open_0,volume_0,10)\n\nAlpha_16=-1*sum(rank(correlation(rank(high_0),rank(volume_0),3)),3)\n\nAlpha_17=-1*rank(covariance(rank(high_0),rank(volume_0),5))\n\nAlpha_18=((-1*rank(ts_rank(close_0,10)))*rank(delta(delta(close_0,1),1)))*rank(ts_rank((volume_0/mean(amount_0,20)),5))\n\nAlpha_19=-1*rank(((std(abs((close_0-open_0)),5)+(close_0-open_0))+correlation(close_0,open_0,10)))\n\nAlpha_20=(-1*sign(((close_0-delay(close_0,7))+delta(close_0,7))))*(1+rank((1+sum(close_0/shift(close_0,1)-1,250))))\n\nAlpha_21=((-1*rank((open_0-delay(high_0,1))))*rank((open_0-delay(close_0,1))))*rank((open_0-delay(low_0,1)))\n\nAlpha_22=where(sum(close_0,8)/8+stddev(close_0,8)<sum(close_0,2)/2,-1,where(mean(close_0,2)<mean(close_0,8)-std(close_0,8),1,where((1<volume_0/mean(amount_0,20)) |(volume_0/mean(amount_0,20)==1),1,-1)))\n\nAlpha_23=-1*(delta(correlation(high_0,volume_0,5),5)*rank(std(close_0,20)))\n\nAlpha_24=where(sum(high_0,20)/20<high_0,-1*delta(high_2,0),0)\n\nAlpha_25=where((delta(mean(close_0,100),100)/delay(close_0,100)<0.05) |(delta(mean(close_0,100),100)/delay(close_0,100)==0.05) ,-1*(close_0-ts_min(close_0,100)),-1*delta(close_0,2))\n\nAlpha_26=rank(-1*(close_0/shift(close_0,1)-1)*mean(amount_0,20)*amount_0/volume_0*adjust_factor_0*(high_0-close_0))\n\nAlpha_27=-1*ts_max(correlation(ts_rank(volume_0,5),ts_rank(high_0,5),5),3)\n\nAlpha_28=where(0.5<rank((sum(correlation(rank(volume_0),rank(amount_0/volume_0*adjust_factor_0),6),2)/2.0)),-1,1)\n\nAlpha_29=scale(correlation(mean(amount_0,20),low_0,5)+(high_0+low_0)*0.5-close_0)\n\nAlpha_30=min(product(rank(rank(scale(log(sum(ts_min(rank(rank((-1*rank(delta((close_0-1),5))))),2),1))))),1),5)+ts_rank(delay((-1*shift(close_0,1)/close_0-1),6),5)\n\nAlpha_31=((1.0-rank(((sign((close_0-delay(close_0,1)))+sign((delay(close_0,1)-delay(close_0,2)))) +sign((delay(close_0,2)-delay(close_0,3))))))*sum(volume_0,5))/sum(volume_0,20)\n\nAlpha_32=(rank(rank(rank(decay_linear((-1*rank(rank(delta(close_0,10)))),10))))+rank((-1*delta(close_0,3))))+sign(scale(correlation(mean(amount_0,20),low_0,12)))\n\nAlpha_33=scale(((sum(close_0,7)/7)-close_0))+20*scale(correlation(amount_0/volume_0*adjust_factor_0,delay(close_0,5),230))\n\nAlpha_34=rank((-1*((1-(open_0/close_0)))))\n\nAlpha_35=rank(((1-rank((std(close_0/shift(close_0,1),2)/stddev(close_0/shift(close_0,1)-1,5))))+(1-rank(delta(close_0,1))))) \n\nAlpha_36=ts_rank(volume_0,32)*(1-ts_rank(((close_0+high_0)-low_0),16))*(1-ts_rank(close_0/shift(close_0,1)-1,32))\n\nAlpha_37=((((2.21*rank(correlation((close_0-open_0),delay(volume_0,1),15)))+(0.7*rank((open_0-close_0))))+(0.73*rank(ts_rank(delay((-1*close_0/shift(close_0,1)-1),6),5))))+rank(abs(correlation(amount_0/volume_0*adjust_factor_0,mean(amount_0,20),6))))+(0.6*rank((((sum(close_0,200)/200)-open_0)*(close_0-open_0)))) \n\nAlpha_38=rank(correlation(delay((open_0-close_0),1),close_0,200))+rank((open_0-close_0))\n\nAlpha_39=(-1*rank(ts_rank(close_0,10)))*rank((close_0/open_0))\n\nAlpha_40=((-1*rank((delta(close_0,7)*(1-rank(decay_linear((volume_0/mean(amount_0,20)),9))))))*(1 +rank(sum(close_0/shift(close_0,1),250))))\n\nAlpha_41=((-1*rank(std(high_0,10)))*correlation(high_0,volume_0,10))\n\nAlpha_42=(((high_0*low_0)**0.5)-amount_0/volume_0*adjust_factor_0)\n\nAlpha_43=(rank((amount_0/volume_0*adjust_factor_0-close_0))/rank((amount_0/volume_0*adjust_factor_0+close_0)))\n\nAlpha_44=(ts_rank((volume_0/mean(amount_0,20)),20)*ts_rank((-1*delta(close_0,7)),8))\n\nAlpha_45=(-1*correlation(high_0,rank(volume_0),5))\n\nAlpha_46=(-1*((rank((sum(delay(close_0,5),20)/20))*correlation(close_0,volume_0,2))*rank(correlation(sum(close_0,5),sum(close_0,20),2))))\n\nAlpha_47=where((0.25<(((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))),-1,where(((((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))<0),1,((-1*1)*(close_0-delay(close_0,1)))))\n\nAlpha_48=(((rank((1/close_0))*volume_0)/mean(amount_0,20))*((high_0*rank((high_0-close_0)))/(sum(high_0,5) /5)))-rank((amount_0/volume_0*adjust_factor_0-delay(amount_0/volume_0*adjust_factor_0,5)))\n\nAlpha_49=((correlation(delta(close_0,1),delta(delay(close_0,1),1),250)*delta(close_0,1))/close_0)/group_mean(industry_sw_level1_0,((correlation(delta(close_0,1),delta(delay(close_0,1),1),250)*delta(close_0,1))/close_0))/sum(((delta(close_0,1)/delay(close_0,1))**2),250) \n\nAlpha_50=where(((((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))<(-1*0.1)),1,(close_0-delay(close_0,1))*(-1)) \n\nAlpha_51=(-1*ts_max(rank(correlation(rank(volume_0),rank(amount_0/volume_0*adjust_factor_0),5)),5))\n\nAlpha_52=where((((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))<(-1*0.05),1,-1*(close_0-delay(close_0,1)))\n\nAlpha_53=(((-1*ts_min(low_0,5))+delay(ts_min(low_0,5),5))*rank(((sum(close_0/shift(close_0,1),240)-sum(close_0/shift(close_0,1),20))/220)))*ts_rank(volume_0,5)\n\nAlpha_54=(-1*delta((((close_0-low_0)-(high_0-close_0))/(close_0-low_0)),9))\n\nAlpha_55=((-1*((low_0-close_0)*(open_0**5)))/((low_0-high_0)*(close_0** 5))) \n\nAlpha_56=-1*correlation(rank(((close_0-ts_min(low_0,12))/(ts_max(high_0,12)-ts_min(low_0,12)))),rank(volume_0),6)\n\nAlpha_57=0-1*(1*(rank((sum(close_0/shift(close_0,1)-1,10)/sum(sum(close_0/shift(close_0,1)-1,2),3)))*rank(((close_0/shift(close_0,1)-1)*market_cap_0)))) \n\nAlpha_58=(0-(1*((close_0-amount_0/volume_0*adjust_factor_0)/decay_linear(rank(ts_argmax(close_0,30)),2)))) \n\nAlpha_59=(-1*ts_rank(decay_linear(correlation( amount_0/volume_0*adjust_factor_0/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),volume_0,4),8),5))\n\nAlpha_60=(0-(1*((2*scale(rank(((((close_0-low_0)-(high_0-close_0))/(high_0-low_0))*volume_0))))-scale(rank(ts_argmax(close_0,10))))))\n\nAlpha_61=(rank((amount_0/volume_0*adjust_factor_0-ts_min(amount_0/volume_0*adjust_factor_0,16)))<rank(correlation(amount_0/volume_0*adjust_factor_0,mean(amount_0,180),18)))\n\nAlpha_62=(rank(correlation(amount_0/volume_0*adjust_factor_0,sum(mean(amount_0,20),22),10))<rank(((rank(open_0)+rank(open_0))<(rank(((high_0+low_0)/2))+rank(high_0)))))*-1\n\nAlpha_63=((rank(decay_linear(delta(close_0/group_mean(industry_sw_level1_0,close_0),2),8))-rank(decay_linear(correlation(((amount_0/volume_0*adjust_factor_0*0.318108)+(open_0*(1-0.318108))),sum(mean(amount_0,180),37),14),12)))*-1)\n\nAlpha_64=((rank(correlation(sum(((open_0*0.178404)+(low_0*(1-0.178404))),13),sum(mean(amount_0,20),13),17))<rank(delta(((((high_0+low_0)/2)*0.178404)+(amount_0/volume_0*adjust_factor_0*(1-0.178404))),4)))*-1)\n\nAlpha_65=((rank(correlation(((open_0*0.00817205)+(amount_0/volume_0*adjust_factor_0*(1-0.00817205))),sum(mean(amount_0,60),9),6))<rank((open_0-ts_min(open_0,14))))*-1)\n\nAlpha_66=((rank(decay_linear(delta(amount_0/volume_0*adjust_factor_0,4),7))+ts_rank(decay_linear(((((low_0* 0.96633)+(low_0*(1-0.96633)))-amount_0/volume_0*adjust_factor_0)/(open_0-((high_0+low_0)/2))),11),7))*-1)\n\nAlpha_67=((rank((high_0-ts_min(high_0,2)))**rank(correlation( amount_0/volume_0*adjust_factor_0 /group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),mean(amount_0,20)/group_mean(industry_sw_level1_0,mean(amount_0,20)),6)))*-1)\n\nAlpha_68=((ts_rank(correlation(rank(high_0),rank(mean(amount_0,15)),9),14)<rank(delta(((close_0*0.518371)+(low_0*(1-0.518371))),1.06157)))*-1)\n\nAlpha_69=((rank(ts_max(delta(amount_0/volume_0*adjust_factor_0/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),3),5))**ts_rank(correlation(((close_0*0.490655)+(amount_0/volume_0*adjust_factor_0*(1-0.490655))),mean(amount_0,20),5),9))*-1)\n\nAlpha_70=((rank(delta(amount_0/volume_0*adjust_factor_0,1))**ts_rank(correlation( close_0/group_mean(industry_sw_level1_0,close_0),mean(amount_0,50),18),18))*-1)\n\nAlpha_71=max(ts_rank(decay_linear(correlation(ts_rank(close_0,3),ts_rank(mean(amount_0,180),12),18),4),16),ts_rank(decay_linear((rank(((low_0+open_0)-(amount_0/volume_0*adjust_factor_0 +amount_0/volume_0*adjust_factor_0)))**2),16 ),4))\n\nAlpha_72=(rank(decay_linear(correlation(((high_0+low_0)/2),mean(amount_0,40),9),10)) /rank(decay_linear(correlation(ts_rank(amount_0/volume_0*adjust_factor_0,4),ts_rank(volume_0,19),7),3)))\n\nAlpha_73=(max(rank(decay_linear(delta(amount_0/volume_0*adjust_factor_0,5),3)),ts_rank(decay_linear(((delta(((open_0* 0.147155)+(low_0*(1-0.147155))),2 ) /((open_0* 0.147155)+(low_0*(1-0.147155))))*-1),3),17))*-1) \n\nAlpha_74=(rank(correlation(close_0,sum(mean(amount_0,30),37),15))<rank(correlation(rank(high_0*0.0261661+amount_0/volume_0*adjust_factor_0*(1-0.0261661)),rank(volume_0),11)))*-1\n\nAlpha_75=rank(correlation(amount_0/volume_0*adjust_factor_0,volume_0,4 ))<rank(correlation(rank(low_0),rank(mean(amount_0,50)),12))\n\nAlpha_76=max(rank(decay_linear(delta(amount_0/volume_0*adjust_factor_0,1),12)),ts_rank(decay_linear(ts_rank(correlation( low_0/group_mean(industry_sw_level1_0,low_0),mean(amount_0,81),8 ),20),17),19))*-1\n\nAlpha_77=min(rank(decay_linear(((((high_0+low_0)/2)+high_0)-(amount_0/volume_0*adjust_factor_0+high_0)),20 )),rank(decay_linear(correlation(((high_0+low_0)/2),mean(amount_0,40),3),6)))\n\nAlpha_78=rank(correlation(sum(((low_0*0.352233)+(amount_0/volume_0*adjust_factor_0*(1-0.352233))),20),sum(mean(amount_0,20),20),7))**rank(correlation(rank(amount_0/volume_0*adjust_factor_0),rank(volume_0),6))\n\nAlpha_79=rank(delta((close_0*0.60733+open_0*(1-0.60733))/ group_mean(industry_sw_level1_0,(close_0*0.60733+open_0*(1-0.60733))),1))<rank(correlation(ts_rank(amount_0/volume_0*adjust_factor_0,4),ts_rank(mean(amount_0,150),9),115))\n\nAlpha_80=(rank(sign(delta((open_0*0.868128+high_0*(1-0.868128))/group_mean(industry_sw_level1_0,(open_0*0.868128+high_0*(1-0.868128))),4)))**ts_rank(correlation(high_0,mean(amount_0,10),5),6))*-1\n\nAlpha_81=(rank(log(product(rank((rank(correlation(amount_0/volume_0*adjust_factor_0,sum(mean(amount_0,10),50),8))**4)),15)))<rank(correlation(rank(amount_0/volume_0*adjust_factor_0),rank(volume_0),5)))*-1\n\nAlpha_82=min(rank(decay_linear(delta(open_0,1.46063),15)),ts_rank(decay_linear(correlation( volume_0/group_mean(industry_sw_level1_0,volume_0),((open_0*0.634196) +(open_0*(1-0.634196))),17),7),13))*-1\n\nAlpha_83=(rank(delay(((high_0-low_0)/(sum(close_0,5)/5)),2))*rank(rank(volume_0)))/(((high_0-low_0)/(sum(close_0,5)/5))/(amount_0/volume_0*adjust_factor_0-close_0))\n\nAlpha_84=signedpower(ts_rank((amount_0/volume_0*adjust_factor_0-ts_max(amount_0/volume_0*adjust_factor_0,15)),20),delta(close_0,5))\n\nAlpha_85=rank(correlation(((high_0*0.876703)+(close_0*(1-0.876703))),mean(amount_0,30),10))**rank(correlation(ts_rank(((high_0+low_0)/2),4),ts_rank(volume_0,10),7))\n\nAlpha_86=(ts_rank(correlation(close_0,sum(mean(amount_0,20),15),6),20)<rank(((open_0+close_0)-(amount_0/volume_0*adjust_factor_0+open_0))))*-1\n\nAlpha_87=max(rank(decay_linear(delta(((close_0*0.369701)+(amount_0/volume_0*adjust_factor_0*(1-0.369701))),2),3)),ts_rank(decay_linear(abs(correlation( mean(amount_0,81) /group_mean(industry_sw_level1_0,mean(amount_0,81)) ,close_0,14)),5),14))*-1\n\nAlpha_88=min(rank(decay_linear(((rank(open_0)+rank(low_0))-(rank(high_0)+rank(close_0))),8)),ts_rank(decay_linear(correlation(ts_rank(close_0,8),ts_rank(mean(amount_0,60),21),8),7),3))\n\nAlpha_89=ts_rank(decay_linear(correlation(((low_0*0.967285)+(low_0*(1-0.967285))),mean(amount_0,10),7),6),4)-ts_rank(decay_linear(delta( amount_0/volume_0*adjust_factor_0/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),3),10),15)\n\nAlpha_90=(rank((close_0-ts_max(close_0,5)))**ts_rank(correlation(mean(amount_0,40)/group_mean(industry_sw_level1_0,mean(amount_0,40)),low_0,5),3))*-1\n\nAlpha_91=(ts_rank(decay_linear(decay_linear(correlation(close_0/group_mean(industry_sw_level1_0,close_0),volume_0,10),16),4),5)-rank(decay_linear(correlation(amount_0/volume_0*adjust_factor_0,mean(amount_0,30),4),3)))*-1\n\nAlpha_92=min(ts_rank(decay_linear(((((high_0+low_0)/2)+close_0)<(low_0+open_0)),15),19),ts_rank(decay_linear(correlation(rank(low_0),rank(mean(amount_0,30)),8),7),7))\n\nAlpha_93=ts_rank(decay_linear(correlation((amount_0/volume_0*adjust_factor_0)/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0) ,mean(amount_0,81),17),20),8)/rank(decay_linear(delta(((close_0*0.524434)+(amount_0/volume_0*adjust_factor_0*(1-0.524434))),3),16))\n\nAlpha_94=(rank((amount_0/volume_0*adjust_factor_0-ts_min(amount_0/volume_0*adjust_factor_0,12)))**ts_rank(correlation(ts_rank(amount_0/volume_0*adjust_factor_0,20),ts_rank(mean(amount_0,60),4),18),3))*-1\n\nAlpha_95=rank((open_0-ts_min(open_0,12)))<ts_rank((rank(correlation(sum(((high_0+low_0)/ 2),19),sum(mean(amount_0,40),19),13))**5),12)\n\nAlpha_96=max(ts_rank(decay_linear(correlation(rank(amount_0/volume_0*adjust_factor_0),rank(volume_0),4),4),8),ts_rank(decay_linear(ts_argmax(correlation(ts_rank(close_0,7),ts_rank(mean(amount_0,60),4),4),13),14),13))*-1 \n\nAlpha_97=(rank(decay_linear(delta(((low_0*0.721001)+(amount_0/volume_0*adjust_factor_0*(1-0.721001)))/group_mean(industry_sw_level1_0,(low_0*0.721001)+(amount_0/volume_0*adjust_factor_0*(1-0.721001))),3),20)) -ts_rank(decay_linear(ts_rank(correlation(ts_rank(low_0,8),ts_rank(mean(amount_0,60),17),5),16),16),7))*-1\n\nAlpha_98=rank(decay_linear(correlation(amount_0/volume_0*adjust_factor_0,sum(mean(amount_0,5),26),5),7))-rank(decay_linear(ts_rank(ts_argmin(correlation(rank(open_0),rank(mean(amount_0,15)),21),9),7),8))\n\nAlpha_99=(rank(correlation(sum(((high_0+low_0)/2),20),sum(mean(amount_0,60),20),9)) <rank(correlation(low_0,volume_0,6)))*-1\n\nAlpha_100=-1*(((1.5*scale(rank(((((close_0-low_0)-(high_0-close_0))/(high_0-low_0))*volume_0))/group_mean(industry_sw_level2_0,rank(((((close_0-low_0)-(high_0-close_0))/(high_0-low_0))*volume_0)))))-scale((correlation(close_0,rank(mean(amount_0,20)),5)-rank(ts_argmin(close_0,30)))/group_mean(industry_sw_level2_0,(correlation(close_0,rank(mean(amount_0,20)),5)-rank(ts_argmin(close_0,30))))))*(volume_0/mean(amount_0,20)))\n\nAlpha_101=(close_0-open_0)/((high_0-low_0)+0.001) ","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"inner","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","ModuleId":"BigQuantSpace.stock_ranker_predict.stock_ranker_predict-v5","ModuleParameters":[{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"OutputPortsInternal":[{"Name":"predictions","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null},{"Name":"m_lazy_run","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2020-02-20","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-86","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-86"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-86","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-274","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":"120","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-274"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-274"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-274","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-281","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-281"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-281"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-281","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-288","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":"120","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-288"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-288"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-288","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-295","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-295"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-295"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-295","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-6060","ModuleId":"BigQuantSpace.trade.trade-v4","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n \n #print('初始化...')\n \n # 加载预测数据\n # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)\n context.ranker_prediction = context.options['data'].read_df()\n \n #print(context.ranker_prediction.head(10))\n \n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n \n # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只\n stock_count = 1\n \n # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]\n context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])\n \n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 0.5\n context.options['hold_days'] = 2\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n #print('hello')\n # 1. 资金分配\n # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金\n # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)\n is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)\n cash_avg = context.portfolio.portfolio_value / context.options['hold_days']\n cash_for_buy = min(context.portfolio.cash, cash_avg)\n positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items()}\n \n buy_cash_weights = context.stock_weights\n print(ranker_prediction[:5])\n buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])\n \n # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰\n equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}\n instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(\n lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))\n # print('rank order for sell %s' % instruments)\n for instrument in instruments:\n if instrument not in buy_instruments:\n context.order_target(context.symbol(instrument), 0)\n\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument\n for i, instrument in enumerate(buy_instruments):\n cash = cash_for_buy * buy_cash_weights[i]\n if cash > max_cash_per_instrument - positions.get(instrument, 0):\n # 确保股票持仓量不会超过每次股票最大的占用资金量\n cash = max_cash_per_instrument - positions.get(instrument, 0)\n if cash > 0:\n context.order_value(context.symbol(instrument), cash)\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"close","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":"400000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"后复权","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-6060"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-6060"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-6060"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-6060"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-6060"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-6060","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-3776","ModuleId":"BigQuantSpace.filter_stockcode.filter_stockcode-v2","ModuleParameters":[{"Name":"start","Value":"688","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-3776"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-3776","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-3780","ModuleId":"BigQuantSpace.filter_delist_stock.filter_delist_stock-v4","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-3780"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-3780","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-123","ModuleId":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v6","ModuleParameters":[{"Name":"learning_algorithm","Value":"排序","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_leaves","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"minimum_docs_per_leaf","Value":1000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_trees","Value":"30","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"learning_rate","Value":0.1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_bins","Value":1023,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_row_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ndcg_discount_base","Value":"1","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-123"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-123"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-123"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"base_model","NodeId":"-123"}],"OutputPortsInternal":[{"Name":"model","NodeId":"-123","OutputType":null},{"Name":"feature_gains","NodeId":"-123","OutputType":null},{"Name":"m_lazy_run","NodeId":"-123","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='88,-152,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='-101,74,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='545,-351,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='107,318,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='907,647,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1033,-219,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='320,471,200,200'/><NodePosition Node='-86' Position='1026,259,200,200'/><NodePosition Node='-274' Position='280,34,200,200'/><NodePosition Node='-281' Position='284,179,200,200'/><NodePosition Node='-288' Position='1021,-19,200,200'/><NodePosition Node='-295' Position='1018,74,200,200'/><NodePosition Node='-6060' Position='1026,750,200,200'/><NodePosition Node='-3776' Position='1021,394,200,200'/><NodePosition Node='-3780' Position='1025,171,200,200'/><NodePosition Node='-123' Position='633,556,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":true}
    In [3]:
    # 本代码由可视化策略环境自动生成 2020年3月6日 13:33
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m4_initialize_bigquant_run(context):
        
        #print('初始化...')
        
        # 加载预测数据
        # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)
        context.ranker_prediction = context.options['data'].read_df()
        
        #print(context.ranker_prediction.head(10))
        
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
        
        # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只
        stock_count = 1
        
        # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]
        context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])
        
        # 设置每只股票占用的最大资金比例
        context.max_cash_per_instrument = 0.5
        context.options['hold_days'] = 2
    
    
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m4_handle_data_bigquant_run(context, data):
        # 按日期过滤得到今日的预测数据
        ranker_prediction = context.ranker_prediction[
            context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
        #print('hello')
        # 1. 资金分配
        # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金
        # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)
        is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)
        cash_avg = context.portfolio.portfolio_value / context.options['hold_days']
        cash_for_buy = min(context.portfolio.cash, cash_avg)
        positions = {e.symbol: p.amount * p.last_sale_price
                     for e, p in context.perf_tracker.position_tracker.positions.items()}
        
        buy_cash_weights = context.stock_weights
        print(ranker_prediction[:5])
        buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])
        
        # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
        equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}
        instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(
               lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))
        # print('rank order for sell %s' % instruments)
        for instrument in instruments:
            if instrument not in buy_instruments:
                context.order_target(context.symbol(instrument), 0)
    
        # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
        max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument
        for i, instrument in enumerate(buy_instruments):
            cash = cash_for_buy * buy_cash_weights[i]
            if cash > max_cash_per_instrument - positions.get(instrument, 0):
                # 确保股票持仓量不会超过每次股票最大的占用资金量
                cash = max_cash_per_instrument - positions.get(instrument, 0)
            if cash > 0:
                context.order_value(context.symbol(instrument), cash)
    
    
    
    # 回测引擎:准备数据,只执行一次
    def m4_prepare_bigquant_run(context):
        pass
    
    m1 = M.instruments.v2(
        start_date='2012-01-01',
        end_date='2018-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.advanced_auto_labeler.v2(
        instruments=m1.data,
        label_expr="""# #号开始的表示注释
    # 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
    # 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html
    #   添加benchmark_前缀,可使用对应的benchmark数据
    # 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_
    
    # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    #signedpower((shift(close, -5) / shift(open, -1)-1),log10(market_cap_float)/pe_ttm)
    #where((shift(close, -3) / shift(open, -1) > 0) & (correlation(close, amount, -3)>0),correlation(close, amount, -3) ,0)
    (shift(close, -2) / shift(open, -1) - 1)*100
    # 极值处理:用1%和99%分位的值做clip
    clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
    
    # 将分数映射到分类,这里使用20个分类
    all_wbins(label, 60)
    
    # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
    where(shift(high, -1) == shift(low, -1), NaN, label)
    """,
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=True,
        cast_label_int=True
    )
    
    m3 = M.input_features.v1(
        features="""Alpha_1=where(mean(amount_0,20)<volume_0,((-1*ts_rank(abs(delta(close_0,7)),60))*sign(delta(close_0,7))),-1)
    
    Alpha_2=rank(ts_argmax(signedpower(where(close_0/shift(close_0,1)-1<0,std(close_0/shift(close_0,1)-1<0,20),close_0),2),5))-0.5
    
    Alpha_3=-1*correlation(rank(delta(log(volume_0),2)),rank(((close_0-open_0)/open_0)),6)
    
    Alpha_4=-1*correlation(rank(open_0),rank(volume_0),10)
    
    Alpha_5=-1*ts_rank(rank(low_0),9)
    
    Alpha_6=rank((open_0-(sum(amount_0/volume_0*adjust_factor_0,10)/10)))*(-1*abs(rank((close_0-amount_0/volume_0*adjust_factor_0))))
    
    Alpha_7=-1*correlation(open_0,volume_0,10)
    
    Alpha_8=where(mean(amount_0,20)<volume_0,((-1*ts_rank(abs(delta(close_0,7)),60))*sign(delta(close_0,7))),-1)
    
    Alpha_9=(-1*rank(((sum(open_0,5)*sum(close_0/shift(close_0,1)-1,5))-delay((sum(open_0,5)*sum(close_0/shift(close_0,1)-1,5)),10))))
    
    Alpha_10=where(0<ts_min(delta(close_0,1),5),delta(close_0,1),where(ts_max(delta(close_0,1),5)<0,delta(close_0,1),-1*delta(close_0,1)))
    
    Alpha_11=rank(where(0<ts_min(delta(close_0,1),4),delta(close_0,1),where(ts_max(delta(close_0,1),4)<0,delta(close_0,1),-1*delta(close_0,1))))
    
    Alpha_12=(rank(ts_max((amount_0/volume_0*adjust_factor_0-close_0),3))+rank(ts_min((amount_0/volume_0*adjust_factor_0-close_0),3)))*rank(delta(volume_0,3))
    
    Alpha_13=sign(delta(volume_0,1))*(-1*delta(close_0,1))
    
    Alpha_14=-1*rank(covariance(rank(close_0),rank(volume_0),5))
    
    Alpha_15=(-1*rank(delta(close_0/shift(close_0,1)-1,3)))*correlation(open_0,volume_0,10)
    
    Alpha_16=-1*sum(rank(correlation(rank(high_0),rank(volume_0),3)),3)
    
    Alpha_17=-1*rank(covariance(rank(high_0),rank(volume_0),5))
    
    Alpha_18=((-1*rank(ts_rank(close_0,10)))*rank(delta(delta(close_0,1),1)))*rank(ts_rank((volume_0/mean(amount_0,20)),5))
    
    Alpha_19=-1*rank(((std(abs((close_0-open_0)),5)+(close_0-open_0))+correlation(close_0,open_0,10)))
    
    Alpha_20=(-1*sign(((close_0-delay(close_0,7))+delta(close_0,7))))*(1+rank((1+sum(close_0/shift(close_0,1)-1,250))))
    
    Alpha_21=((-1*rank((open_0-delay(high_0,1))))*rank((open_0-delay(close_0,1))))*rank((open_0-delay(low_0,1)))
    
    Alpha_22=where(sum(close_0,8)/8+stddev(close_0,8)<sum(close_0,2)/2,-1,where(mean(close_0,2)<mean(close_0,8)-std(close_0,8),1,where((1<volume_0/mean(amount_0,20)) |(volume_0/mean(amount_0,20)==1),1,-1)))
    
    Alpha_23=-1*(delta(correlation(high_0,volume_0,5),5)*rank(std(close_0,20)))
    
    Alpha_24=where(sum(high_0,20)/20<high_0,-1*delta(high_2,0),0)
    
    Alpha_25=where((delta(mean(close_0,100),100)/delay(close_0,100)<0.05)  |(delta(mean(close_0,100),100)/delay(close_0,100)==0.05) ,-1*(close_0-ts_min(close_0,100)),-1*delta(close_0,2))
    
    Alpha_26=rank(-1*(close_0/shift(close_0,1)-1)*mean(amount_0,20)*amount_0/volume_0*adjust_factor_0*(high_0-close_0))
    
    Alpha_27=-1*ts_max(correlation(ts_rank(volume_0,5),ts_rank(high_0,5),5),3)
    
    Alpha_28=where(0.5<rank((sum(correlation(rank(volume_0),rank(amount_0/volume_0*adjust_factor_0),6),2)/2.0)),-1,1)
    
    Alpha_29=scale(correlation(mean(amount_0,20),low_0,5)+(high_0+low_0)*0.5-close_0)
    
    Alpha_30=min(product(rank(rank(scale(log(sum(ts_min(rank(rank((-1*rank(delta((close_0-1),5))))),2),1))))),1),5)+ts_rank(delay((-1*shift(close_0,1)/close_0-1),6),5)
    
    Alpha_31=((1.0-rank(((sign((close_0-delay(close_0,1)))+sign((delay(close_0,1)-delay(close_0,2)))) +sign((delay(close_0,2)-delay(close_0,3))))))*sum(volume_0,5))/sum(volume_0,20)
    
    Alpha_32=(rank(rank(rank(decay_linear((-1*rank(rank(delta(close_0,10)))),10))))+rank((-1*delta(close_0,3))))+sign(scale(correlation(mean(amount_0,20),low_0,12)))
    
    Alpha_33=scale(((sum(close_0,7)/7)-close_0))+20*scale(correlation(amount_0/volume_0*adjust_factor_0,delay(close_0,5),230))
    
    Alpha_34=rank((-1*((1-(open_0/close_0)))))
    
    Alpha_35=rank(((1-rank((std(close_0/shift(close_0,1),2)/stddev(close_0/shift(close_0,1)-1,5))))+(1-rank(delta(close_0,1))))) 
    
    Alpha_36=ts_rank(volume_0,32)*(1-ts_rank(((close_0+high_0)-low_0),16))*(1-ts_rank(close_0/shift(close_0,1)-1,32))
    
    Alpha_37=((((2.21*rank(correlation((close_0-open_0),delay(volume_0,1),15)))+(0.7*rank((open_0-close_0))))+(0.73*rank(ts_rank(delay((-1*close_0/shift(close_0,1)-1),6),5))))+rank(abs(correlation(amount_0/volume_0*adjust_factor_0,mean(amount_0,20),6))))+(0.6*rank((((sum(close_0,200)/200)-open_0)*(close_0-open_0)))) 
    
    Alpha_38=rank(correlation(delay((open_0-close_0),1),close_0,200))+rank((open_0-close_0))
    
    Alpha_39=(-1*rank(ts_rank(close_0,10)))*rank((close_0/open_0))
    
    Alpha_40=((-1*rank((delta(close_0,7)*(1-rank(decay_linear((volume_0/mean(amount_0,20)),9))))))*(1 +rank(sum(close_0/shift(close_0,1),250))))
    
    Alpha_41=((-1*rank(std(high_0,10)))*correlation(high_0,volume_0,10))
    
    Alpha_42=(((high_0*low_0)**0.5)-amount_0/volume_0*adjust_factor_0)
    
    Alpha_43=(rank((amount_0/volume_0*adjust_factor_0-close_0))/rank((amount_0/volume_0*adjust_factor_0+close_0)))
    
    Alpha_44=(ts_rank((volume_0/mean(amount_0,20)),20)*ts_rank((-1*delta(close_0,7)),8))
    
    Alpha_45=(-1*correlation(high_0,rank(volume_0),5))
    
    Alpha_46=(-1*((rank((sum(delay(close_0,5),20)/20))*correlation(close_0,volume_0,2))*rank(correlation(sum(close_0,5),sum(close_0,20),2))))
    
    Alpha_47=where((0.25<(((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))),-1,where(((((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))<0),1,((-1*1)*(close_0-delay(close_0,1)))))
    
    Alpha_48=(((rank((1/close_0))*volume_0)/mean(amount_0,20))*((high_0*rank((high_0-close_0)))/(sum(high_0,5) /5)))-rank((amount_0/volume_0*adjust_factor_0-delay(amount_0/volume_0*adjust_factor_0,5)))
    
    Alpha_49=((correlation(delta(close_0,1),delta(delay(close_0,1),1),250)*delta(close_0,1))/close_0)/group_mean(industry_sw_level1_0,((correlation(delta(close_0,1),delta(delay(close_0,1),1),250)*delta(close_0,1))/close_0))/sum(((delta(close_0,1)/delay(close_0,1))**2),250)   
    
    Alpha_50=where(((((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))<(-1*0.1)),1,(close_0-delay(close_0,1))*(-1))   
    
    Alpha_51=(-1*ts_max(rank(correlation(rank(volume_0),rank(amount_0/volume_0*adjust_factor_0),5)),5))
    
    Alpha_52=where((((delay(close_0,20)-delay(close_0,10))/10)-((delay(close_0,10)-close_0)/10))<(-1*0.05),1,-1*(close_0-delay(close_0,1)))
    
    Alpha_53=(((-1*ts_min(low_0,5))+delay(ts_min(low_0,5),5))*rank(((sum(close_0/shift(close_0,1),240)-sum(close_0/shift(close_0,1),20))/220)))*ts_rank(volume_0,5)
    
    Alpha_54=(-1*delta((((close_0-low_0)-(high_0-close_0))/(close_0-low_0)),9))
    
    Alpha_55=((-1*((low_0-close_0)*(open_0**5)))/((low_0-high_0)*(close_0** 5))) 
    
    Alpha_56=-1*correlation(rank(((close_0-ts_min(low_0,12))/(ts_max(high_0,12)-ts_min(low_0,12)))),rank(volume_0),6)
    
    Alpha_57=0-1*(1*(rank((sum(close_0/shift(close_0,1)-1,10)/sum(sum(close_0/shift(close_0,1)-1,2),3)))*rank(((close_0/shift(close_0,1)-1)*market_cap_0)))) 
    
    Alpha_58=(0-(1*((close_0-amount_0/volume_0*adjust_factor_0)/decay_linear(rank(ts_argmax(close_0,30)),2)))) 
    
    Alpha_59=(-1*ts_rank(decay_linear(correlation( amount_0/volume_0*adjust_factor_0/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),volume_0,4),8),5))
    
    Alpha_60=(0-(1*((2*scale(rank(((((close_0-low_0)-(high_0-close_0))/(high_0-low_0))*volume_0))))-scale(rank(ts_argmax(close_0,10))))))
    
    Alpha_61=(rank((amount_0/volume_0*adjust_factor_0-ts_min(amount_0/volume_0*adjust_factor_0,16)))<rank(correlation(amount_0/volume_0*adjust_factor_0,mean(amount_0,180),18)))
    
    Alpha_62=(rank(correlation(amount_0/volume_0*adjust_factor_0,sum(mean(amount_0,20),22),10))<rank(((rank(open_0)+rank(open_0))<(rank(((high_0+low_0)/2))+rank(high_0)))))*-1
    
    Alpha_63=((rank(decay_linear(delta(close_0/group_mean(industry_sw_level1_0,close_0),2),8))-rank(decay_linear(correlation(((amount_0/volume_0*adjust_factor_0*0.318108)+(open_0*(1-0.318108))),sum(mean(amount_0,180),37),14),12)))*-1)
    
    Alpha_64=((rank(correlation(sum(((open_0*0.178404)+(low_0*(1-0.178404))),13),sum(mean(amount_0,20),13),17))<rank(delta(((((high_0+low_0)/2)*0.178404)+(amount_0/volume_0*adjust_factor_0*(1-0.178404))),4)))*-1)
    
    Alpha_65=((rank(correlation(((open_0*0.00817205)+(amount_0/volume_0*adjust_factor_0*(1-0.00817205))),sum(mean(amount_0,60),9),6))<rank((open_0-ts_min(open_0,14))))*-1)
    
    Alpha_66=((rank(decay_linear(delta(amount_0/volume_0*adjust_factor_0,4),7))+ts_rank(decay_linear(((((low_0* 0.96633)+(low_0*(1-0.96633)))-amount_0/volume_0*adjust_factor_0)/(open_0-((high_0+low_0)/2))),11),7))*-1)
    
    Alpha_67=((rank((high_0-ts_min(high_0,2)))**rank(correlation( amount_0/volume_0*adjust_factor_0 /group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),mean(amount_0,20)/group_mean(industry_sw_level1_0,mean(amount_0,20)),6)))*-1)
    
    Alpha_68=((ts_rank(correlation(rank(high_0),rank(mean(amount_0,15)),9),14)<rank(delta(((close_0*0.518371)+(low_0*(1-0.518371))),1.06157)))*-1)
    
    Alpha_69=((rank(ts_max(delta(amount_0/volume_0*adjust_factor_0/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),3),5))**ts_rank(correlation(((close_0*0.490655)+(amount_0/volume_0*adjust_factor_0*(1-0.490655))),mean(amount_0,20),5),9))*-1)
    
    Alpha_70=((rank(delta(amount_0/volume_0*adjust_factor_0,1))**ts_rank(correlation(  close_0/group_mean(industry_sw_level1_0,close_0),mean(amount_0,50),18),18))*-1)
    
    Alpha_71=max(ts_rank(decay_linear(correlation(ts_rank(close_0,3),ts_rank(mean(amount_0,180),12),18),4),16),ts_rank(decay_linear((rank(((low_0+open_0)-(amount_0/volume_0*adjust_factor_0 +amount_0/volume_0*adjust_factor_0)))**2),16 ),4))
    
    Alpha_72=(rank(decay_linear(correlation(((high_0+low_0)/2),mean(amount_0,40),9),10)) /rank(decay_linear(correlation(ts_rank(amount_0/volume_0*adjust_factor_0,4),ts_rank(volume_0,19),7),3)))
    
    Alpha_73=(max(rank(decay_linear(delta(amount_0/volume_0*adjust_factor_0,5),3)),ts_rank(decay_linear(((delta(((open_0* 0.147155)+(low_0*(1-0.147155))),2 ) /((open_0* 0.147155)+(low_0*(1-0.147155))))*-1),3),17))*-1)     
    
    Alpha_74=(rank(correlation(close_0,sum(mean(amount_0,30),37),15))<rank(correlation(rank(high_0*0.0261661+amount_0/volume_0*adjust_factor_0*(1-0.0261661)),rank(volume_0),11)))*-1
    
    Alpha_75=rank(correlation(amount_0/volume_0*adjust_factor_0,volume_0,4 ))<rank(correlation(rank(low_0),rank(mean(amount_0,50)),12))
    
    Alpha_76=max(rank(decay_linear(delta(amount_0/volume_0*adjust_factor_0,1),12)),ts_rank(decay_linear(ts_rank(correlation( low_0/group_mean(industry_sw_level1_0,low_0),mean(amount_0,81),8 ),20),17),19))*-1
    
    Alpha_77=min(rank(decay_linear(((((high_0+low_0)/2)+high_0)-(amount_0/volume_0*adjust_factor_0+high_0)),20 )),rank(decay_linear(correlation(((high_0+low_0)/2),mean(amount_0,40),3),6)))
    
    Alpha_78=rank(correlation(sum(((low_0*0.352233)+(amount_0/volume_0*adjust_factor_0*(1-0.352233))),20),sum(mean(amount_0,20),20),7))**rank(correlation(rank(amount_0/volume_0*adjust_factor_0),rank(volume_0),6))
    
    Alpha_79=rank(delta((close_0*0.60733+open_0*(1-0.60733))/ group_mean(industry_sw_level1_0,(close_0*0.60733+open_0*(1-0.60733))),1))<rank(correlation(ts_rank(amount_0/volume_0*adjust_factor_0,4),ts_rank(mean(amount_0,150),9),115))
    
    Alpha_80=(rank(sign(delta((open_0*0.868128+high_0*(1-0.868128))/group_mean(industry_sw_level1_0,(open_0*0.868128+high_0*(1-0.868128))),4)))**ts_rank(correlation(high_0,mean(amount_0,10),5),6))*-1
    
    Alpha_81=(rank(log(product(rank((rank(correlation(amount_0/volume_0*adjust_factor_0,sum(mean(amount_0,10),50),8))**4)),15)))<rank(correlation(rank(amount_0/volume_0*adjust_factor_0),rank(volume_0),5)))*-1
    
    Alpha_82=min(rank(decay_linear(delta(open_0,1.46063),15)),ts_rank(decay_linear(correlation( volume_0/group_mean(industry_sw_level1_0,volume_0),((open_0*0.634196) +(open_0*(1-0.634196))),17),7),13))*-1
    
    Alpha_83=(rank(delay(((high_0-low_0)/(sum(close_0,5)/5)),2))*rank(rank(volume_0)))/(((high_0-low_0)/(sum(close_0,5)/5))/(amount_0/volume_0*adjust_factor_0-close_0))
    
    Alpha_84=signedpower(ts_rank((amount_0/volume_0*adjust_factor_0-ts_max(amount_0/volume_0*adjust_factor_0,15)),20),delta(close_0,5))
    
    Alpha_85=rank(correlation(((high_0*0.876703)+(close_0*(1-0.876703))),mean(amount_0,30),10))**rank(correlation(ts_rank(((high_0+low_0)/2),4),ts_rank(volume_0,10),7))
    
    Alpha_86=(ts_rank(correlation(close_0,sum(mean(amount_0,20),15),6),20)<rank(((open_0+close_0)-(amount_0/volume_0*adjust_factor_0+open_0))))*-1
    
    Alpha_87=max(rank(decay_linear(delta(((close_0*0.369701)+(amount_0/volume_0*adjust_factor_0*(1-0.369701))),2),3)),ts_rank(decay_linear(abs(correlation( mean(amount_0,81) /group_mean(industry_sw_level1_0,mean(amount_0,81)) ,close_0,14)),5),14))*-1
    
    Alpha_88=min(rank(decay_linear(((rank(open_0)+rank(low_0))-(rank(high_0)+rank(close_0))),8)),ts_rank(decay_linear(correlation(ts_rank(close_0,8),ts_rank(mean(amount_0,60),21),8),7),3))
    
    Alpha_89=ts_rank(decay_linear(correlation(((low_0*0.967285)+(low_0*(1-0.967285))),mean(amount_0,10),7),6),4)-ts_rank(decay_linear(delta( amount_0/volume_0*adjust_factor_0/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0),3),10),15)
    
    Alpha_90=(rank((close_0-ts_max(close_0,5)))**ts_rank(correlation(mean(amount_0,40)/group_mean(industry_sw_level1_0,mean(amount_0,40)),low_0,5),3))*-1
    
    Alpha_91=(ts_rank(decay_linear(decay_linear(correlation(close_0/group_mean(industry_sw_level1_0,close_0),volume_0,10),16),4),5)-rank(decay_linear(correlation(amount_0/volume_0*adjust_factor_0,mean(amount_0,30),4),3)))*-1
    
    Alpha_92=min(ts_rank(decay_linear(((((high_0+low_0)/2)+close_0)<(low_0+open_0)),15),19),ts_rank(decay_linear(correlation(rank(low_0),rank(mean(amount_0,30)),8),7),7))
    
    Alpha_93=ts_rank(decay_linear(correlation((amount_0/volume_0*adjust_factor_0)/group_mean(industry_sw_level1_0,amount_0/volume_0*adjust_factor_0) ,mean(amount_0,81),17),20),8)/rank(decay_linear(delta(((close_0*0.524434)+(amount_0/volume_0*adjust_factor_0*(1-0.524434))),3),16))
    
    Alpha_94=(rank((amount_0/volume_0*adjust_factor_0-ts_min(amount_0/volume_0*adjust_factor_0,12)))**ts_rank(correlation(ts_rank(amount_0/volume_0*adjust_factor_0,20),ts_rank(mean(amount_0,60),4),18),3))*-1
    
    Alpha_95=rank((open_0-ts_min(open_0,12)))<ts_rank((rank(correlation(sum(((high_0+low_0)/ 2),19),sum(mean(amount_0,40),19),13))**5),12)
    
    Alpha_96=max(ts_rank(decay_linear(correlation(rank(amount_0/volume_0*adjust_factor_0),rank(volume_0),4),4),8),ts_rank(decay_linear(ts_argmax(correlation(ts_rank(close_0,7),ts_rank(mean(amount_0,60),4),4),13),14),13))*-1     
    
    Alpha_97=(rank(decay_linear(delta(((low_0*0.721001)+(amount_0/volume_0*adjust_factor_0*(1-0.721001)))/group_mean(industry_sw_level1_0,(low_0*0.721001)+(amount_0/volume_0*adjust_factor_0*(1-0.721001))),3),20)) -ts_rank(decay_linear(ts_rank(correlation(ts_rank(low_0,8),ts_rank(mean(amount_0,60),17),5),16),16),7))*-1
    
    Alpha_98=rank(decay_linear(correlation(amount_0/volume_0*adjust_factor_0,sum(mean(amount_0,5),26),5),7))-rank(decay_linear(ts_rank(ts_argmin(correlation(rank(open_0),rank(mean(amount_0,15)),21),9),7),8))
    
    Alpha_99=(rank(correlation(sum(((high_0+low_0)/2),20),sum(mean(amount_0,60),20),9)) <rank(correlation(low_0,volume_0,6)))*-1
    
    Alpha_100=-1*(((1.5*scale(rank(((((close_0-low_0)-(high_0-close_0))/(high_0-low_0))*volume_0))/group_mean(industry_sw_level2_0,rank(((((close_0-low_0)-(high_0-close_0))/(high_0-low_0))*volume_0)))))-scale((correlation(close_0,rank(mean(amount_0,20)),5)-rank(ts_argmin(close_0,30)))/group_mean(industry_sw_level2_0,(correlation(close_0,rank(mean(amount_0,20)),5)-rank(ts_argmin(close_0,30))))))*(volume_0/mean(amount_0,20)))
    
    Alpha_101=(close_0-open_0)/((high_0-low_0)+0.001) """
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=120
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m7 = M.join.v3(
        data1=m2.data,
        data2=m16.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m7.data
    )
    
    m11 = M.stock_ranker_train.v6(
        training_ds=m13.data,
        features=m3.data,
        learning_algorithm='排序',
        number_of_leaves=30,
        minimum_docs_per_leaf=1000,
        number_of_trees=30,
        learning_rate=0.1,
        max_bins=1023,
        feature_fraction=1,
        data_row_fraction=1,
        ndcg_discount_base=1,
        m_lazy_run=False
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2018-01-01'),
        end_date=T.live_run_param('trading_date', '2020-02-20'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m17 = M.general_feature_extractor.v7(
        instruments=m9.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=120
    )
    
    m18 = M.derived_feature_extractor.v3(
        input_data=m17.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m10 = M.filter_delist_stock.v4(
        input_1=m18.data
    )
    
    m14 = M.dropnan.v1(
        input_data=m10.data_1
    )
    
    m5 = M.filter_stockcode.v2(
        input_1=m14.data,
        start='688'
    )
    
    m8 = M.stock_ranker_predict.v5(
        model=m11.model,
        data=m5.data_1,
        m_lazy_run=False,
        m_cached=False
    )
    
    m4 = M.trade.v4(
        instruments=m9.data,
        options_data=m8.predictions,
        start_date='',
        end_date='',
        initialize=m4_initialize_bigquant_run,
        handle_data=m4_handle_data_bigquant_run,
        prepare=m4_prepare_bigquant_run,
        volume_limit=0,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=400000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='后复权',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark=''
    )
    

    StockRanker训练(GBDT)(stock_ranker_train)使用错误,你可以:

    1.一键查看文档

    2.一键搜索答案

    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-3-c646971912ca> in <module>()
        354     data_row_fraction=1,
        355     ndcg_discount_base=1,
    --> 356     m_lazy_run=False
        357 )
        358 
    
    ValueError: max() arg is an empty sequence
    In [ ]:
     
    

    (iQuant) #2

    收到 我们帮您看一下。


    (zacharyhu) #3

    有帮忙定位到问题原因吗?


    (temp2205) #4

    同问同问同问


    (大胡子) #5

    主要原因是特征(因子)在重命名的时候,格式在解析的时候出错了。

    将等号两边留出空格符 就没问题,亲测有效。
    这样改一下就行: