老师您好,我这里序列窗口滚动(深度学习)(dl_convert_to_bin)使用错误,能帮我看看么?

策略分享
标签: #<Tag:0x00007fc4ccee96a0>

(woshisilvio) #1

https://i.bigquant.com/user/woshisilvio/lab/share/dnn-AI选股.ipynb?_t=1584500003204
https://i.bigquant.com/user/woshisilvio/lab/share/dnn-AI选股.ipynb

KeyError Traceback (most recent call last)
in ()
306 feature_clip=5,
307 flatten=True,
–> 308 window_along_col=‘instrument’
309 )
310

KeyError: “[‘buy_condition=where((mean(close_0,5)>mean(close_0,10))&(mean(close_0,10)>mean(close_0,20))&(mean(close_0,20)>mean(close_0,40))&(mean(close_0,40)>mean(close_0,120))&(low_0<mean(close_0,10)),1,0)’\n ‘sell_condition=where(mean(close_0,5)<mean(close_0,40),1,0)’] not in index”
老师您好,我想在因子特征里面添加一个买入卖出条件,实现买入信号和卖出信号,让AI帮我在这些位置买入卖出股票,为什么这里会报错呢?
另外,如果我想实现 在当日收盘价突破布林线中线买入,在当日收盘价跌出布林线上线卖出,该怎么构造因子输入条件呢?
ta_bbands_m(close, timeperiod)
ta_bbands_lowerband_28_0
ta_bbands_upperband_28_0


(woshisilvio) #2
克隆策略
In [11]:
m5.raw_perf,m19.raw_perf
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-11-ce75b6b3471a> in <module>()
----> 1 m5.raw_perf,m19.raw_perf
      2 

NameError: name 'm5' is not defined

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-106: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":"-106:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-113:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-122:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-129:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-232:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-240:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-232:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-122:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-141:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-113:input_data","SourceOutputPortId":"-106:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-113:data"},{"DestinationInputPortId":"-129:input_data","SourceOutputPortId":"-122:data"},{"DestinationInputPortId":"-2431:input_2","SourceOutputPortId":"-129:data"},{"DestinationInputPortId":"-240:input_data","SourceOutputPortId":"-129:data"},{"DestinationInputPortId":"-168:inputs","SourceOutputPortId":"-160:data"},{"DestinationInputPortId":"-682:inputs","SourceOutputPortId":"-160:data"},{"DestinationInputPortId":"-224:inputs","SourceOutputPortId":"-168:data"},{"DestinationInputPortId":"-231:inputs","SourceOutputPortId":"-196:data"},{"DestinationInputPortId":"-196:inputs","SourceOutputPortId":"-224:data"},{"DestinationInputPortId":"-238:inputs","SourceOutputPortId":"-231:data"},{"DestinationInputPortId":"-682:outputs","SourceOutputPortId":"-238:data"},{"DestinationInputPortId":"-1098:input_model","SourceOutputPortId":"-682:data"},{"DestinationInputPortId":"-1540:trained_model","SourceOutputPortId":"-1098:data"},{"DestinationInputPortId":"-2431:input_1","SourceOutputPortId":"-1540:data"},{"DestinationInputPortId":"-141:options_data","SourceOutputPortId":"-2431:data_1"},{"DestinationInputPortId":"-1098:training_data","SourceOutputPortId":"-232:data"},{"DestinationInputPortId":"-1540:input_data","SourceOutputPortId":"-240:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2017-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000004.SZA\n000001.SZA\n000002.SZA\n600800.SHA\n002498.SZA\n300212.SZA\n300576.SZA\n002879.SZA\n300363.SZA\n002291.SZA\n002023.SZA\n600196.SHA\n600161.SHA\n002007.SZA\n300543.SZA\n300525.SZA\n300607.SZA\n300316.SZA\n002409.SZA\n300236.SZA\n603707.SHA\n002371.SZA\n300413.SZA\n600536.SHA\n002555.SZA\n603160.SHA\n300455.SZA\n600570.SHA\n300033.SZA\n002396.SZA\n603859.SHA\n000661.SZA\n603986.SHA\n600588.SHA\n300122.SZA\n600585.SHA\n603160.SHA\n300142.SZA\n300706.SZA\n000938.SZA\n002230.SZA\n603939.SHA\n002714.SZA\n600745.SHA\n603501.SHA\n002153.SZA\n000895.SZA\n300347.SZA\n601888.SHA\n300750.SZA\n603288.SHA\n300552.SZA\n300526.SZA\n002552.SZA\n603501.SHA\n300661.SZA\n300223.SZA\n002351.SZA\n300573.SZA\n300759.SZA\n300803.SZA\n300775.SZA\n300661.SZA\n601865.SHA\n002600.SZA\n300785.SZA\n300777.SZA\n002869.SZA\n601236.SHA\n300220.SZA\n300797.SZA\n603093.SHA\n300799.SZA\n300709.SZA\n603613.SHA\n300792.SZA\n002937.SZA\n300783.SZA\n601066.SHA\n601698.SHA\n002945.SZA\n002458.SZA\n603927.SHA\n603068.SHA\n300379.SZA\n002201.SZA\n603986.SHA\n000066.SZA\n600131.SHA\n002475.SZA\n300341.SZA\n300397.SZA\n300014.SZA\n002791.SZA\n002463.SZA\n600519.SHA\n600809.SHA\n000858.SZA\n000596.SZA\n600132.SHA\n600779.SHA\n600776.SHA\n000622.SZA\n002607.SZA\n300107.SZA\n002243.SZA\n000860.SZA\n300559.SZA\n000860.SZA\n603605.SHA\n603039.SHA\n300253.SZA\n300550.SZA\n300596.SZA\n603345.SHA\n300451.SZA\n002399.SZA\n600604.SHA\n600556.SHA\n603283.SHA\n002708.SZA\n600408.SHA\n600235.SHA\n300598.SZA\n002755.SZA\n000953.SZA\n000760.SZA\n002921.SZA\n002864.SZA\n002795.SZA\n002575.SZA\n002288.SZA\n000068.SZA\n002927.SZA\n603032.SHA\n600247.SHA\n002931.SZA\n300746.SZA\n601330.SHA\n300748.SZA\n603712.SHA\n002927.SZA\n601606.SHA\n300747.SZA\n601162.SHA\n603056.SHA\n002415.SZA\n300003.SZA\n002963.SZA\n002236.SZA\n300124.SZA\n300296.SZA\n300253.SZA\n002475.SZA\n000333.SZA\n600886.SHA\n000703.SZA\n600438.SHA\n600482.SHA\n600661.SHA\n002955.SZA\n002465.SZA\n600739.SHA\n601989.SHA\n600601.SHA\n600654.SHA\n600887.SHA\n000626.SZA\n000538.SZA\n000002.SZA\n600118.SHA\n000568.SZA\n600620.SHA\n600570.SHA\n000060.SZA\n000503.SZA\n300674.SZA\n600903.SHA\n300487.SZA\n300647.SZA\n002776.SZA\n300670.SZA\n300107.SZA\n300730.SZA\n300027.SZA\n601899.SHA\n300352.SZA\n000636.SZA\n002092.SZA\n000980.SZA\n600704.SHA\n002635.SZA\n000709.SZA\n000050.SZA\n300079.SZA\n300296.SZA\n002405.SZA\n600660.SHA\n601088.SHA\n000338.SZA\n600697.SHA\n000803.SZA\n000895.SZA\n300223.SZA\n002826.SZA\n002371.SZA\n002218.SZA\n300676.SZA\n300015.SZA\n000625.SZA\n000063.SZA\n300148.SZA\n603288.SHA\n601668.SHA\n600839.SHA\n002466.SZA\n000876.SZA\n002234.SZA\n600332.SHA\n002024.SZA\n600547.SHA\n002038.SZA\n000651.SZA\n002035.SZA\n002032.SZA\n300498.SZA\n002022.SZA\n600048.SHA\n600489.SHA\n600436.SHA\n600031.SHA\n000402.SZA\n600309.SHA\n000423.SZA\n600521.SHA\n600500.SHA\n600030.SHA\n600993.SHA\n600522.SHA\n002230.SZA\n600853.SHA\n002838.SZA\n002414.SZA\n300628.SZA\n002239.SZA\n300160.SZA\n300578.SZA\n603200.SHA\n002613.SZA\n000652.SZA\n002824.SZA\n300677.SZA\n300235.SZA\n600516.SHA\n000425.SZA\n002607.SZA\n600789.SHA\n000518.SZA\n300346.SZA\n300236.SZA\n300706.SZA\n300666.SZA\n600276.SHA\n600422.SHA\n300601.SZA\n002223.SZA\n002916.SZA\n300632.SZA\n300450.SZA\n300014.SZA\n002841.SZA\n002463.SZA\n603160.SHA\n600183.SHA\n603178.SHA\n600242.SHA\n603825.SHA\n603738.SHA\n603920.SHA\n603005.SHA\n600513.SHA\n603598.SHA\n603608.SHA\n300176.SZA\n601313.SHA\n000830.SZA\n601012.SHA\n002460.SZA\n002415.SZA\n600460.SHA\n600779.SHA\n603690.SHA\n603533.SHA\n300708.SZA\n300725.SZA\n603032.SHA\n002833.SZA\n300618.SZA\n603929.SHA\n002836.SZA\n000830.SZA\n601012.SHA\n002460.SZA\n300585.SZA\n000935.SZA\n603876.SHA\n601116.SHA\n002695.SZA\n300174.SZA\n002089.SZA\n300340.SZA\n300431.SZA\n300364.SZA\n002751.SZA\n300446.SZA\n300451.SZA\n002506.SZA\n300469.SZA\n000025.SZA\n603601.SHA\n002739.SZA\n300410.SZA\n300467.SZA\n002747.SZA\n300437.SZA\n600053.SHA\n002075.SZA\n300479.SZA\n300078.SZA\n300383.SZA\n002771.SZA\n300458.SZA\n300422.SZA\n300441.SZA\n300302.SZA\n600165.SHA\n300429.SZA\n300480.SZA\n603318.SHA\n002027.SZA\n603678.SHA\n300299.SZA\n002741.SZA\n300457.SZA\n603918.SHA\n603169.SHA\n603019.SHA\n600399.SHA\n300162.SZA\n600317.SHA\n300033.SZA\n600556.SHA\n000693.SZA\n300324.SZA\n002544.SZA","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日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -5) / shift(open, -1)-1\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\nwhere(label>0.5, NaN, label)\nwhere(label<-0.5, 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":"False","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":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_5-1\nreturn_10-1\nreturn_20-1\navg_amount_0/avg_amount_5-1\navg_amount_5/avg_amount_20-1\nrank_avg_amount_0-rank_avg_amount_5\nrank_avg_amount_5-rank_avg_amount_10\nrank_return_0-rank_return_5\nrank_return_5-rank_return_10\nbeta_csi300_30_0/10\nbeta_csi300_60_0/10\nswing_volatility_5_0/swing_volatility_30_0-1\nswing_volatility_30_0/swing_volatility_60_0-1\nta_atr_14_0/ta_atr_28_0-1\nta_sma_5_0/ta_sma_20_0-1\nta_sma_10_0/ta_sma_20_0-1\nta_sma_20_0/ta_sma_30_0-1\nta_sma_30_0/ta_sma_60_0-1\nta_rsi_14_0/100\nta_rsi_28_0/100\nta_cci_14_0/500\nta_cci_28_0/500\nbeta_industry_30_0/10\nbeta_industry_60_0/10\nta_sma(amount_0, 10)/ta_sma(amount_0, 20)-1\nta_sma(amount_0, 20)/ta_sma(amount_0, 30)-1\nta_sma(amount_0, 30)/ta_sma(amount_0, 60)-1\nta_sma(amount_0, 50)/ta_sma(amount_0, 100)-1\nta_sma(turn_0, 10)/ta_sma(turn_0, 20)-1\nta_sma(turn_0, 20)/ta_sma(turn_0, 30)-1\nta_sma(turn_0, 30)/ta_sma(turn_0, 60)-1\nta_sma(turn_0, 50)/ta_sma(turn_0, 100)-1\nhigh_0/low_0-1\nclose_0/open_0-1\nshift(close_0,1)/close_0-1\nshift(close_0,2)/close_0-1\nshift(close_0,3)/close_0-1\nshift(close_0,4)/close_0-1\nshift(close_0,5)/close_0-1\nshift(close_0,10)/close_0-1\nshift(close_0,20)/close_0-1\nta_sma(high_0-low_0, 5)/ta_sma(high_0-low_0, 20)-1\nta_sma(high_0-low_0, 10)/ta_sma(high_0-low_0, 20)-1\nta_sma(high_0-low_0, 20)/ta_sma(high_0-low_0, 30)-1\nta_sma(high_0-low_0, 30)/ta_sma(high_0-low_0, 60)-1\nta_sma(high_0-low_0, 50)/ta_sma(high_0-low_0, 100)-1\nrank_avg_amount_5\nrank_avg_turn_5\nrank_volatility_5_0\nrank_swing_volatility_5_0\nrank_avg_mf_net_amount_5\nrank_beta_industry_5_0\nrank_return_5\nrank_return_2\nstd(close_0,5)/std(close_0,20)-1\nstd(close_0,10)/std(close_0,20)-1\nstd(close_0,20)/std(close_0,30)-1\nstd(close_0,30)/std(close_0,60)-1\nstd(close_0,50)/std(close_0,100)-1\n#--------多头排列回踩买入\nbuy_condition=where((mean(close_0,5)>mean(close_0,10))&(mean(close_0,10)>mean(close_0,20))&(mean(close_0,20)>mean(close_0,40))&(mean(close_0,40)>mean(close_0,120))&(low_0<mean(close_0,10)),1,0)\nsell_condition=where(mean(close_0,5)<mean(close_0,40),1,0)\n\nta_bbands_lowerband_28_0\nta_bbands_upperband_28_0","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-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2017-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2020-03-17","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000004.SZA\n000001.SZA\n000002.SZA\n600800.SHA\n002498.SZA\n300212.SZA\n300576.SZA\n002879.SZA\n300363.SZA\n002291.SZA\n002023.SZA\n600196.SHA\n600161.SHA\n002007.SZA\n300543.SZA\n300525.SZA\n300607.SZA\n300316.SZA\n002409.SZA\n300236.SZA\n603707.SHA\n002371.SZA\n300413.SZA\n600536.SHA\n002555.SZA\n603160.SHA\n300455.SZA\n600570.SHA\n300033.SZA\n002396.SZA\n603859.SHA\n000661.SZA\n603986.SHA\n600588.SHA\n300122.SZA\n600585.SHA\n603160.SHA\n300142.SZA\n300706.SZA\n000938.SZA\n002230.SZA\n603939.SHA\n002714.SZA\n600745.SHA\n603501.SHA\n002153.SZA\n000895.SZA\n300347.SZA\n601888.SHA\n300750.SZA\n603288.SHA\n300552.SZA\n300526.SZA\n002552.SZA\n603501.SHA\n300661.SZA\n300223.SZA\n002351.SZA\n300573.SZA\n300759.SZA\n300803.SZA\n300775.SZA\n300661.SZA\n601865.SHA\n002600.SZA\n300785.SZA\n300777.SZA\n002869.SZA\n601236.SHA\n300220.SZA\n300797.SZA\n603093.SHA\n300799.SZA\n300709.SZA\n603613.SHA\n300792.SZA\n002937.SZA\n300783.SZA\n601066.SHA\n601698.SHA\n002945.SZA\n002458.SZA\n603927.SHA\n603068.SHA\n300379.SZA\n002201.SZA\n603986.SHA\n000066.SZA\n600131.SHA\n002475.SZA\n300341.SZA\n300397.SZA\n300014.SZA\n002791.SZA\n002463.SZA\n600519.SHA\n600809.SHA\n000858.SZA\n000596.SZA\n600132.SHA\n600779.SHA\n600776.SHA\n000622.SZA\n002607.SZA\n300107.SZA\n002243.SZA\n000860.SZA\n300559.SZA\n000860.SZA\n603605.SHA\n603039.SHA\n300253.SZA\n300550.SZA\n300596.SZA\n603345.SHA\n300451.SZA\n002399.SZA\n600604.SHA\n600556.SHA\n603283.SHA\n002708.SZA\n600408.SHA\n600235.SHA\n300598.SZA\n002755.SZA\n000953.SZA\n000760.SZA\n002921.SZA\n002864.SZA\n002795.SZA\n002575.SZA\n002288.SZA\n000068.SZA\n002927.SZA\n603032.SHA\n600247.SHA\n002931.SZA\n300746.SZA\n601330.SHA\n300748.SZA\n603712.SHA\n002927.SZA\n601606.SHA\n300747.SZA\n601162.SHA\n603056.SHA\n002415.SZA\n300003.SZA\n002963.SZA\n002236.SZA\n300124.SZA\n300296.SZA\n300253.SZA\n002475.SZA\n000333.SZA\n600886.SHA\n000703.SZA\n600438.SHA\n600482.SHA\n600661.SHA\n002955.SZA\n002465.SZA\n600739.SHA\n601989.SHA\n600601.SHA\n600654.SHA\n600887.SHA\n000626.SZA\n000538.SZA\n000002.SZA\n600118.SHA\n000568.SZA\n600620.SHA\n600570.SHA\n000060.SZA\n000503.SZA\n300674.SZA\n600903.SHA\n300487.SZA\n300647.SZA\n002776.SZA\n300670.SZA\n300107.SZA\n300730.SZA\n300027.SZA\n601899.SHA\n300352.SZA\n000636.SZA\n002092.SZA\n000980.SZA\n600704.SHA\n002635.SZA\n000709.SZA\n000050.SZA\n300079.SZA\n300296.SZA\n002405.SZA\n600660.SHA\n601088.SHA\n000338.SZA\n600697.SHA\n000803.SZA\n000895.SZA\n300223.SZA\n002826.SZA\n002371.SZA\n002218.SZA\n300676.SZA\n300015.SZA\n000625.SZA\n000063.SZA\n300148.SZA\n603288.SHA\n601668.SHA\n600839.SHA\n002466.SZA\n000876.SZA\n002234.SZA\n600332.SHA\n002024.SZA\n600547.SHA\n002038.SZA\n000651.SZA\n002035.SZA\n002032.SZA\n300498.SZA\n002022.SZA\n600048.SHA\n600489.SHA\n600436.SHA\n600031.SHA\n000402.SZA\n600309.SHA\n000423.SZA\n600521.SHA\n600500.SHA\n600030.SHA\n600993.SHA\n600522.SHA\n002230.SZA\n600853.SHA\n002838.SZA\n002414.SZA\n300628.SZA\n002239.SZA\n300160.SZA\n300578.SZA\n603200.SHA\n002613.SZA\n000652.SZA\n002824.SZA\n300677.SZA\n300235.SZA\n600516.SHA\n000425.SZA\n002607.SZA\n600789.SHA\n000518.SZA\n300346.SZA\n300236.SZA\n300706.SZA\n300666.SZA\n600276.SHA\n600422.SHA\n300601.SZA\n002223.SZA\n002916.SZA\n300632.SZA\n300450.SZA\n300014.SZA\n002841.SZA\n002463.SZA\n603160.SHA\n600183.SHA\n603178.SHA\n600242.SHA\n603825.SHA\n603738.SHA\n603920.SHA\n603005.SHA\n600513.SHA\n603598.SHA\n603608.SHA\n300176.SZA\n601313.SHA\n000830.SZA\n601012.SHA\n002460.SZA\n002415.SZA\n600460.SHA\n600779.SHA\n603690.SHA\n603533.SHA\n300708.SZA\n300725.SZA\n603032.SHA\n002833.SZA\n300618.SZA\n603929.SHA\n002836.SZA\n000830.SZA\n601012.SHA\n002460.SZA\n300585.SZA\n000935.SZA\n603876.SHA\n601116.SHA\n002695.SZA\n300174.SZA\n002089.SZA\n300340.SZA\n300431.SZA\n300364.SZA\n002751.SZA\n300446.SZA\n300451.SZA\n002506.SZA\n300469.SZA\n000025.SZA\n603601.SHA\n002739.SZA\n300410.SZA\n300467.SZA\n002747.SZA\n300437.SZA\n600053.SHA\n002075.SZA\n300479.SZA\n300078.SZA\n300383.SZA\n002771.SZA\n300458.SZA\n300422.SZA\n300441.SZA\n300302.SZA\n600165.SHA\n300429.SZA\n300480.SZA\n603318.SHA\n002027.SZA\n603678.SHA\n300299.SZA\n002741.SZA\n300457.SZA\n603918.SHA\n603169.SHA\n603019.SHA\n600399.SHA\n300162.SZA\n600317.SHA\n300033.SZA\n600556.SHA\n000693.SZA\n300324.SZA\n002544.SZA","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":"-106","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":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-106"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-106"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-106","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-113","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":"True","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":"-113"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-113"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-113","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-122","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":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-122"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-122"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-122","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-129","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":"True","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":"-129"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-129"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-129","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-141","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 # 加载预测数据\n context.ranker_prediction = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)\n # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只\n stock_count = 4\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 context.max_cash_per_instrument =0.7\n context.options['hold_days'] =4\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n #获取当日日期\n today = data.current_dt.strftime('%Y-%m-%d')\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]\n #大盘风控模块,读取风控数据 \n benckmark_risk=context.benckmark_risk[today]\n context.symbol\n #当risk为1时,市场有风险,全部平仓,不再执行其它操作\n if benckmark_risk >1:\n for instrument in stock_hold_now:\n context.order_target(symbol(instrument), 0)\n print(today,'大盘风控止损触发,全仓卖出')\n return\n \n \n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n \n\n# try:\n# prediction = context.prediction[data.current_dt.strftime('%Y-%m-%d')]\n# except KeyError as e:\n# return\n \n instrument = context.instruments[0]\n sid = context.symbol(instrument)\n cur_position = context.portfolio.positions[sid].amount\n \n # 交易逻辑\n# if prediction > 0.5 and cur_position == 0:\n# context.order_target_percent(context.symbol(instrument), 1)\n# print(data.current_dt, '买入!')\n \n# elif prediction < 0.5 and cur_position > 0:\n# context.order_target_percent(context.symbol(instrument), 0)\n# print(data.current_dt, '卖出!')\n \n \n #跟踪止盈止损------设定若回调4%止盈, 止损\n \n #------------------------------------------止损模块START--------------------------------------------\n equities = {e.symbol: p for e, p in context.portfolio.positions.items() if p.amount>0}\n \n # 新建当日止损股票列表是为了handle_data 策略逻辑部分不再对该股票进行判断\n stoploss_stock = [] \n if len(equities) > 0:\n for i in equities.keys():\n stock_market_price = data.current(context.symbol(i), 'price') # 最新市场价格\n last_sale_date = equities[i].last_sale_date # 上次交易日期\n delta_days = data.current_dt - last_sale_date \n hold_days = delta_days.days # 持仓天数\n # 建仓以来的最高价\n highest_price_since_buy = data.history(context.symbol(i), 'high', hold_days, '1d').max()\n # 确定止损位置5%\n stoploss_line = highest_price_since_buy - highest_price_since_buy * 0.05\n #record('止损位置', stoploss_line)\n # 如果价格下穿止损位置\n if stock_market_price < stoploss_line:\n context.order_target_percent(context.symbol(i), 0) \n stoploss_stock.append(i)\n if len(stoploss_stock)>0:\n print('日期:', today, '股票:', stoploss_stock, '出现跟踪止损状况')\n #-------------------------------------------止损模块END--------------------------------------------- \n \n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n\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, (1 if is_staging else 1.5) * cash_avg)\n cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)\n positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items()}\n\n sell_stock = []\n # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰\n if not is_staging and cash_for_sell > 0:\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 for instrument in instruments:\n # 如果已经移动止损卖出过则不再轮仓卖出,以防止出现空头持仓\n if instrument in stoploss_stock:\n continue\n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n # 记录轮仓卖出的股票\n sell_stock.append(instrument)\n if cash_for_sell <= 0:\n break\n\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n buy_list = list(ranker_prediction.instrument)\n # 不再买入已经轮仓卖出和移动止损的股票,以防止出现空头持仓\n buy_instruments = [i for i in buy_list if i not in sell_stock + stoploss_stock][:len(buy_cash_weights)]\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","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n #在数据准备函数中一次性计算每日的大盘风控条件相比于在handle中每日计算风控条件可以提高回测速度\n # 多取50天的数据便于计算均值(保证回测的第一天均值不为Nan值),其中context.start_date和context.end_date是回测指定的起始时间和终止时间\n start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d') \n df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close'])\n benckmark_data=df[df.instrument=='000001.HIX']\n #计算上证指数5日涨幅\n benckmark_data['ret5']=benckmark_data['close']/benckmark_data['close'].shift(5)-1\n #计算大盘风控条件,如果5日涨幅小于-5%则设置风险状态risk为1,否则为0\n benckmark_data['risk'] = np.where(benckmark_data['ret5']<-0.05,1,0)\n #修改日期格式为字符串(便于在handle中使用字符串日期索引来查看每日的风险状态)\n benckmark_data['date']=benckmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d'))\n #设置日期为索引\n benckmark_data.set_index('date',inplace=True)\n #把风控序列输出给全局变量context.benckmark_risk\n context.benckmark_risk=benckmark_data['risk']\n\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"def bigquant_run(context, data):\n pass","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":0.025,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"vwap_2","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"vwap_4","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":1000000,"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":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-141"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-141","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":19,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-160","ModuleId":"BigQuantSpace.dl_layer_input.dl_layer_input-v1","ModuleParameters":[{"Name":"shape","Value":"59","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"batch_shape","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"dtype","Value":"float32","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sparse","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-160"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-160","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-168","ModuleId":"BigQuantSpace.dl_layer_dense.dl_layer_dense-v1","ModuleParameters":[{"Name":"units","Value":"256","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activation","Value":"relu","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activation","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"use_bias","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_initializer","Value":"glorot_uniform","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_initializer","Value":"Zeros","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activity_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-168"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-168","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-196","ModuleId":"BigQuantSpace.dl_layer_dense.dl_layer_dense-v1","ModuleParameters":[{"Name":"units","Value":"128","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activation","Value":"relu","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activation","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"use_bias","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_initializer","Value":"glorot_uniform","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_initializer","Value":"Zeros","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activity_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-196"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-196","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":20,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-224","ModuleId":"BigQuantSpace.dl_layer_dropout.dl_layer_dropout-v1","ModuleParameters":[{"Name":"rate","Value":"0.9","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"noise_shape","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"seed","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-224"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-224","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":21,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-231","ModuleId":"BigQuantSpace.dl_layer_dropout.dl_layer_dropout-v1","ModuleParameters":[{"Name":"rate","Value":"0.9","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"noise_shape","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"seed","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-231"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-231","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":22,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-238","ModuleId":"BigQuantSpace.dl_layer_dense.dl_layer_dense-v1","ModuleParameters":[{"Name":"units","Value":"1","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activation","Value":"linear","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activation","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"use_bias","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_initializer","Value":"glorot_uniform","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_initializer","Value":"Zeros","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activity_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-238"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-238","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":23,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-682","ModuleId":"BigQuantSpace.dl_model_init.dl_model_init-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-682"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"outputs","NodeId":"-682"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-682","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-1098","ModuleId":"BigQuantSpace.dl_model_train.dl_model_train-v1","ModuleParameters":[{"Name":"optimizer","Value":"Adam","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_optimizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"loss","Value":"mean_squared_error","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_loss","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"metrics","Value":"mse","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"batch_size","Value":"10240","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"epochs","Value":"2","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"n_gpus","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"verbose","Value":"2:每个epoch输出一行记录","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_model","NodeId":"-1098"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_data","NodeId":"-1098"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"validation_data","NodeId":"-1098"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1098","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-1540","ModuleId":"BigQuantSpace.dl_model_predict.dl_model_predict-v1","ModuleParameters":[{"Name":"batch_size","Value":"1024","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"n_gpus","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"verbose","Value":"2:每个epoch输出一行记录","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trained_model","NodeId":"-1540"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-1540"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1540","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-2431","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n pred_label = input_1.read_pickle()\n df = input_2.read_df()\n df = pd.DataFrame({'pred_label':pred_label[:,0], 'instrument':df.instrument, 'date':df.date})\n df.sort_values(['date','pred_label'],inplace=True, ascending=[True,False])\n return Outputs(data_1=DataSource.write_df(df), data_2=None, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-2431"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-2431"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-2431"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-2431","OutputType":null},{"Name":"data_2","NodeId":"-2431","OutputType":null},{"Name":"data_3","NodeId":"-2431","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":24,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-232","ModuleId":"BigQuantSpace.dl_convert_to_bin.dl_convert_to_bin-v2","ModuleParameters":[{"Name":"window_size","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_clip","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"flatten","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"window_along_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-232"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-232"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-232","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-240","ModuleId":"BigQuantSpace.dl_convert_to_bin.dl_convert_to_bin-v2","ModuleParameters":[{"Name":"window_size","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_clip","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"flatten","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"window_along_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-240"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-240"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-240","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"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='205,55,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='70,183,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='763,-1,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='249,375,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1074,127,200,200'/><NodePosition Node='-106' Position='381,188,200,200'/><NodePosition Node='-113' Position='385,280,200,200'/><NodePosition Node='-122' Position='1064,259,200,200'/><NodePosition Node='-129' Position='1067,348,200,200'/><NodePosition Node='-141' Position='816,1103,200,200'/><NodePosition Node='-160' Position='-283,55,200,200'/><NodePosition Node='-168' Position='-282,147,200,200'/><NodePosition Node='-196' Position='-278,321,200,200'/><NodePosition Node='-224' Position='-278,229,200,200'/><NodePosition Node='-231' Position='-276,405,200,200'/><NodePosition Node='-238' Position='-275,496,200,200'/><NodePosition Node='-682' Position='-225,659,200,200'/><NodePosition Node='-1098' Position='-50,765,200,200'/><NodePosition Node='-1540' Position='249,844,200,200'/><NodePosition Node='-2431' Position='533,940,200,200'/><NodePosition Node='-232' Position='388,510,200,200'/><NodePosition Node='-240' Position='800,525,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 [12]:
    # 本代码由可视化策略环境自动生成 2020年3月18日 14:13
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m24_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        pred_label = input_1.read_pickle()
        df = input_2.read_df()
        df = pd.DataFrame({'pred_label':pred_label[:,0], 'instrument':df.instrument, 'date':df.date})
        df.sort_values(['date','pred_label'],inplace=True, ascending=[True,False])
        return Outputs(data_1=DataSource.write_df(df), data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m24_post_run_bigquant_run(outputs):
        return outputs
    
    # 回测引擎:初始化函数,只执行一次
    def m19_initialize_bigquant_run(context):
        
         # 加载预测数据
        context.ranker_prediction = context.options['data'].read_df()
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
        # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)
        # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只
        stock_count = 4
        # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[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.7
        context.options['hold_days'] =4
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m19_handle_data_bigquant_run(context, data):
        #获取当日日期
        today = data.current_dt.strftime('%Y-%m-%d')
        stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]
        #大盘风控模块,读取风控数据    
        benckmark_risk=context.benckmark_risk[today]
        context.symbol
        #当risk为1时,市场有风险,全部平仓,不再执行其它操作
        if benckmark_risk >1:
            for instrument in stock_hold_now:
                context.order_target(symbol(instrument), 0)
            print(today,'大盘风控止损触发,全仓卖出')
            return
     
        
          # 按日期过滤得到今日的预测数据
        ranker_prediction = context.ranker_prediction[
            context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
        
    
    #    try:
    #        prediction = context.prediction[data.current_dt.strftime('%Y-%m-%d')]
    #    except KeyError as e:
    #        return
        
        instrument = context.instruments[0]
        sid = context.symbol(instrument)
        cur_position = context.portfolio.positions[sid].amount
        
        # 交易逻辑
    #    if prediction > 0.5 and cur_position == 0:
    #        context.order_target_percent(context.symbol(instrument), 1)
    #        print(data.current_dt, '买入!')
            
    #    elif prediction < 0.5 and cur_position > 0:
    #        context.order_target_percent(context.symbol(instrument), 0)
    #        print(data.current_dt, '卖出!')
        
        
        #跟踪止盈止损------设定若回调4%止盈, 止损
        
        #------------------------------------------止损模块START--------------------------------------------
        equities = {e.symbol: p for e, p in context.portfolio.positions.items() if p.amount>0}
        
        # 新建当日止损股票列表是为了handle_data 策略逻辑部分不再对该股票进行判断
        stoploss_stock = [] 
        if len(equities) > 0:
            for i in equities.keys():
                stock_market_price = data.current(context.symbol(i), 'price')  # 最新市场价格
                last_sale_date = equities[i].last_sale_date   # 上次交易日期
                delta_days = data.current_dt - last_sale_date  
                hold_days = delta_days.days # 持仓天数
                # 建仓以来的最高价
                highest_price_since_buy = data.history(context.symbol(i), 'high', hold_days, '1d').max()
                # 确定止损位置5%
                stoploss_line = highest_price_since_buy - highest_price_since_buy * 0.05
                #record('止损位置', stoploss_line)
                # 如果价格下穿止损位置
                if stock_market_price < stoploss_line:
                    context.order_target_percent(context.symbol(i), 0)     
                    stoploss_stock.append(i)
            if len(stoploss_stock)>0:
                print('日期:', today, '股票:', stoploss_stock, '出现跟踪止损状况')
        #-------------------------------------------止损模块END---------------------------------------------    
        
        # 按日期过滤得到今日的预测数据
        ranker_prediction = context.ranker_prediction[
            context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
    
        # 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, (1 if is_staging else 1.5) * cash_avg)
        cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)
        positions = {e.symbol: p.amount * p.last_sale_price
                     for e, p in context.perf_tracker.position_tracker.positions.items()}
    
        sell_stock = []
        # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
        if not is_staging and cash_for_sell > 0:
            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]))])))
            for instrument in instruments:
                # 如果已经移动止损卖出过则不再轮仓卖出,以防止出现空头持仓
                if instrument in stoploss_stock:
                    continue
                context.order_target(context.symbol(instrument), 0)
                cash_for_sell -= positions[instrument]
                # 记录轮仓卖出的股票
                sell_stock.append(instrument)
                if cash_for_sell <= 0:
                    break
    
        # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
        buy_cash_weights = context.stock_weights
        buy_list = list(ranker_prediction.instrument)
        # 不再买入已经轮仓卖出和移动止损的股票,以防止出现空头持仓
        buy_instruments = [i for i in buy_list if i not in sell_stock + stoploss_stock][:len(buy_cash_weights)]
        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 m19_prepare_bigquant_run(context):
        #在数据准备函数中一次性计算每日的大盘风控条件相比于在handle中每日计算风控条件可以提高回测速度
        # 多取50天的数据便于计算均值(保证回测的第一天均值不为Nan值),其中context.start_date和context.end_date是回测指定的起始时间和终止时间
        start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d') 
        df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close'])
        benckmark_data=df[df.instrument=='000001.HIX']
        #计算上证指数5日涨幅
        benckmark_data['ret5']=benckmark_data['close']/benckmark_data['close'].shift(5)-1
        #计算大盘风控条件,如果5日涨幅小于-5%则设置风险状态risk为1,否则为0
        benckmark_data['risk'] = np.where(benckmark_data['ret5']<-0.05,1,0)
        #修改日期格式为字符串(便于在handle中使用字符串日期索引来查看每日的风险状态)
        benckmark_data['date']=benckmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d'))
        #设置日期为索引
        benckmark_data.set_index('date',inplace=True)
        #把风控序列输出给全局变量context.benckmark_risk
        context.benckmark_risk=benckmark_data['risk']
    
    
    def m19_before_trading_start_bigquant_run(context, data):
        pass
    
    m1 = M.instruments.v2(
        start_date='2015-01-01',
        end_date='2017-01-01',
        market='CN_STOCK_A',
        instrument_list="""000004.SZA
    000001.SZA
    000002.SZA
    600800.SHA
    002498.SZA
    300212.SZA
    300576.SZA
    002879.SZA
    300363.SZA
    002291.SZA
    002023.SZA
    600196.SHA
    600161.SHA
    002007.SZA
    300543.SZA
    300525.SZA
    300607.SZA
    300316.SZA
    002409.SZA
    300236.SZA
    603707.SHA
    002371.SZA
    300413.SZA
    600536.SHA
    002555.SZA
    603160.SHA
    300455.SZA
    600570.SHA
    300033.SZA
    002396.SZA
    603859.SHA
    000661.SZA
    603986.SHA
    600588.SHA
    300122.SZA
    600585.SHA
    603160.SHA
    300142.SZA
    300706.SZA
    000938.SZA
    002230.SZA
    603939.SHA
    002714.SZA
    600745.SHA
    603501.SHA
    002153.SZA
    000895.SZA
    300347.SZA
    601888.SHA
    300750.SZA
    603288.SHA
    300552.SZA
    300526.SZA
    002552.SZA
    603501.SHA
    300661.SZA
    300223.SZA
    002351.SZA
    300573.SZA
    300759.SZA
    300803.SZA
    300775.SZA
    300661.SZA
    601865.SHA
    002600.SZA
    300785.SZA
    300777.SZA
    002869.SZA
    601236.SHA
    300220.SZA
    300797.SZA
    603093.SHA
    300799.SZA
    300709.SZA
    603613.SHA
    300792.SZA
    002937.SZA
    300783.SZA
    601066.SHA
    601698.SHA
    002945.SZA
    002458.SZA
    603927.SHA
    603068.SHA
    300379.SZA
    002201.SZA
    603986.SHA
    000066.SZA
    600131.SHA
    002475.SZA
    300341.SZA
    300397.SZA
    300014.SZA
    002791.SZA
    002463.SZA
    600519.SHA
    600809.SHA
    000858.SZA
    000596.SZA
    600132.SHA
    600779.SHA
    600776.SHA
    000622.SZA
    002607.SZA
    300107.SZA
    002243.SZA
    000860.SZA
    300559.SZA
    000860.SZA
    603605.SHA
    603039.SHA
    300253.SZA
    300550.SZA
    300596.SZA
    603345.SHA
    300451.SZA
    002399.SZA
    600604.SHA
    600556.SHA
    603283.SHA
    002708.SZA
    600408.SHA
    600235.SHA
    300598.SZA
    002755.SZA
    000953.SZA
    000760.SZA
    002921.SZA
    002864.SZA
    002795.SZA
    002575.SZA
    002288.SZA
    000068.SZA
    002927.SZA
    603032.SHA
    600247.SHA
    002931.SZA
    300746.SZA
    601330.SHA
    300748.SZA
    603712.SHA
    002927.SZA
    601606.SHA
    300747.SZA
    601162.SHA
    603056.SHA
    002415.SZA
    300003.SZA
    002963.SZA
    002236.SZA
    300124.SZA
    300296.SZA
    300253.SZA
    002475.SZA
    000333.SZA
    600886.SHA
    000703.SZA
    600438.SHA
    600482.SHA
    600661.SHA
    002955.SZA
    002465.SZA
    600739.SHA
    601989.SHA
    600601.SHA
    600654.SHA
    600887.SHA
    000626.SZA
    000538.SZA
    000002.SZA
    600118.SHA
    000568.SZA
    600620.SHA
    600570.SHA
    000060.SZA
    000503.SZA
    300674.SZA
    600903.SHA
    300487.SZA
    300647.SZA
    002776.SZA
    300670.SZA
    300107.SZA
    300730.SZA
    300027.SZA
    601899.SHA
    300352.SZA
    000636.SZA
    002092.SZA
    000980.SZA
    600704.SHA
    002635.SZA
    000709.SZA
    000050.SZA
    300079.SZA
    300296.SZA
    002405.SZA
    600660.SHA
    601088.SHA
    000338.SZA
    600697.SHA
    000803.SZA
    000895.SZA
    300223.SZA
    002826.SZA
    002371.SZA
    002218.SZA
    300676.SZA
    300015.SZA
    000625.SZA
    000063.SZA
    300148.SZA
    603288.SHA
    601668.SHA
    600839.SHA
    002466.SZA
    000876.SZA
    002234.SZA
    600332.SHA
    002024.SZA
    600547.SHA
    002038.SZA
    000651.SZA
    002035.SZA
    002032.SZA
    300498.SZA
    002022.SZA
    600048.SHA
    600489.SHA
    600436.SHA
    600031.SHA
    000402.SZA
    600309.SHA
    000423.SZA
    600521.SHA
    600500.SHA
    600030.SHA
    600993.SHA
    600522.SHA
    002230.SZA
    600853.SHA
    002838.SZA
    002414.SZA
    300628.SZA
    002239.SZA
    300160.SZA
    300578.SZA
    603200.SHA
    002613.SZA
    000652.SZA
    002824.SZA
    300677.SZA
    300235.SZA
    600516.SHA
    000425.SZA
    002607.SZA
    600789.SHA
    000518.SZA
    300346.SZA
    300236.SZA
    300706.SZA
    300666.SZA
    600276.SHA
    600422.SHA
    300601.SZA
    002223.SZA
    002916.SZA
    300632.SZA
    300450.SZA
    300014.SZA
    002841.SZA
    002463.SZA
    603160.SHA
    600183.SHA
    603178.SHA
    600242.SHA
    603825.SHA
    603738.SHA
    603920.SHA
    603005.SHA
    600513.SHA
    603598.SHA
    603608.SHA
    300176.SZA
    601313.SHA
    000830.SZA
    601012.SHA
    002460.SZA
    002415.SZA
    600460.SHA
    600779.SHA
    603690.SHA
    603533.SHA
    300708.SZA
    300725.SZA
    603032.SHA
    002833.SZA
    300618.SZA
    603929.SHA
    002836.SZA
    000830.SZA
    601012.SHA
    002460.SZA
    300585.SZA
    000935.SZA
    603876.SHA
    601116.SHA
    002695.SZA
    300174.SZA
    002089.SZA
    300340.SZA
    300431.SZA
    300364.SZA
    002751.SZA
    300446.SZA
    300451.SZA
    002506.SZA
    300469.SZA
    000025.SZA
    603601.SHA
    002739.SZA
    300410.SZA
    300467.SZA
    002747.SZA
    300437.SZA
    600053.SHA
    002075.SZA
    300479.SZA
    300078.SZA
    300383.SZA
    002771.SZA
    300458.SZA
    300422.SZA
    300441.SZA
    300302.SZA
    600165.SHA
    300429.SZA
    300480.SZA
    603318.SHA
    002027.SZA
    603678.SHA
    300299.SZA
    002741.SZA
    300457.SZA
    603918.SHA
    603169.SHA
    603019.SHA
    600399.SHA
    300162.SZA
    600317.SHA
    300033.SZA
    600556.SHA
    000693.SZA
    300324.SZA
    002544.SZA""",
        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日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    shift(close, -5) / shift(open, -1)-1
    
    # 极值处理:用1%和99%分位的值做clip
    clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
    
    # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
    where(shift(high, -1) == shift(low, -1), NaN, label)
    where(label>0.5, NaN, label)
    where(label<-0.5, NaN, label)
    """,
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=True,
        cast_label_int=False
    )
    
    m3 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    return_5-1
    return_10-1
    return_20-1
    avg_amount_0/avg_amount_5-1
    avg_amount_5/avg_amount_20-1
    rank_avg_amount_0-rank_avg_amount_5
    rank_avg_amount_5-rank_avg_amount_10
    rank_return_0-rank_return_5
    rank_return_5-rank_return_10
    beta_csi300_30_0/10
    beta_csi300_60_0/10
    swing_volatility_5_0/swing_volatility_30_0-1
    swing_volatility_30_0/swing_volatility_60_0-1
    ta_atr_14_0/ta_atr_28_0-1
    ta_sma_5_0/ta_sma_20_0-1
    ta_sma_10_0/ta_sma_20_0-1
    ta_sma_20_0/ta_sma_30_0-1
    ta_sma_30_0/ta_sma_60_0-1
    ta_rsi_14_0/100
    ta_rsi_28_0/100
    ta_cci_14_0/500
    ta_cci_28_0/500
    beta_industry_30_0/10
    beta_industry_60_0/10
    ta_sma(amount_0, 10)/ta_sma(amount_0, 20)-1
    ta_sma(amount_0, 20)/ta_sma(amount_0, 30)-1
    ta_sma(amount_0, 30)/ta_sma(amount_0, 60)-1
    ta_sma(amount_0, 50)/ta_sma(amount_0, 100)-1
    ta_sma(turn_0, 10)/ta_sma(turn_0, 20)-1
    ta_sma(turn_0, 20)/ta_sma(turn_0, 30)-1
    ta_sma(turn_0, 30)/ta_sma(turn_0, 60)-1
    ta_sma(turn_0, 50)/ta_sma(turn_0, 100)-1
    high_0/low_0-1
    close_0/open_0-1
    shift(close_0,1)/close_0-1
    shift(close_0,2)/close_0-1
    shift(close_0,3)/close_0-1
    shift(close_0,4)/close_0-1
    shift(close_0,5)/close_0-1
    shift(close_0,10)/close_0-1
    shift(close_0,20)/close_0-1
    ta_sma(high_0-low_0, 5)/ta_sma(high_0-low_0, 20)-1
    ta_sma(high_0-low_0, 10)/ta_sma(high_0-low_0, 20)-1
    ta_sma(high_0-low_0, 20)/ta_sma(high_0-low_0, 30)-1
    ta_sma(high_0-low_0, 30)/ta_sma(high_0-low_0, 60)-1
    ta_sma(high_0-low_0, 50)/ta_sma(high_0-low_0, 100)-1
    rank_avg_amount_5
    rank_avg_turn_5
    rank_volatility_5_0
    rank_swing_volatility_5_0
    rank_avg_mf_net_amount_5
    rank_beta_industry_5_0
    rank_return_5
    rank_return_2
    std(close_0,5)/std(close_0,20)-1
    std(close_0,10)/std(close_0,20)-1
    std(close_0,20)/std(close_0,30)-1
    std(close_0,30)/std(close_0,60)-1
    std(close_0,50)/std(close_0,100)-1
    #--------多头排列回踩买入
    buy_condition=where((mean(close_0,5)>mean(close_0,10))&(mean(close_0,10)>mean(close_0,20))&(mean(close_0,20)>mean(close_0,40))&(mean(close_0,40)>mean(close_0,120))&(low_0<mean(close_0,10)),1,0)
    sell_condition=where(mean(close_0,5)<mean(close_0,40),1,0)
    
    ta_bbands_lowerband_28_0
    ta_bbands_upperband_28_0"""
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False
    )
    
    m7 = M.join.v3(
        data1=m2.data,
        data2=m16.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m13 = M.dl_convert_to_bin.v2(
        input_data=m7.data,
        features=m3.data,
        window_size=1,
        feature_clip=5,
        flatten=True,
        window_along_col='instrument'
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2017-01-01'),
        end_date=T.live_run_param('trading_date', '2020-03-17'),
        market='CN_STOCK_A',
        instrument_list="""000004.SZA
    000001.SZA
    000002.SZA
    600800.SHA
    002498.SZA
    300212.SZA
    300576.SZA
    002879.SZA
    300363.SZA
    002291.SZA
    002023.SZA
    600196.SHA
    600161.SHA
    002007.SZA
    300543.SZA
    300525.SZA
    300607.SZA
    300316.SZA
    002409.SZA
    300236.SZA
    603707.SHA
    002371.SZA
    300413.SZA
    600536.SHA
    002555.SZA
    603160.SHA
    300455.SZA
    600570.SHA
    300033.SZA
    002396.SZA
    603859.SHA
    000661.SZA
    603986.SHA
    600588.SHA
    300122.SZA
    600585.SHA
    603160.SHA
    300142.SZA
    300706.SZA
    000938.SZA
    002230.SZA
    603939.SHA
    002714.SZA
    600745.SHA
    603501.SHA
    002153.SZA
    000895.SZA
    300347.SZA
    601888.SHA
    300750.SZA
    603288.SHA
    300552.SZA
    300526.SZA
    002552.SZA
    603501.SHA
    300661.SZA
    300223.SZA
    002351.SZA
    300573.SZA
    300759.SZA
    300803.SZA
    300775.SZA
    300661.SZA
    601865.SHA
    002600.SZA
    300785.SZA
    300777.SZA
    002869.SZA
    601236.SHA
    300220.SZA
    300797.SZA
    603093.SHA
    300799.SZA
    300709.SZA
    603613.SHA
    300792.SZA
    002937.SZA
    300783.SZA
    601066.SHA
    601698.SHA
    002945.SZA
    002458.SZA
    603927.SHA
    603068.SHA
    300379.SZA
    002201.SZA
    603986.SHA
    000066.SZA
    600131.SHA
    002475.SZA
    300341.SZA
    300397.SZA
    300014.SZA
    002791.SZA
    002463.SZA
    600519.SHA
    600809.SHA
    000858.SZA
    000596.SZA
    600132.SHA
    600779.SHA
    600776.SHA
    000622.SZA
    002607.SZA
    300107.SZA
    002243.SZA
    000860.SZA
    300559.SZA
    000860.SZA
    603605.SHA
    603039.SHA
    300253.SZA
    300550.SZA
    300596.SZA
    603345.SHA
    300451.SZA
    002399.SZA
    600604.SHA
    600556.SHA
    603283.SHA
    002708.SZA
    600408.SHA
    600235.SHA
    300598.SZA
    002755.SZA
    000953.SZA
    000760.SZA
    002921.SZA
    002864.SZA
    002795.SZA
    002575.SZA
    002288.SZA
    000068.SZA
    002927.SZA
    603032.SHA
    600247.SHA
    002931.SZA
    300746.SZA
    601330.SHA
    300748.SZA
    603712.SHA
    002927.SZA
    601606.SHA
    300747.SZA
    601162.SHA
    603056.SHA
    002415.SZA
    300003.SZA
    002963.SZA
    002236.SZA
    300124.SZA
    300296.SZA
    300253.SZA
    002475.SZA
    000333.SZA
    600886.SHA
    000703.SZA
    600438.SHA
    600482.SHA
    600661.SHA
    002955.SZA
    002465.SZA
    600739.SHA
    601989.SHA
    600601.SHA
    600654.SHA
    600887.SHA
    000626.SZA
    000538.SZA
    000002.SZA
    600118.SHA
    000568.SZA
    600620.SHA
    600570.SHA
    000060.SZA
    000503.SZA
    300674.SZA
    600903.SHA
    300487.SZA
    300647.SZA
    002776.SZA
    300670.SZA
    300107.SZA
    300730.SZA
    300027.SZA
    601899.SHA
    300352.SZA
    000636.SZA
    002092.SZA
    000980.SZA
    600704.SHA
    002635.SZA
    000709.SZA
    000050.SZA
    300079.SZA
    300296.SZA
    002405.SZA
    600660.SHA
    601088.SHA
    000338.SZA
    600697.SHA
    000803.SZA
    000895.SZA
    300223.SZA
    002826.SZA
    002371.SZA
    002218.SZA
    300676.SZA
    300015.SZA
    000625.SZA
    000063.SZA
    300148.SZA
    603288.SHA
    601668.SHA
    600839.SHA
    002466.SZA
    000876.SZA
    002234.SZA
    600332.SHA
    002024.SZA
    600547.SHA
    002038.SZA
    000651.SZA
    002035.SZA
    002032.SZA
    300498.SZA
    002022.SZA
    600048.SHA
    600489.SHA
    600436.SHA
    600031.SHA
    000402.SZA
    600309.SHA
    000423.SZA
    600521.SHA
    600500.SHA
    600030.SHA
    600993.SHA
    600522.SHA
    002230.SZA
    600853.SHA
    002838.SZA
    002414.SZA
    300628.SZA
    002239.SZA
    300160.SZA
    300578.SZA
    603200.SHA
    002613.SZA
    000652.SZA
    002824.SZA
    300677.SZA
    300235.SZA
    600516.SHA
    000425.SZA
    002607.SZA
    600789.SHA
    000518.SZA
    300346.SZA
    300236.SZA
    300706.SZA
    300666.SZA
    600276.SHA
    600422.SHA
    300601.SZA
    002223.SZA
    002916.SZA
    300632.SZA
    300450.SZA
    300014.SZA
    002841.SZA
    002463.SZA
    603160.SHA
    600183.SHA
    603178.SHA
    600242.SHA
    603825.SHA
    603738.SHA
    603920.SHA
    603005.SHA
    600513.SHA
    603598.SHA
    603608.SHA
    300176.SZA
    601313.SHA
    000830.SZA
    601012.SHA
    002460.SZA
    002415.SZA
    600460.SHA
    600779.SHA
    603690.SHA
    603533.SHA
    300708.SZA
    300725.SZA
    603032.SHA
    002833.SZA
    300618.SZA
    603929.SHA
    002836.SZA
    000830.SZA
    601012.SHA
    002460.SZA
    300585.SZA
    000935.SZA
    603876.SHA
    601116.SHA
    002695.SZA
    300174.SZA
    002089.SZA
    300340.SZA
    300431.SZA
    300364.SZA
    002751.SZA
    300446.SZA
    300451.SZA
    002506.SZA
    300469.SZA
    000025.SZA
    603601.SHA
    002739.SZA
    300410.SZA
    300467.SZA
    002747.SZA
    300437.SZA
    600053.SHA
    002075.SZA
    300479.SZA
    300078.SZA
    300383.SZA
    002771.SZA
    300458.SZA
    300422.SZA
    300441.SZA
    300302.SZA
    600165.SHA
    300429.SZA
    300480.SZA
    603318.SHA
    002027.SZA
    603678.SHA
    300299.SZA
    002741.SZA
    300457.SZA
    603918.SHA
    603169.SHA
    603019.SHA
    600399.SHA
    300162.SZA
    600317.SHA
    300033.SZA
    600556.SHA
    000693.SZA
    300324.SZA
    002544.SZA""",
        max_count=0
    )
    
    m17 = M.general_feature_extractor.v7(
        instruments=m9.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m18 = M.derived_feature_extractor.v3(
        input_data=m17.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False
    )
    
    m14 = M.dl_convert_to_bin.v2(
        input_data=m18.data,
        features=m3.data,
        window_size=1,
        feature_clip=5,
        flatten=True,
        window_along_col='instrument'
    )
    
    m6 = M.dl_layer_input.v1(
        shape='59',
        batch_shape='',
        dtype='float32',
        sparse=False,
        name=''
    )
    
    m8 = M.dl_layer_dense.v1(
        inputs=m6.data,
        units=256,
        activation='relu',
        use_bias=True,
        kernel_initializer='glorot_uniform',
        bias_initializer='Zeros',
        kernel_regularizer='None',
        kernel_regularizer_l1=0,
        kernel_regularizer_l2=0,
        bias_regularizer='None',
        bias_regularizer_l1=0,
        bias_regularizer_l2=0,
        activity_regularizer='None',
        activity_regularizer_l1=0,
        activity_regularizer_l2=0,
        kernel_constraint='None',
        bias_constraint='None',
        name=''
    )
    
    m21 = M.dl_layer_dropout.v1(
        inputs=m8.data,
        rate=0.9,
        noise_shape='',
        name=''
    )
    
    m20 = M.dl_layer_dense.v1(
        inputs=m21.data,
        units=128,
        activation='relu',
        use_bias=True,
        kernel_initializer='glorot_uniform',
        bias_initializer='Zeros',
        kernel_regularizer='None',
        kernel_regularizer_l1=0,
        kernel_regularizer_l2=0,
        bias_regularizer='None',
        bias_regularizer_l1=0,
        bias_regularizer_l2=0,
        activity_regularizer='None',
        activity_regularizer_l1=0,
        activity_regularizer_l2=0,
        kernel_constraint='None',
        bias_constraint='None',
        name=''
    )
    
    m22 = M.dl_layer_dropout.v1(
        inputs=m20.data,
        rate=0.9,
        noise_shape='',
        name=''
    )
    
    m23 = M.dl_layer_dense.v1(
        inputs=m22.data,
        units=1,
        activation='linear',
        use_bias=True,
        kernel_initializer='glorot_uniform',
        bias_initializer='Zeros',
        kernel_regularizer='None',
        kernel_regularizer_l1=0,
        kernel_regularizer_l2=0,
        bias_regularizer='None',
        bias_regularizer_l1=0,
        bias_regularizer_l2=0,
        activity_regularizer='None',
        activity_regularizer_l1=0,
        activity_regularizer_l2=0,
        kernel_constraint='None',
        bias_constraint='None',
        name=''
    )
    
    m4 = M.dl_model_init.v1(
        inputs=m6.data,
        outputs=m23.data
    )
    
    m5 = M.dl_model_train.v1(
        input_model=m4.data,
        training_data=m13.data,
        optimizer='Adam',
        loss='mean_squared_error',
        metrics='mse',
        batch_size=10240,
        epochs=2,
        n_gpus=0,
        verbose='2:每个epoch输出一行记录'
    )
    
    m11 = M.dl_model_predict.v1(
        trained_model=m5.data,
        input_data=m14.data,
        batch_size=1024,
        n_gpus=0,
        verbose='2:每个epoch输出一行记录'
    )
    
    m24 = M.cached.v3(
        input_1=m11.data,
        input_2=m18.data,
        run=m24_run_bigquant_run,
        post_run=m24_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m19 = M.trade.v4(
        instruments=m9.data,
        options_data=m24.data_1,
        start_date='',
        end_date='',
        initialize=m19_initialize_bigquant_run,
        handle_data=m19_handle_data_bigquant_run,
        prepare=m19_prepare_bigquant_run,
        before_trading_start=m19_before_trading_start_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='vwap_2',
        order_price_field_sell='vwap_4',
        capital_base=1000000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='后复权',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark='000300.SHA'
    )
    

    序列窗口滚动(深度学习)(dl_convert_to_bin)使用错误,你可以:

    1.一键查看文档

    2.一键搜索答案

    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    <ipython-input-12-ad1d8837bd54> in <module>()
        655     feature_clip=5,
        656     flatten=True,
    --> 657     window_along_col='instrument'
        658 )
        659 
    
    KeyError: "['buy_condition=where((mean(close_0,5)>mean(close_0,10))&(mean(close_0,10)>mean(close_0,20))&(mean(close_0,20)>mean(close_0,40))&(mean(close_0,40)>mean(close_0,120))&(low_0<mean(close_0,10)),1,0)'\n 'sell_condition=where(mean(close_0,5)<mean(close_0,40),1,0)'] not in index"

    (iQuant) #3

    这个是因为你的特征因子列表里面有别名,不能直接传递给滚动窗口模块,需要用因子简称模块处理一下。另外输入模块的参数有误,需要根据你的因子数量和窗口大小的乘积进行设置。

    克隆策略
    In [ ]:
    m5.raw_perf,m19.raw_perf
    

      {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-106: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":"-106:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-113:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-122:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-129:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-236:input_1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-232:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-122:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-141:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-113:input_data","SourceOutputPortId":"-106:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-113:data"},{"DestinationInputPortId":"-129:input_data","SourceOutputPortId":"-122:data"},{"DestinationInputPortId":"-2431:input_2","SourceOutputPortId":"-129:data"},{"DestinationInputPortId":"-240:input_data","SourceOutputPortId":"-129:data"},{"DestinationInputPortId":"-168:inputs","SourceOutputPortId":"-160:data"},{"DestinationInputPortId":"-682:inputs","SourceOutputPortId":"-160:data"},{"DestinationInputPortId":"-224:inputs","SourceOutputPortId":"-168:data"},{"DestinationInputPortId":"-231:inputs","SourceOutputPortId":"-196:data"},{"DestinationInputPortId":"-196:inputs","SourceOutputPortId":"-224:data"},{"DestinationInputPortId":"-238:inputs","SourceOutputPortId":"-231:data"},{"DestinationInputPortId":"-682:outputs","SourceOutputPortId":"-238:data"},{"DestinationInputPortId":"-1098:input_model","SourceOutputPortId":"-682:data"},{"DestinationInputPortId":"-1540:trained_model","SourceOutputPortId":"-1098:data"},{"DestinationInputPortId":"-2431:input_1","SourceOutputPortId":"-1540:data"},{"DestinationInputPortId":"-141:options_data","SourceOutputPortId":"-2431:data_1"},{"DestinationInputPortId":"-1098:training_data","SourceOutputPortId":"-232:data"},{"DestinationInputPortId":"-1540:input_data","SourceOutputPortId":"-240:data"},{"DestinationInputPortId":"-232:features","SourceOutputPortId":"-236:data_1"},{"DestinationInputPortId":"-240:features","SourceOutputPortId":"-236:data_1"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2017-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000004.SZA\n000001.SZA\n000002.SZA\n600800.SHA\n002498.SZA\n300212.SZA\n300576.SZA\n002879.SZA\n300363.SZA\n002291.SZA\n002023.SZA\n600196.SHA\n600161.SHA\n002007.SZA\n300543.SZA\n300525.SZA\n300607.SZA\n300316.SZA\n002409.SZA\n300236.SZA\n603707.SHA\n002371.SZA\n300413.SZA\n600536.SHA\n002555.SZA\n603160.SHA\n300455.SZA\n600570.SHA\n300033.SZA\n002396.SZA\n603859.SHA\n000661.SZA\n603986.SHA\n600588.SHA\n300122.SZA\n600585.SHA\n603160.SHA\n300142.SZA\n300706.SZA\n000938.SZA\n002230.SZA\n603939.SHA\n002714.SZA\n600745.SHA\n603501.SHA\n002153.SZA\n000895.SZA\n300347.SZA\n601888.SHA\n300750.SZA\n603288.SHA\n300552.SZA\n300526.SZA\n002552.SZA\n603501.SHA\n300661.SZA\n300223.SZA\n002351.SZA\n300573.SZA\n300759.SZA\n300803.SZA\n300775.SZA\n300661.SZA\n601865.SHA\n002600.SZA\n300785.SZA\n300777.SZA\n002869.SZA\n601236.SHA\n300220.SZA\n300797.SZA\n603093.SHA\n300799.SZA\n300709.SZA\n603613.SHA\n300792.SZA\n002937.SZA\n300783.SZA\n601066.SHA\n601698.SHA\n002945.SZA\n002458.SZA\n603927.SHA\n603068.SHA\n300379.SZA\n002201.SZA\n603986.SHA\n000066.SZA\n600131.SHA\n002475.SZA\n300341.SZA\n300397.SZA\n300014.SZA\n002791.SZA\n002463.SZA\n600519.SHA\n600809.SHA\n000858.SZA\n000596.SZA\n600132.SHA\n600779.SHA\n600776.SHA\n000622.SZA\n002607.SZA\n300107.SZA\n002243.SZA\n000860.SZA\n300559.SZA\n000860.SZA\n603605.SHA\n603039.SHA\n300253.SZA\n300550.SZA\n300596.SZA\n603345.SHA\n300451.SZA\n002399.SZA\n600604.SHA\n600556.SHA\n603283.SHA\n002708.SZA\n600408.SHA\n600235.SHA\n300598.SZA\n002755.SZA\n000953.SZA\n000760.SZA\n002921.SZA\n002864.SZA\n002795.SZA\n002575.SZA\n002288.SZA\n000068.SZA\n002927.SZA\n603032.SHA\n600247.SHA\n002931.SZA\n300746.SZA\n601330.SHA\n300748.SZA\n603712.SHA\n002927.SZA\n601606.SHA\n300747.SZA\n601162.SHA\n603056.SHA\n002415.SZA\n300003.SZA\n002963.SZA\n002236.SZA\n300124.SZA\n300296.SZA\n300253.SZA\n002475.SZA\n000333.SZA\n600886.SHA\n000703.SZA\n600438.SHA\n600482.SHA\n600661.SHA\n002955.SZA\n002465.SZA\n600739.SHA\n601989.SHA\n600601.SHA\n600654.SHA\n600887.SHA\n000626.SZA\n000538.SZA\n000002.SZA\n600118.SHA\n000568.SZA\n600620.SHA\n600570.SHA\n000060.SZA\n000503.SZA\n300674.SZA\n600903.SHA\n300487.SZA\n300647.SZA\n002776.SZA\n300670.SZA\n300107.SZA\n300730.SZA\n300027.SZA\n601899.SHA\n300352.SZA\n000636.SZA\n002092.SZA\n000980.SZA\n600704.SHA\n002635.SZA\n000709.SZA\n000050.SZA\n300079.SZA\n300296.SZA\n002405.SZA\n600660.SHA\n601088.SHA\n000338.SZA\n600697.SHA\n000803.SZA\n000895.SZA\n300223.SZA\n002826.SZA\n002371.SZA\n002218.SZA\n300676.SZA\n300015.SZA\n000625.SZA\n000063.SZA\n300148.SZA\n603288.SHA\n601668.SHA\n600839.SHA\n002466.SZA\n000876.SZA\n002234.SZA\n600332.SHA\n002024.SZA\n600547.SHA\n002038.SZA\n000651.SZA\n002035.SZA\n002032.SZA\n300498.SZA\n002022.SZA\n600048.SHA\n600489.SHA\n600436.SHA\n600031.SHA\n000402.SZA\n600309.SHA\n000423.SZA\n600521.SHA\n600500.SHA\n600030.SHA\n600993.SHA\n600522.SHA\n002230.SZA\n600853.SHA\n002838.SZA\n002414.SZA\n300628.SZA\n002239.SZA\n300160.SZA\n300578.SZA\n603200.SHA\n002613.SZA\n000652.SZA\n002824.SZA\n300677.SZA\n300235.SZA\n600516.SHA\n000425.SZA\n002607.SZA\n600789.SHA\n000518.SZA\n300346.SZA\n300236.SZA\n300706.SZA\n300666.SZA\n600276.SHA\n600422.SHA\n300601.SZA\n002223.SZA\n002916.SZA\n300632.SZA\n300450.SZA\n300014.SZA\n002841.SZA\n002463.SZA\n603160.SHA\n600183.SHA\n603178.SHA\n600242.SHA\n603825.SHA\n603738.SHA\n603920.SHA\n603005.SHA\n600513.SHA\n603598.SHA\n603608.SHA\n300176.SZA\n601313.SHA\n000830.SZA\n601012.SHA\n002460.SZA\n002415.SZA\n600460.SHA\n600779.SHA\n603690.SHA\n603533.SHA\n300708.SZA\n300725.SZA\n603032.SHA\n002833.SZA\n300618.SZA\n603929.SHA\n002836.SZA\n000830.SZA\n601012.SHA\n002460.SZA\n300585.SZA\n000935.SZA\n603876.SHA\n601116.SHA\n002695.SZA\n300174.SZA\n002089.SZA\n300340.SZA\n300431.SZA\n300364.SZA\n002751.SZA\n300446.SZA\n300451.SZA\n002506.SZA\n300469.SZA\n000025.SZA\n603601.SHA\n002739.SZA\n300410.SZA\n300467.SZA\n002747.SZA\n300437.SZA\n600053.SHA\n002075.SZA\n300479.SZA\n300078.SZA\n300383.SZA\n002771.SZA\n300458.SZA\n300422.SZA\n300441.SZA\n300302.SZA\n600165.SHA\n300429.SZA\n300480.SZA\n603318.SHA\n002027.SZA\n603678.SHA\n300299.SZA\n002741.SZA\n300457.SZA\n603918.SHA\n603169.SHA\n603019.SHA\n600399.SHA\n300162.SZA\n600317.SHA\n300033.SZA\n600556.SHA\n000693.SZA\n300324.SZA\n002544.SZA","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,"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日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -5) / shift(open, -1)-1\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\nwhere(label>0.5, NaN, label)\nwhere(label<-0.5, 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":"False","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,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_5-1\nreturn_10-1\nreturn_20-1\navg_amount_0/avg_amount_5-1\navg_amount_5/avg_amount_20-1\nrank_avg_amount_0-rank_avg_amount_5\nrank_avg_amount_5-rank_avg_amount_10\nrank_return_0-rank_return_5\nrank_return_5-rank_return_10\nbeta_csi300_30_0/10\nbeta_csi300_60_0/10\nswing_volatility_5_0/swing_volatility_30_0-1\nswing_volatility_30_0/swing_volatility_60_0-1\nta_atr_14_0/ta_atr_28_0-1\nta_sma_5_0/ta_sma_20_0-1\nta_sma_10_0/ta_sma_20_0-1\nta_sma_20_0/ta_sma_30_0-1\nta_sma_30_0/ta_sma_60_0-1\nta_rsi_14_0/100\nta_rsi_28_0/100\nta_cci_14_0/500\nta_cci_28_0/500\nbeta_industry_30_0/10\nbeta_industry_60_0/10\nta_sma(amount_0, 10)/ta_sma(amount_0, 20)-1\nta_sma(amount_0, 20)/ta_sma(amount_0, 30)-1\nta_sma(amount_0, 30)/ta_sma(amount_0, 60)-1\nta_sma(amount_0, 50)/ta_sma(amount_0, 100)-1\nta_sma(turn_0, 10)/ta_sma(turn_0, 20)-1\nta_sma(turn_0, 20)/ta_sma(turn_0, 30)-1\nta_sma(turn_0, 30)/ta_sma(turn_0, 60)-1\nta_sma(turn_0, 50)/ta_sma(turn_0, 100)-1\nhigh_0/low_0-1\nclose_0/open_0-1\nshift(close_0,1)/close_0-1\nshift(close_0,2)/close_0-1\nshift(close_0,3)/close_0-1\nshift(close_0,4)/close_0-1\nshift(close_0,5)/close_0-1\nshift(close_0,10)/close_0-1\nshift(close_0,20)/close_0-1\nta_sma(high_0-low_0, 5)/ta_sma(high_0-low_0, 20)-1\nta_sma(high_0-low_0, 10)/ta_sma(high_0-low_0, 20)-1\nta_sma(high_0-low_0, 20)/ta_sma(high_0-low_0, 30)-1\nta_sma(high_0-low_0, 30)/ta_sma(high_0-low_0, 60)-1\nta_sma(high_0-low_0, 50)/ta_sma(high_0-low_0, 100)-1\nrank_avg_amount_5\nrank_avg_turn_5\nrank_volatility_5_0\nrank_swing_volatility_5_0\nrank_avg_mf_net_amount_5\nrank_beta_industry_5_0\nrank_return_5\nrank_return_2\nstd(close_0,5)/std(close_0,20)-1\nstd(close_0,10)/std(close_0,20)-1\nstd(close_0,20)/std(close_0,30)-1\nstd(close_0,30)/std(close_0,60)-1\nstd(close_0,50)/std(close_0,100)-1\n#--------多头排列回踩买入\nbuy_condition=where((mean(close_0,5)>mean(close_0,10))&(mean(close_0,10)>mean(close_0,20))&(mean(close_0,20)>mean(close_0,40))&(mean(close_0,40)>mean(close_0,120))&(low_0<mean(close_0,10)),1,0)\nsell_condition=where(mean(close_0,5)<mean(close_0,40),1,0)\n\nta_bbands_lowerband_28_0\nta_bbands_upperband_28_0","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,"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,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2017-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2020-03-17","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000004.SZA\n000001.SZA\n000002.SZA\n600800.SHA\n002498.SZA\n300212.SZA\n300576.SZA\n002879.SZA\n300363.SZA\n002291.SZA\n002023.SZA\n600196.SHA\n600161.SHA\n002007.SZA\n300543.SZA\n300525.SZA\n300607.SZA\n300316.SZA\n002409.SZA\n300236.SZA\n603707.SHA\n002371.SZA\n300413.SZA\n600536.SHA\n002555.SZA\n603160.SHA\n300455.SZA\n600570.SHA\n300033.SZA\n002396.SZA\n603859.SHA\n000661.SZA\n603986.SHA\n600588.SHA\n300122.SZA\n600585.SHA\n603160.SHA\n300142.SZA\n300706.SZA\n000938.SZA\n002230.SZA\n603939.SHA\n002714.SZA\n600745.SHA\n603501.SHA\n002153.SZA\n000895.SZA\n300347.SZA\n601888.SHA\n300750.SZA\n603288.SHA\n300552.SZA\n300526.SZA\n002552.SZA\n603501.SHA\n300661.SZA\n300223.SZA\n002351.SZA\n300573.SZA\n300759.SZA\n300803.SZA\n300775.SZA\n300661.SZA\n601865.SHA\n002600.SZA\n300785.SZA\n300777.SZA\n002869.SZA\n601236.SHA\n300220.SZA\n300797.SZA\n603093.SHA\n300799.SZA\n300709.SZA\n603613.SHA\n300792.SZA\n002937.SZA\n300783.SZA\n601066.SHA\n601698.SHA\n002945.SZA\n002458.SZA\n603927.SHA\n603068.SHA\n300379.SZA\n002201.SZA\n603986.SHA\n000066.SZA\n600131.SHA\n002475.SZA\n300341.SZA\n300397.SZA\n300014.SZA\n002791.SZA\n002463.SZA\n600519.SHA\n600809.SHA\n000858.SZA\n000596.SZA\n600132.SHA\n600779.SHA\n600776.SHA\n000622.SZA\n002607.SZA\n300107.SZA\n002243.SZA\n000860.SZA\n300559.SZA\n000860.SZA\n603605.SHA\n603039.SHA\n300253.SZA\n300550.SZA\n300596.SZA\n603345.SHA\n300451.SZA\n002399.SZA\n600604.SHA\n600556.SHA\n603283.SHA\n002708.SZA\n600408.SHA\n600235.SHA\n300598.SZA\n002755.SZA\n000953.SZA\n000760.SZA\n002921.SZA\n002864.SZA\n002795.SZA\n002575.SZA\n002288.SZA\n000068.SZA\n002927.SZA\n603032.SHA\n600247.SHA\n002931.SZA\n300746.SZA\n601330.SHA\n300748.SZA\n603712.SHA\n002927.SZA\n601606.SHA\n300747.SZA\n601162.SHA\n603056.SHA\n002415.SZA\n300003.SZA\n002963.SZA\n002236.SZA\n300124.SZA\n300296.SZA\n300253.SZA\n002475.SZA\n000333.SZA\n600886.SHA\n000703.SZA\n600438.SHA\n600482.SHA\n600661.SHA\n002955.SZA\n002465.SZA\n600739.SHA\n601989.SHA\n600601.SHA\n600654.SHA\n600887.SHA\n000626.SZA\n000538.SZA\n000002.SZA\n600118.SHA\n000568.SZA\n600620.SHA\n600570.SHA\n000060.SZA\n000503.SZA\n300674.SZA\n600903.SHA\n300487.SZA\n300647.SZA\n002776.SZA\n300670.SZA\n300107.SZA\n300730.SZA\n300027.SZA\n601899.SHA\n300352.SZA\n000636.SZA\n002092.SZA\n000980.SZA\n600704.SHA\n002635.SZA\n000709.SZA\n000050.SZA\n300079.SZA\n300296.SZA\n002405.SZA\n600660.SHA\n601088.SHA\n000338.SZA\n600697.SHA\n000803.SZA\n000895.SZA\n300223.SZA\n002826.SZA\n002371.SZA\n002218.SZA\n300676.SZA\n300015.SZA\n000625.SZA\n000063.SZA\n300148.SZA\n603288.SHA\n601668.SHA\n600839.SHA\n002466.SZA\n000876.SZA\n002234.SZA\n600332.SHA\n002024.SZA\n600547.SHA\n002038.SZA\n000651.SZA\n002035.SZA\n002032.SZA\n300498.SZA\n002022.SZA\n600048.SHA\n600489.SHA\n600436.SHA\n600031.SHA\n000402.SZA\n600309.SHA\n000423.SZA\n600521.SHA\n600500.SHA\n600030.SHA\n600993.SHA\n600522.SHA\n002230.SZA\n600853.SHA\n002838.SZA\n002414.SZA\n300628.SZA\n002239.SZA\n300160.SZA\n300578.SZA\n603200.SHA\n002613.SZA\n000652.SZA\n002824.SZA\n300677.SZA\n300235.SZA\n600516.SHA\n000425.SZA\n002607.SZA\n600789.SHA\n000518.SZA\n300346.SZA\n300236.SZA\n300706.SZA\n300666.SZA\n600276.SHA\n600422.SHA\n300601.SZA\n002223.SZA\n002916.SZA\n300632.SZA\n300450.SZA\n300014.SZA\n002841.SZA\n002463.SZA\n603160.SHA\n600183.SHA\n603178.SHA\n600242.SHA\n603825.SHA\n603738.SHA\n603920.SHA\n603005.SHA\n600513.SHA\n603598.SHA\n603608.SHA\n300176.SZA\n601313.SHA\n000830.SZA\n601012.SHA\n002460.SZA\n002415.SZA\n600460.SHA\n600779.SHA\n603690.SHA\n603533.SHA\n300708.SZA\n300725.SZA\n603032.SHA\n002833.SZA\n300618.SZA\n603929.SHA\n002836.SZA\n000830.SZA\n601012.SHA\n002460.SZA\n300585.SZA\n000935.SZA\n603876.SHA\n601116.SHA\n002695.SZA\n300174.SZA\n002089.SZA\n300340.SZA\n300431.SZA\n300364.SZA\n002751.SZA\n300446.SZA\n300451.SZA\n002506.SZA\n300469.SZA\n000025.SZA\n603601.SHA\n002739.SZA\n300410.SZA\n300467.SZA\n002747.SZA\n300437.SZA\n600053.SHA\n002075.SZA\n300479.SZA\n300078.SZA\n300383.SZA\n002771.SZA\n300458.SZA\n300422.SZA\n300441.SZA\n300302.SZA\n600165.SHA\n300429.SZA\n300480.SZA\n603318.SHA\n002027.SZA\n603678.SHA\n300299.SZA\n002741.SZA\n300457.SZA\n603918.SHA\n603169.SHA\n603019.SHA\n600399.SHA\n300162.SZA\n600317.SHA\n300033.SZA\n600556.SHA\n000693.SZA\n300324.SZA\n002544.SZA","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,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"-106","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":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-106"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-106"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-106","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"Comment":"","CommentCollapsed":true},{"Id":"-113","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":"True","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":"-113"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-113"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-113","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"Comment":"","CommentCollapsed":true},{"Id":"-122","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":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-122"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-122"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-122","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"Comment":"","CommentCollapsed":true},{"Id":"-129","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":"True","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":"-129"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-129"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-129","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"Comment":"","CommentCollapsed":true},{"Id":"-141","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 # 加载预测数据\n context.ranker_prediction = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)\n # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只\n stock_count = 4\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 context.max_cash_per_instrument =0.7\n context.options['hold_days'] =4\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n #获取当日日期\n today = data.current_dt.strftime('%Y-%m-%d')\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]\n #大盘风控模块,读取风控数据 \n benckmark_risk=context.benckmark_risk[today]\n context.symbol\n #当risk为1时,市场有风险,全部平仓,不再执行其它操作\n if benckmark_risk >1:\n for instrument in stock_hold_now:\n context.order_target(symbol(instrument), 0)\n print(today,'大盘风控止损触发,全仓卖出')\n return\n \n \n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n \n\n# try:\n# prediction = context.prediction[data.current_dt.strftime('%Y-%m-%d')]\n# except KeyError as e:\n# return\n \n instrument = context.instruments[0]\n sid = context.symbol(instrument)\n cur_position = context.portfolio.positions[sid].amount\n \n # 交易逻辑\n# if prediction > 0.5 and cur_position == 0:\n# context.order_target_percent(context.symbol(instrument), 1)\n# print(data.current_dt, '买入!')\n \n# elif prediction < 0.5 and cur_position > 0:\n# context.order_target_percent(context.symbol(instrument), 0)\n# print(data.current_dt, '卖出!')\n \n \n #跟踪止盈止损------设定若回调4%止盈, 止损\n \n #------------------------------------------止损模块START--------------------------------------------\n equities = {e.symbol: p for e, p in context.portfolio.positions.items() if p.amount>0}\n \n # 新建当日止损股票列表是为了handle_data 策略逻辑部分不再对该股票进行判断\n stoploss_stock = [] \n if len(equities) > 0:\n for i in equities.keys():\n stock_market_price = data.current(context.symbol(i), 'price') # 最新市场价格\n last_sale_date = equities[i].last_sale_date # 上次交易日期\n delta_days = data.current_dt - last_sale_date \n hold_days = delta_days.days # 持仓天数\n # 建仓以来的最高价\n highest_price_since_buy = data.history(context.symbol(i), 'high', hold_days, '1d').max()\n # 确定止损位置5%\n stoploss_line = highest_price_since_buy - highest_price_since_buy * 0.05\n #record('止损位置', stoploss_line)\n # 如果价格下穿止损位置\n if stock_market_price < stoploss_line:\n context.order_target_percent(context.symbol(i), 0) \n stoploss_stock.append(i)\n if len(stoploss_stock)>0:\n print('日期:', today, '股票:', stoploss_stock, '出现跟踪止损状况')\n #-------------------------------------------止损模块END--------------------------------------------- \n \n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n\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, (1 if is_staging else 1.5) * cash_avg)\n cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)\n positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items()}\n\n sell_stock = []\n # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰\n if not is_staging and cash_for_sell > 0:\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 for instrument in instruments:\n # 如果已经移动止损卖出过则不再轮仓卖出,以防止出现空头持仓\n if instrument in stoploss_stock:\n continue\n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n # 记录轮仓卖出的股票\n sell_stock.append(instrument)\n if cash_for_sell <= 0:\n break\n\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n buy_list = list(ranker_prediction.instrument)\n # 不再买入已经轮仓卖出和移动止损的股票,以防止出现空头持仓\n buy_instruments = [i for i in buy_list if i not in sell_stock + stoploss_stock][:len(buy_cash_weights)]\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","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n #在数据准备函数中一次性计算每日的大盘风控条件相比于在handle中每日计算风控条件可以提高回测速度\n # 多取50天的数据便于计算均值(保证回测的第一天均值不为Nan值),其中context.start_date和context.end_date是回测指定的起始时间和终止时间\n start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d') \n df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close'])\n benckmark_data=df[df.instrument=='000001.HIX']\n #计算上证指数5日涨幅\n benckmark_data['ret5']=benckmark_data['close']/benckmark_data['close'].shift(5)-1\n #计算大盘风控条件,如果5日涨幅小于-5%则设置风险状态risk为1,否则为0\n benckmark_data['risk'] = np.where(benckmark_data['ret5']<-0.05,1,0)\n #修改日期格式为字符串(便于在handle中使用字符串日期索引来查看每日的风险状态)\n benckmark_data['date']=benckmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d'))\n #设置日期为索引\n benckmark_data.set_index('date',inplace=True)\n #把风控序列输出给全局变量context.benckmark_risk\n context.benckmark_risk=benckmark_data['risk']\n\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"def bigquant_run(context, data):\n pass","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":0.025,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"vwap_2","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"vwap_4","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":1000000,"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":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-141"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-141"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-141","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":19,"Comment":"","CommentCollapsed":true},{"Id":"-160","ModuleId":"BigQuantSpace.dl_layer_input.dl_layer_input-v1","ModuleParameters":[{"Name":"shape","Value":"63","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"batch_shape","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"dtype","Value":"float32","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sparse","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-160"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-160","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-168","ModuleId":"BigQuantSpace.dl_layer_dense.dl_layer_dense-v1","ModuleParameters":[{"Name":"units","Value":"256","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activation","Value":"relu","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activation","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"use_bias","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_initializer","Value":"glorot_uniform","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_initializer","Value":"Zeros","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activity_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-168"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-168","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":8,"Comment":"","CommentCollapsed":true},{"Id":"-196","ModuleId":"BigQuantSpace.dl_layer_dense.dl_layer_dense-v1","ModuleParameters":[{"Name":"units","Value":"128","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activation","Value":"relu","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activation","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"use_bias","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_initializer","Value":"glorot_uniform","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_initializer","Value":"Zeros","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activity_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-196"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-196","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":20,"Comment":"","CommentCollapsed":true},{"Id":"-224","ModuleId":"BigQuantSpace.dl_layer_dropout.dl_layer_dropout-v1","ModuleParameters":[{"Name":"rate","Value":"0.9","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"noise_shape","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"seed","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-224"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-224","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":21,"Comment":"","CommentCollapsed":true},{"Id":"-231","ModuleId":"BigQuantSpace.dl_layer_dropout.dl_layer_dropout-v1","ModuleParameters":[{"Name":"rate","Value":"0.9","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"noise_shape","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"seed","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-231"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-231","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":22,"Comment":"","CommentCollapsed":true},{"Id":"-238","ModuleId":"BigQuantSpace.dl_layer_dense.dl_layer_dense-v1","ModuleParameters":[{"Name":"units","Value":"1","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activation","Value":"linear","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activation","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"use_bias","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_initializer","Value":"glorot_uniform","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_initializer","Value":"Zeros","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_initializer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l1","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"activity_regularizer_l2","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_activity_regularizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"kernel_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_kernel_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bias_constraint","Value":"None","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_bias_constraint","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"name","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-238"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-238","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":23,"Comment":"","CommentCollapsed":true},{"Id":"-682","ModuleId":"BigQuantSpace.dl_model_init.dl_model_init-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"inputs","NodeId":"-682"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"outputs","NodeId":"-682"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-682","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-1098","ModuleId":"BigQuantSpace.dl_model_train.dl_model_train-v1","ModuleParameters":[{"Name":"optimizer","Value":"Adam","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_optimizer","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"loss","Value":"mean_squared_error","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_loss","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"metrics","Value":"mse","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"batch_size","Value":"10240","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"epochs","Value":"2","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"n_gpus","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"verbose","Value":"2:每个epoch输出一行记录","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_model","NodeId":"-1098"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_data","NodeId":"-1098"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"validation_data","NodeId":"-1098"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1098","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-1540","ModuleId":"BigQuantSpace.dl_model_predict.dl_model_predict-v1","ModuleParameters":[{"Name":"batch_size","Value":"1024","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"n_gpus","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"verbose","Value":"2:每个epoch输出一行记录","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trained_model","NodeId":"-1540"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-1540"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1540","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"","CommentCollapsed":true},{"Id":"-2431","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n pred_label = input_1.read_pickle()\n df = input_2.read_df()\n df = pd.DataFrame({'pred_label':pred_label[:,0], 'instrument':df.instrument, 'date':df.date})\n df.sort_values(['date','pred_label'],inplace=True, ascending=[True,False])\n return Outputs(data_1=DataSource.write_df(df), data_2=None, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-2431"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-2431"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-2431"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-2431","OutputType":null},{"Name":"data_2","NodeId":"-2431","OutputType":null},{"Name":"data_3","NodeId":"-2431","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":24,"Comment":"","CommentCollapsed":true},{"Id":"-232","ModuleId":"BigQuantSpace.dl_convert_to_bin.dl_convert_to_bin-v2","ModuleParameters":[{"Name":"window_size","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_clip","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"flatten","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"window_along_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-232"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-232"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-232","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"Comment":"","CommentCollapsed":true},{"Id":"-240","ModuleId":"BigQuantSpace.dl_convert_to_bin.dl_convert_to_bin-v2","ModuleParameters":[{"Name":"window_size","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_clip","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"flatten","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"window_along_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-240"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-240"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-240","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"Comment":"","CommentCollapsed":true},{"Id":"-236","ModuleId":"BigQuantSpace.features_short.features_short-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-236"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-236","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"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='205,55,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='70,183,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='763,1.4693450927734375,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='249,375,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1074,127,200,200'/><NodePosition Node='-106' Position='381,188,200,200'/><NodePosition Node='-113' Position='385,280,200,200'/><NodePosition Node='-122' Position='1064,259,200,200'/><NodePosition Node='-129' Position='1067,348,200,200'/><NodePosition Node='-141' Position='816,1103,200,200'/><NodePosition Node='-160' Position='-283,55,200,200'/><NodePosition Node='-168' Position='-282,149.46934509277344,200,200'/><NodePosition Node='-196' Position='-278,321,200,200'/><NodePosition Node='-224' Position='-278,229,200,200'/><NodePosition Node='-231' Position='-276,405,200,200'/><NodePosition Node='-238' Position='-275,496,200,200'/><NodePosition Node='-682' Position='-225,659,200,200'/><NodePosition Node='-1098' Position='-50,765,200,200'/><NodePosition Node='-1540' Position='249,844,200,200'/><NodePosition Node='-2431' Position='533,940,200,200'/><NodePosition Node='-232' Position='388,510,200,200'/><NodePosition Node='-240' Position='800,525,200,200'/><NodePosition Node='-236' Position='759.7958374023438,280.82861328125,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 [7]:
      # 本代码由可视化策略环境自动生成 2020年3月18日 15:39
      # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
      
      
      # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
      def m24_run_bigquant_run(input_1, input_2, input_3):
          # 示例代码如下。在这里编写您的代码
          pred_label = input_1.read_pickle()
          df = input_2.read_df()
          df = pd.DataFrame({'pred_label':pred_label[:,0], 'instrument':df.instrument, 'date':df.date})
          df.sort_values(['date','pred_label'],inplace=True, ascending=[True,False])
          return Outputs(data_1=DataSource.write_df(df), data_2=None, data_3=None)
      
      # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
      def m24_post_run_bigquant_run(outputs):
          return outputs
      
      # 回测引擎:初始化函数,只执行一次
      def m19_initialize_bigquant_run(context):
          
           # 加载预测数据
          context.ranker_prediction = context.options['data'].read_df()
      
          # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
          context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
          # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)
          # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只
          stock_count = 4
          # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[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.7
          context.options['hold_days'] =4
      
      # 回测引擎:每日数据处理函数,每天执行一次
      def m19_handle_data_bigquant_run(context, data):
          #获取当日日期
          today = data.current_dt.strftime('%Y-%m-%d')
          stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]
          #大盘风控模块,读取风控数据    
          benckmark_risk=context.benckmark_risk[today]
          context.symbol
          #当risk为1时,市场有风险,全部平仓,不再执行其它操作
          if benckmark_risk >1:
              for instrument in stock_hold_now:
                  context.order_target(symbol(instrument), 0)
              print(today,'大盘风控止损触发,全仓卖出')
              return
       
          
            # 按日期过滤得到今日的预测数据
          ranker_prediction = context.ranker_prediction[
              context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
          
      
      #    try:
      #        prediction = context.prediction[data.current_dt.strftime('%Y-%m-%d')]
      #    except KeyError as e:
      #        return
          
          instrument = context.instruments[0]
          sid = context.symbol(instrument)
          cur_position = context.portfolio.positions[sid].amount
          
          # 交易逻辑
      #    if prediction > 0.5 and cur_position == 0:
      #        context.order_target_percent(context.symbol(instrument), 1)
      #        print(data.current_dt, '买入!')
              
      #    elif prediction < 0.5 and cur_position > 0:
      #        context.order_target_percent(context.symbol(instrument), 0)
      #        print(data.current_dt, '卖出!')
          
          
          #跟踪止盈止损------设定若回调4%止盈, 止损
          
          #------------------------------------------止损模块START--------------------------------------------
          equities = {e.symbol: p for e, p in context.portfolio.positions.items() if p.amount>0}
          
          # 新建当日止损股票列表是为了handle_data 策略逻辑部分不再对该股票进行判断
          stoploss_stock = [] 
          if len(equities) > 0:
              for i in equities.keys():
                  stock_market_price = data.current(context.symbol(i), 'price')  # 最新市场价格
                  last_sale_date = equities[i].last_sale_date   # 上次交易日期
                  delta_days = data.current_dt - last_sale_date  
                  hold_days = delta_days.days # 持仓天数
                  # 建仓以来的最高价
                  highest_price_since_buy = data.history(context.symbol(i), 'high', hold_days, '1d').max()
                  # 确定止损位置5%
                  stoploss_line = highest_price_since_buy - highest_price_since_buy * 0.05
                  #record('止损位置', stoploss_line)
                  # 如果价格下穿止损位置
                  if stock_market_price < stoploss_line:
                      context.order_target_percent(context.symbol(i), 0)     
                      stoploss_stock.append(i)
              if len(stoploss_stock)>0:
                  print('日期:', today, '股票:', stoploss_stock, '出现跟踪止损状况')
          #-------------------------------------------止损模块END---------------------------------------------    
          
          # 按日期过滤得到今日的预测数据
          ranker_prediction = context.ranker_prediction[
              context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
      
          # 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, (1 if is_staging else 1.5) * cash_avg)
          cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)
          positions = {e.symbol: p.amount * p.last_sale_price
                       for e, p in context.perf_tracker.position_tracker.positions.items()}
      
          sell_stock = []
          # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
          if not is_staging and cash_for_sell > 0:
              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]))])))
              for instrument in instruments:
                  # 如果已经移动止损卖出过则不再轮仓卖出,以防止出现空头持仓
                  if instrument in stoploss_stock:
                      continue
                  context.order_target(context.symbol(instrument), 0)
                  cash_for_sell -= positions[instrument]
                  # 记录轮仓卖出的股票
                  sell_stock.append(instrument)
                  if cash_for_sell <= 0:
                      break
      
          # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
          buy_cash_weights = context.stock_weights
          buy_list = list(ranker_prediction.instrument)
          # 不再买入已经轮仓卖出和移动止损的股票,以防止出现空头持仓
          buy_instruments = [i for i in buy_list if i not in sell_stock + stoploss_stock][:len(buy_cash_weights)]
          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 m19_prepare_bigquant_run(context):
          #在数据准备函数中一次性计算每日的大盘风控条件相比于在handle中每日计算风控条件可以提高回测速度
          # 多取50天的数据便于计算均值(保证回测的第一天均值不为Nan值),其中context.start_date和context.end_date是回测指定的起始时间和终止时间
          start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d') 
          df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close'])
          benckmark_data=df[df.instrument=='000001.HIX']
          #计算上证指数5日涨幅
          benckmark_data['ret5']=benckmark_data['close']/benckmark_data['close'].shift(5)-1
          #计算大盘风控条件,如果5日涨幅小于-5%则设置风险状态risk为1,否则为0
          benckmark_data['risk'] = np.where(benckmark_data['ret5']<-0.05,1,0)
          #修改日期格式为字符串(便于在handle中使用字符串日期索引来查看每日的风险状态)
          benckmark_data['date']=benckmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d'))
          #设置日期为索引
          benckmark_data.set_index('date',inplace=True)
          #把风控序列输出给全局变量context.benckmark_risk
          context.benckmark_risk=benckmark_data['risk']
      
      
      def m19_before_trading_start_bigquant_run(context, data):
          pass
      
      m1 = M.instruments.v2(
          start_date='2015-01-01',
          end_date='2017-01-01',
          market='CN_STOCK_A',
          instrument_list="""000004.SZA
      000001.SZA
      000002.SZA
      600800.SHA
      002498.SZA
      300212.SZA
      300576.SZA
      002879.SZA
      300363.SZA
      002291.SZA
      002023.SZA
      600196.SHA
      600161.SHA
      002007.SZA
      300543.SZA
      300525.SZA
      300607.SZA
      300316.SZA
      002409.SZA
      300236.SZA
      603707.SHA
      002371.SZA
      300413.SZA
      600536.SHA
      002555.SZA
      603160.SHA
      300455.SZA
      600570.SHA
      300033.SZA
      002396.SZA
      603859.SHA
      000661.SZA
      603986.SHA
      600588.SHA
      300122.SZA
      600585.SHA
      603160.SHA
      300142.SZA
      300706.SZA
      000938.SZA
      002230.SZA
      603939.SHA
      002714.SZA
      600745.SHA
      603501.SHA
      002153.SZA
      000895.SZA
      300347.SZA
      601888.SHA
      300750.SZA
      603288.SHA
      300552.SZA
      300526.SZA
      002552.SZA
      603501.SHA
      300661.SZA
      300223.SZA
      002351.SZA
      300573.SZA
      300759.SZA
      300803.SZA
      300775.SZA
      300661.SZA
      601865.SHA
      002600.SZA
      300785.SZA
      300777.SZA
      002869.SZA
      601236.SHA
      300220.SZA
      300797.SZA
      603093.SHA
      300799.SZA
      300709.SZA
      603613.SHA
      300792.SZA
      002937.SZA
      300783.SZA
      601066.SHA
      601698.SHA
      002945.SZA
      002458.SZA
      603927.SHA
      603068.SHA
      300379.SZA
      002201.SZA
      603986.SHA
      000066.SZA
      600131.SHA
      002475.SZA
      300341.SZA
      300397.SZA
      300014.SZA
      002791.SZA
      002463.SZA
      600519.SHA
      600809.SHA
      000858.SZA
      000596.SZA
      600132.SHA
      600779.SHA
      600776.SHA
      000622.SZA
      002607.SZA
      300107.SZA
      002243.SZA
      000860.SZA
      300559.SZA
      000860.SZA
      603605.SHA
      603039.SHA
      300253.SZA
      300550.SZA
      300596.SZA
      603345.SHA
      300451.SZA
      002399.SZA
      600604.SHA
      600556.SHA
      603283.SHA
      002708.SZA
      600408.SHA
      600235.SHA
      300598.SZA
      002755.SZA
      000953.SZA
      000760.SZA
      002921.SZA
      002864.SZA
      002795.SZA
      002575.SZA
      002288.SZA
      000068.SZA
      002927.SZA
      603032.SHA
      600247.SHA
      002931.SZA
      300746.SZA
      601330.SHA
      300748.SZA
      603712.SHA
      002927.SZA
      601606.SHA
      300747.SZA
      601162.SHA
      603056.SHA
      002415.SZA
      300003.SZA
      002963.SZA
      002236.SZA
      300124.SZA
      300296.SZA
      300253.SZA
      002475.SZA
      000333.SZA
      600886.SHA
      000703.SZA
      600438.SHA
      600482.SHA
      600661.SHA
      002955.SZA
      002465.SZA
      600739.SHA
      601989.SHA
      600601.SHA
      600654.SHA
      600887.SHA
      000626.SZA
      000538.SZA
      000002.SZA
      600118.SHA
      000568.SZA
      600620.SHA
      600570.SHA
      000060.SZA
      000503.SZA
      300674.SZA
      600903.SHA
      300487.SZA
      300647.SZA
      002776.SZA
      300670.SZA
      300107.SZA
      300730.SZA
      300027.SZA
      601899.SHA
      300352.SZA
      000636.SZA
      002092.SZA
      000980.SZA
      600704.SHA
      002635.SZA
      000709.SZA
      000050.SZA
      300079.SZA
      300296.SZA
      002405.SZA
      600660.SHA
      601088.SHA
      000338.SZA
      600697.SHA
      000803.SZA
      000895.SZA
      300223.SZA
      002826.SZA
      002371.SZA
      002218.SZA
      300676.SZA
      300015.SZA
      000625.SZA
      000063.SZA
      300148.SZA
      603288.SHA
      601668.SHA
      600839.SHA
      002466.SZA
      000876.SZA
      002234.SZA
      600332.SHA
      002024.SZA
      600547.SHA
      002038.SZA
      000651.SZA
      002035.SZA
      002032.SZA
      300498.SZA
      002022.SZA
      600048.SHA
      600489.SHA
      600436.SHA
      600031.SHA
      000402.SZA
      600309.SHA
      000423.SZA
      600521.SHA
      600500.SHA
      600030.SHA
      600993.SHA
      600522.SHA
      002230.SZA
      600853.SHA
      002838.SZA
      002414.SZA
      300628.SZA
      002239.SZA
      300160.SZA
      300578.SZA
      603200.SHA
      002613.SZA
      000652.SZA
      002824.SZA
      300677.SZA
      300235.SZA
      600516.SHA
      000425.SZA
      002607.SZA
      600789.SHA
      000518.SZA
      300346.SZA
      300236.SZA
      300706.SZA
      300666.SZA
      600276.SHA
      600422.SHA
      300601.SZA
      002223.SZA
      002916.SZA
      300632.SZA
      300450.SZA
      300014.SZA
      002841.SZA
      002463.SZA
      603160.SHA
      600183.SHA
      603178.SHA
      600242.SHA
      603825.SHA
      603738.SHA
      603920.SHA
      603005.SHA
      600513.SHA
      603598.SHA
      603608.SHA
      300176.SZA
      601313.SHA
      000830.SZA
      601012.SHA
      002460.SZA
      002415.SZA
      600460.SHA
      600779.SHA
      603690.SHA
      603533.SHA
      300708.SZA
      300725.SZA
      603032.SHA
      002833.SZA
      300618.SZA
      603929.SHA
      002836.SZA
      000830.SZA
      601012.SHA
      002460.SZA
      300585.SZA
      000935.SZA
      603876.SHA
      601116.SHA
      002695.SZA
      300174.SZA
      002089.SZA
      300340.SZA
      300431.SZA
      300364.SZA
      002751.SZA
      300446.SZA
      300451.SZA
      002506.SZA
      300469.SZA
      000025.SZA
      603601.SHA
      002739.SZA
      300410.SZA
      300467.SZA
      002747.SZA
      300437.SZA
      600053.SHA
      002075.SZA
      300479.SZA
      300078.SZA
      300383.SZA
      002771.SZA
      300458.SZA
      300422.SZA
      300441.SZA
      300302.SZA
      600165.SHA
      300429.SZA
      300480.SZA
      603318.SHA
      002027.SZA
      603678.SHA
      300299.SZA
      002741.SZA
      300457.SZA
      603918.SHA
      603169.SHA
      603019.SHA
      600399.SHA
      300162.SZA
      600317.SHA
      300033.SZA
      600556.SHA
      000693.SZA
      300324.SZA
      002544.SZA""",
          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日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
      shift(close, -5) / shift(open, -1)-1
      
      # 极值处理:用1%和99%分位的值做clip
      clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
      
      # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
      where(shift(high, -1) == shift(low, -1), NaN, label)
      where(label>0.5, NaN, label)
      where(label<-0.5, NaN, label)
      """,
          start_date='',
          end_date='',
          benchmark='000300.SHA',
          drop_na_label=True,
          cast_label_int=False
      )
      
      m3 = M.input_features.v1(
          features="""# #号开始的表示注释
      # 多个特征,每行一个,可以包含基础特征和衍生特征
      return_5-1
      return_10-1
      return_20-1
      avg_amount_0/avg_amount_5-1
      avg_amount_5/avg_amount_20-1
      rank_avg_amount_0-rank_avg_amount_5
      rank_avg_amount_5-rank_avg_amount_10
      rank_return_0-rank_return_5
      rank_return_5-rank_return_10
      beta_csi300_30_0/10
      beta_csi300_60_0/10
      swing_volatility_5_0/swing_volatility_30_0-1
      swing_volatility_30_0/swing_volatility_60_0-1
      ta_atr_14_0/ta_atr_28_0-1
      ta_sma_5_0/ta_sma_20_0-1
      ta_sma_10_0/ta_sma_20_0-1
      ta_sma_20_0/ta_sma_30_0-1
      ta_sma_30_0/ta_sma_60_0-1
      ta_rsi_14_0/100
      ta_rsi_28_0/100
      ta_cci_14_0/500
      ta_cci_28_0/500
      beta_industry_30_0/10
      beta_industry_60_0/10
      ta_sma(amount_0, 10)/ta_sma(amount_0, 20)-1
      ta_sma(amount_0, 20)/ta_sma(amount_0, 30)-1
      ta_sma(amount_0, 30)/ta_sma(amount_0, 60)-1
      ta_sma(amount_0, 50)/ta_sma(amount_0, 100)-1
      ta_sma(turn_0, 10)/ta_sma(turn_0, 20)-1
      ta_sma(turn_0, 20)/ta_sma(turn_0, 30)-1
      ta_sma(turn_0, 30)/ta_sma(turn_0, 60)-1
      ta_sma(turn_0, 50)/ta_sma(turn_0, 100)-1
      high_0/low_0-1
      close_0/open_0-1
      shift(close_0,1)/close_0-1
      shift(close_0,2)/close_0-1
      shift(close_0,3)/close_0-1
      shift(close_0,4)/close_0-1
      shift(close_0,5)/close_0-1
      shift(close_0,10)/close_0-1
      shift(close_0,20)/close_0-1
      ta_sma(high_0-low_0, 5)/ta_sma(high_0-low_0, 20)-1
      ta_sma(high_0-low_0, 10)/ta_sma(high_0-low_0, 20)-1
      ta_sma(high_0-low_0, 20)/ta_sma(high_0-low_0, 30)-1
      ta_sma(high_0-low_0, 30)/ta_sma(high_0-low_0, 60)-1
      ta_sma(high_0-low_0, 50)/ta_sma(high_0-low_0, 100)-1
      rank_avg_amount_5
      rank_avg_turn_5
      rank_volatility_5_0
      rank_swing_volatility_5_0
      rank_avg_mf_net_amount_5
      rank_beta_industry_5_0
      rank_return_5
      rank_return_2
      std(close_0,5)/std(close_0,20)-1
      std(close_0,10)/std(close_0,20)-1
      std(close_0,20)/std(close_0,30)-1
      std(close_0,30)/std(close_0,60)-1
      std(close_0,50)/std(close_0,100)-1
      #--------多头排列回踩买入
      buy_condition=where((mean(close_0,5)>mean(close_0,10))&(mean(close_0,10)>mean(close_0,20))&(mean(close_0,20)>mean(close_0,40))&(mean(close_0,40)>mean(close_0,120))&(low_0<mean(close_0,10)),1,0)
      sell_condition=where(mean(close_0,5)<mean(close_0,40),1,0)
      
      ta_bbands_lowerband_28_0
      ta_bbands_upperband_28_0"""
      )
      
      m15 = M.general_feature_extractor.v7(
          instruments=m1.data,
          features=m3.data,
          start_date='',
          end_date='',
          before_start_days=0
      )
      
      m16 = M.derived_feature_extractor.v3(
          input_data=m15.data,
          features=m3.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False
      )
      
      m7 = M.join.v3(
          data1=m2.data,
          data2=m16.data,
          on='date,instrument',
          how='inner',
          sort=False
      )
      
      m10 = M.features_short.v1(
          input_1=m3.data
      )
      
      m13 = M.dl_convert_to_bin.v2(
          input_data=m7.data,
          features=m10.data_1,
          window_size=1,
          feature_clip=5,
          flatten=True,
          window_along_col='instrument'
      )
      
      m9 = M.instruments.v2(
          start_date=T.live_run_param('trading_date', '2017-01-01'),
          end_date=T.live_run_param('trading_date', '2020-03-17'),
          market='CN_STOCK_A',
          instrument_list="""000004.SZA
      000001.SZA
      000002.SZA
      600800.SHA
      002498.SZA
      300212.SZA
      300576.SZA
      002879.SZA
      300363.SZA
      002291.SZA
      002023.SZA
      600196.SHA
      600161.SHA
      002007.SZA
      300543.SZA
      300525.SZA
      300607.SZA
      300316.SZA
      002409.SZA
      300236.SZA
      603707.SHA
      002371.SZA
      300413.SZA
      600536.SHA
      002555.SZA
      603160.SHA
      300455.SZA
      600570.SHA
      300033.SZA
      002396.SZA
      603859.SHA
      000661.SZA
      603986.SHA
      600588.SHA
      300122.SZA
      600585.SHA
      603160.SHA
      300142.SZA
      300706.SZA
      000938.SZA
      002230.SZA
      603939.SHA
      002714.SZA
      600745.SHA
      603501.SHA
      002153.SZA
      000895.SZA
      300347.SZA
      601888.SHA
      300750.SZA
      603288.SHA
      300552.SZA
      300526.SZA
      002552.SZA
      603501.SHA
      300661.SZA
      300223.SZA
      002351.SZA
      300573.SZA
      300759.SZA
      300803.SZA
      300775.SZA
      300661.SZA
      601865.SHA
      002600.SZA
      300785.SZA
      300777.SZA
      002869.SZA
      601236.SHA
      300220.SZA
      300797.SZA
      603093.SHA
      300799.SZA
      300709.SZA
      603613.SHA
      300792.SZA
      002937.SZA
      300783.SZA
      601066.SHA
      601698.SHA
      002945.SZA
      002458.SZA
      603927.SHA
      603068.SHA
      300379.SZA
      002201.SZA
      603986.SHA
      000066.SZA
      600131.SHA
      002475.SZA
      300341.SZA
      300397.SZA
      300014.SZA
      002791.SZA
      002463.SZA
      600519.SHA
      600809.SHA
      000858.SZA
      000596.SZA
      600132.SHA
      600779.SHA
      600776.SHA
      000622.SZA
      002607.SZA
      300107.SZA
      002243.SZA
      000860.SZA
      300559.SZA
      000860.SZA
      603605.SHA
      603039.SHA
      300253.SZA
      300550.SZA
      300596.SZA
      603345.SHA
      300451.SZA
      002399.SZA
      600604.SHA
      600556.SHA
      603283.SHA
      002708.SZA
      600408.SHA
      600235.SHA
      300598.SZA
      002755.SZA
      000953.SZA
      000760.SZA
      002921.SZA
      002864.SZA
      002795.SZA
      002575.SZA
      002288.SZA
      000068.SZA
      002927.SZA
      603032.SHA
      600247.SHA
      002931.SZA
      300746.SZA
      601330.SHA
      300748.SZA
      603712.SHA
      002927.SZA
      601606.SHA
      300747.SZA
      601162.SHA
      603056.SHA
      002415.SZA
      300003.SZA
      002963.SZA
      002236.SZA
      300124.SZA
      300296.SZA
      300253.SZA
      002475.SZA
      000333.SZA
      600886.SHA
      000703.SZA
      600438.SHA
      600482.SHA
      600661.SHA
      002955.SZA
      002465.SZA
      600739.SHA
      601989.SHA
      600601.SHA
      600654.SHA
      600887.SHA
      000626.SZA
      000538.SZA
      000002.SZA
      600118.SHA
      000568.SZA
      600620.SHA
      600570.SHA
      000060.SZA
      000503.SZA
      300674.SZA
      600903.SHA
      300487.SZA
      300647.SZA
      002776.SZA
      300670.SZA
      300107.SZA
      300730.SZA
      300027.SZA
      601899.SHA
      300352.SZA
      000636.SZA
      002092.SZA
      000980.SZA
      600704.SHA
      002635.SZA
      000709.SZA
      000050.SZA
      300079.SZA
      300296.SZA
      002405.SZA
      600660.SHA
      601088.SHA
      000338.SZA
      600697.SHA
      000803.SZA
      000895.SZA
      300223.SZA
      002826.SZA
      002371.SZA
      002218.SZA
      300676.SZA
      300015.SZA
      000625.SZA
      000063.SZA
      300148.SZA
      603288.SHA
      601668.SHA
      600839.SHA
      002466.SZA
      000876.SZA
      002234.SZA
      600332.SHA
      002024.SZA
      600547.SHA
      002038.SZA
      000651.SZA
      002035.SZA
      002032.SZA
      300498.SZA
      002022.SZA
      600048.SHA
      600489.SHA
      600436.SHA
      600031.SHA
      000402.SZA
      600309.SHA
      000423.SZA
      600521.SHA
      600500.SHA
      600030.SHA
      600993.SHA
      600522.SHA
      002230.SZA
      600853.SHA
      002838.SZA
      002414.SZA
      300628.SZA
      002239.SZA
      300160.SZA
      300578.SZA
      603200.SHA
      002613.SZA
      000652.SZA
      002824.SZA
      300677.SZA
      300235.SZA
      600516.SHA
      000425.SZA
      002607.SZA
      600789.SHA
      000518.SZA
      300346.SZA
      300236.SZA
      300706.SZA
      300666.SZA
      600276.SHA
      600422.SHA
      300601.SZA
      002223.SZA
      002916.SZA
      300632.SZA
      300450.SZA
      300014.SZA
      002841.SZA
      002463.SZA
      603160.SHA
      600183.SHA
      603178.SHA
      600242.SHA
      603825.SHA
      603738.SHA
      603920.SHA
      603005.SHA
      600513.SHA
      603598.SHA
      603608.SHA
      300176.SZA
      601313.SHA
      000830.SZA
      601012.SHA
      002460.SZA
      002415.SZA
      600460.SHA
      600779.SHA
      603690.SHA
      603533.SHA
      300708.SZA
      300725.SZA
      603032.SHA
      002833.SZA
      300618.SZA
      603929.SHA
      002836.SZA
      000830.SZA
      601012.SHA
      002460.SZA
      300585.SZA
      000935.SZA
      603876.SHA
      601116.SHA
      002695.SZA
      300174.SZA
      002089.SZA
      300340.SZA
      300431.SZA
      300364.SZA
      002751.SZA
      300446.SZA
      300451.SZA
      002506.SZA
      300469.SZA
      000025.SZA
      603601.SHA
      002739.SZA
      300410.SZA
      300467.SZA
      002747.SZA
      300437.SZA
      600053.SHA
      002075.SZA
      300479.SZA
      300078.SZA
      300383.SZA
      002771.SZA
      300458.SZA
      300422.SZA
      300441.SZA
      300302.SZA
      600165.SHA
      300429.SZA
      300480.SZA
      603318.SHA
      002027.SZA
      603678.SHA
      300299.SZA
      002741.SZA
      300457.SZA
      603918.SHA
      603169.SHA
      603019.SHA
      600399.SHA
      300162.SZA
      600317.SHA
      300033.SZA
      600556.SHA
      000693.SZA
      300324.SZA
      002544.SZA""",
          max_count=0
      )
      
      m17 = M.general_feature_extractor.v7(
          instruments=m9.data,
          features=m3.data,
          start_date='',
          end_date='',
          before_start_days=0
      )
      
      m18 = M.derived_feature_extractor.v3(
          input_data=m17.data,
          features=m3.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False
      )
      
      m14 = M.dl_convert_to_bin.v2(
          input_data=m18.data,
          features=m10.data_1,
          window_size=1,
          feature_clip=5,
          flatten=True,
          window_along_col='instrument'
      )
      
      m6 = M.dl_layer_input.v1(
          shape='63',
          batch_shape='',
          dtype='float32',
          sparse=False,
          name=''
      )
      
      m8 = M.dl_layer_dense.v1(
          inputs=m6.data,
          units=256,
          activation='relu',
          use_bias=True,
          kernel_initializer='glorot_uniform',
          bias_initializer='Zeros',
          kernel_regularizer='None',
          kernel_regularizer_l1=0,
          kernel_regularizer_l2=0,
          bias_regularizer='None',
          bias_regularizer_l1=0,
          bias_regularizer_l2=0,
          activity_regularizer='None',
          activity_regularizer_l1=0,
          activity_regularizer_l2=0,
          kernel_constraint='None',
          bias_constraint='None',
          name=''
      )
      
      m21 = M.dl_layer_dropout.v1(
          inputs=m8.data,
          rate=0.9,
          noise_shape='',
          name=''
      )
      
      m20 = M.dl_layer_dense.v1(
          inputs=m21.data,
          units=128,
          activation='relu',
          use_bias=True,
          kernel_initializer='glorot_uniform',
          bias_initializer='Zeros',
          kernel_regularizer='None',
          kernel_regularizer_l1=0,
          kernel_regularizer_l2=0,
          bias_regularizer='None',
          bias_regularizer_l1=0,
          bias_regularizer_l2=0,
          activity_regularizer='None',
          activity_regularizer_l1=0,
          activity_regularizer_l2=0,
          kernel_constraint='None',
          bias_constraint='None',
          name=''
      )
      
      m22 = M.dl_layer_dropout.v1(
          inputs=m20.data,
          rate=0.9,
          noise_shape='',
          name=''
      )
      
      m23 = M.dl_layer_dense.v1(
          inputs=m22.data,
          units=1,
          activation='linear',
          use_bias=True,
          kernel_initializer='glorot_uniform',
          bias_initializer='Zeros',
          kernel_regularizer='None',
          kernel_regularizer_l1=0,
          kernel_regularizer_l2=0,
          bias_regularizer='None',
          bias_regularizer_l1=0,
          bias_regularizer_l2=0,
          activity_regularizer='None',
          activity_regularizer_l1=0,
          activity_regularizer_l2=0,
          kernel_constraint='None',
          bias_constraint='None',
          name=''
      )
      
      m4 = M.dl_model_init.v1(
          inputs=m6.data,
          outputs=m23.data
      )
      
      m5 = M.dl_model_train.v1(
          input_model=m4.data,
          training_data=m13.data,
          optimizer='Adam',
          loss='mean_squared_error',
          metrics='mse',
          batch_size=10240,
          epochs=2,
          n_gpus=0,
          verbose='2:每个epoch输出一行记录'
      )
      
      m11 = M.dl_model_predict.v1(
          trained_model=m5.data,
          input_data=m14.data,
          batch_size=1024,
          n_gpus=0,
          verbose='2:每个epoch输出一行记录'
      )
      
      m24 = M.cached.v3(
          input_1=m11.data,
          input_2=m18.data,
          run=m24_run_bigquant_run,
          post_run=m24_post_run_bigquant_run,
          input_ports='',
          params='{}',
          output_ports=''
      )
      
      m19 = M.trade.v4(
          instruments=m9.data,
          options_data=m24.data_1,
          start_date='',
          end_date='',
          initialize=m19_initialize_bigquant_run,
          handle_data=m19_handle_data_bigquant_run,
          prepare=m19_prepare_bigquant_run,
          before_trading_start=m19_before_trading_start_bigquant_run,
          volume_limit=0.025,
          order_price_field_buy='vwap_2',
          order_price_field_sell='vwap_4',
          capital_base=1000000,
          auto_cancel_non_tradable_orders=True,
          data_frequency='daily',
          price_type='后复权',
          product_type='股票',
          plot_charts=True,
          backtest_only=False,
          benchmark='000300.SHA'
      )
      
      [2020-03-18 15:32:32.087250] WARNING tensorflow: Large dropout rate: 0.9 (>0.5). In TensorFlow 2.x, dropout() uses dropout rate instead of keep_prob. Please ensure that this is intended.
      
      Train on 72648 samples
      Epoch 1/2
      72648/72648 - 3s - loss: 18.4162 - mse: 18.4162
      Epoch 2/2
      72648/72648 - 2s - loss: 6.7372 - mse: 6.7372
      
      183385/183385 - 1s
      DataSource(6fc60fd7100949c3a678989c8eabb03eT, v3)
      
      日期: 2017-06-12 股票: ['002836.SZA'] 出现跟踪止损状况
      日期: 2017-06-19 股票: ['002836.SZA'] 出现跟踪止损状况
      日期: 2017-07-03 股票: ['600408.SHA'] 出现跟踪止损状况
      日期: 2017-07-13 股票: ['002291.SZA'] 出现跟踪止损状况
      日期: 2017-07-24 股票: ['000002.SZA'] 出现跟踪止损状况
      日期: 2017-08-01 股票: ['300601.SZA'] 出现跟踪止损状况
      日期: 2017-08-02 股票: ['300027.SZA'] 出现跟踪止损状况
      日期: 2017-08-04 股票: ['600183.SHA'] 出现跟踪止损状况
      日期: 2017-08-21 股票: ['300124.SZA'] 出现跟踪止损状况
      日期: 2017-09-14 股票: ['300450.SZA'] 出现跟踪止损状况
      日期: 2017-10-09 股票: ['000402.SZA'] 出现跟踪止损状况
      日期: 2017-10-16 股票: ['300457.SZA'] 出现跟踪止损状况
      日期: 2017-10-18 股票: ['300598.SZA'] 出现跟踪止损状况
      日期: 2017-10-24 股票: ['000063.SZA'] 出现跟踪止损状况
      日期: 2017-10-30 股票: ['300618.SZA'] 出现跟踪止损状况
      日期: 2017-11-03 股票: ['300379.SZA'] 出现跟踪止损状况
      日期: 2017-11-06 股票: ['603690.SHA'] 出现跟踪止损状况
      日期: 2017-11-20 股票: ['002371.SZA'] 出现跟踪止损状况
      日期: 2017-11-27 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-11-28 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-11-29 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-11-30 股票: ['300383.SZA', '000063.SZA'] 出现跟踪止损状况
      日期: 2017-12-01 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-04 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-05 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-06 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-07 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-08 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-11 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-12 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-13 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-14 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-15 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-18 股票: ['300383.SZA', '600161.SHA', '002236.SZA'] 出现跟踪止损状况
      日期: 2017-12-19 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-20 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-21 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-22 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-25 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-26 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-27 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-28 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2017-12-29 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-02 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-03 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-04 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-05 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-08 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-09 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-10 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-11 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-12 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-15 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-16 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-17 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-18 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-19 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-22 股票: ['300383.SZA', '002460.SZA'] 出现跟踪止损状况
      日期: 2018-01-23 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-24 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-25 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-26 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-29 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-30 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-01-31 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-01 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-02 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-05 股票: ['300383.SZA', '002414.SZA'] 出现跟踪止损状况
      日期: 2018-02-06 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-07 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-08 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-09 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-12 股票: ['300383.SZA', '000503.SZA'] 出现跟踪止损状况
      日期: 2018-02-13 股票: ['300383.SZA', '000503.SZA'] 出现跟踪止损状况
      日期: 2018-02-14 股票: ['300383.SZA', '000503.SZA'] 出现跟踪止损状况
      日期: 2018-02-22 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-23 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-26 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-27 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-02-28 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-01 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-02 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-05 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-06 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-07 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-08 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-09 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-12 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-13 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-14 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-15 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-16 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-03-21 股票: ['300647.SZA', '300458.SZA'] 出现跟踪止损状况
      日期: 2018-03-23 股票: ['002291.SZA', '300446.SZA', '300526.SZA'] 出现跟踪止损状况
      日期: 2018-03-28 股票: ['600422.SHA'] 出现跟踪止损状况
      日期: 2018-04-02 股票: ['300469.SZA'] 出现跟踪止损状况
      日期: 2018-04-09 股票: ['002575.SZA'] 出现跟踪止损状况
      日期: 2018-04-17 股票: ['002153.SZA', '600196.SHA'] 出现跟踪止损状况
      日期: 2018-04-20 股票: ['002396.SZA'] 出现跟踪止损状况
      日期: 2018-04-23 股票: ['300469.SZA'] 出现跟踪止损状况
      日期: 2018-04-26 股票: ['300677.SZA'] 出现跟踪止损状况
      日期: 2018-05-02 股票: ['603019.SHA'] 出现跟踪止损状况
      日期: 2018-05-17 股票: ['000636.SZA'] 出现跟踪止损状况
      日期: 2018-05-21 股票: ['000425.SZA', '002755.SZA', '600809.SHA'] 出现跟踪止损状况
      日期: 2018-05-22 股票: ['002795.SZA'] 出现跟踪止损状况
      日期: 2018-05-25 股票: ['300730.SZA'] 出现跟踪止损状况
      日期: 2018-05-28 股票: ['002236.SZA'] 出现跟踪止损状况
      日期: 2018-05-30 股票: ['300598.SZA', '000760.SZA'] 出现跟踪止损状况
      日期: 2018-06-01 股票: ['300730.SZA'] 出现跟踪止损状况
      日期: 2018-06-04 股票: ['603929.SHA', '300618.SZA'] 出现跟踪止损状况
      日期: 2018-06-07 股票: ['300015.SZA'] 出现跟踪止损状况
      日期: 2018-06-11 股票: ['002921.SZA'] 出现跟踪止损状况
      日期: 2018-06-13 股票: ['000068.SZA', '002458.SZA'] 出现跟踪止损状况
      日期: 2018-06-19 股票: ['300647.SZA', '002607.SZA'] 出现跟踪止损状况
      日期: 2018-06-20 股票: ['002741.SZA'] 出现跟踪止损状况
      日期: 2018-06-22 股票: ['300578.SZA'] 出现跟踪止损状况
      日期: 2018-06-27 股票: ['002234.SZA'] 出现跟踪止损状况
      日期: 2018-07-02 股票: ['002607.SZA'] 出现跟踪止损状况
      日期: 2018-07-05 股票: ['600048.SHA'] 出现跟踪止损状况
      日期: 2018-07-13 股票: ['002607.SZA'] 出现跟踪止损状况
      日期: 2018-07-16 股票: ['300607.SZA'] 出现跟踪止损状况
      日期: 2018-07-19 股票: ['300666.SZA'] 出现跟踪止损状况
      日期: 2018-07-23 股票: ['601888.SHA'] 出现跟踪止损状况
      日期: 2018-07-27 股票: ['300437.SZA'] 出现跟踪止损状况
      日期: 2018-07-30 股票: ['002747.SZA', '600739.SHA'] 出现跟踪止损状况
      日期: 2018-08-02 股票: ['600053.SHA'] 出现跟踪止损状况
      日期: 2018-08-06 股票: ['300578.SZA'] 出现跟踪止损状况
      日期: 2018-08-16 股票: ['300647.SZA'] 出现跟踪止损状况
      日期: 2018-08-17 股票: ['300340.SZA'] 出现跟踪止损状况
      日期: 2018-08-20 股票: ['002714.SZA'] 出现跟踪止损状况
      日期: 2018-09-03 股票: ['300383.SZA'] 出现跟踪止损状况
      日期: 2018-09-10 股票: ['603160.SHA', '000980.SZA', '002755.SZA', '002027.SZA', '000760.SZA'] 出现跟踪止损状况
      日期: 2018-09-14 股票: ['002475.SZA'] 出现跟踪止损状况
      日期: 2018-09-17 股票: ['000830.SZA', '300347.SZA', '600276.SHA'] 出现跟踪止损状况
      日期: 2018-09-20 股票: ['000760.SZA'] 出现跟踪止损状况
      日期: 2018-09-27 股票: ['300296.SZA'] 出现跟踪止损状况
      日期: 2018-10-08 股票: ['300618.SZA', '603712.SHA', '002879.SZA'] 出现跟踪止损状况
      日期: 2018-10-11 股票: ['300379.SZA', '002755.SZA', '603986.SHA'] 出现跟踪止损状况
      日期: 2018-10-15 股票: ['603939.SHA', '002607.SZA', '002239.SZA', '002023.SZA', '000980.SZA'] 出现跟踪止损状况
      日期: 2018-10-16 股票: ['603939.SHA'] 出现跟踪止损状况
      日期: 2018-10-17 股票: ['603939.SHA'] 出现跟踪止损状况
      日期: 2018-10-18 股票: ['603939.SHA'] 出现跟踪止损状况
      日期: 2018-10-23 股票: ['002741.SZA', '300107.SZA'] 出现跟踪止损状况
      日期: 2018-10-29 股票: ['002755.SZA', '002465.SZA'] 出现跟踪止损状况
      日期: 2018-11-06 股票: ['603288.SHA', '002708.SZA'] 出现跟踪止损状况
      日期: 2018-11-23 股票: ['000622.SZA'] 出现跟踪止损状况
      日期: 2018-11-26 股票: ['600235.SHA', '300142.SZA', '300469.SZA'] 出现跟踪止损状况
      日期: 2018-12-03 股票: ['600839.SHA', '601066.SHA'] 出现跟踪止损状况
      日期: 2018-12-07 股票: ['002089.SZA'] 出现跟踪止损状况
      日期: 2018-12-10 股票: ['002826.SZA', '600745.SHA'] 出现跟踪止损状况
      日期: 2018-12-27 股票: ['000068.SZA', '600604.SHA', '600053.SHA', '300324.SZA', '000652.SZA'] 出现跟踪止损状况
      日期: 2018-12-28 股票: ['000068.SZA'] 出现跟踪止损状况
      日期: 2019-01-02 股票: ['000068.SZA'] 出现跟踪止损状况
      日期: 2019-01-03 股票: ['000068.SZA'] 出现跟踪止损状况
      日期: 2019-01-04 股票: ['000068.SZA'] 出现跟踪止损状况
      日期: 2019-01-09 股票: ['002708.SZA'] 出现跟踪止损状况
      日期: 2019-01-11 股票: ['300341.SZA'] 出现跟踪止损状况
      日期: 2019-01-18 股票: ['300632.SZA'] 出现跟踪止损状况
      日期: 2019-01-28 股票: ['002089.SZA'] 出现跟踪止损状况
      日期: 2019-02-26 股票: ['002600.SZA'] 出现跟踪止损状况
      日期: 2019-02-28 股票: ['000652.SZA', '002243.SZA'] 出现跟踪止损状况
      日期: 2019-03-07 股票: ['601012.SHA'] 出现跟踪止损状况
      日期: 2019-03-11 股票: ['002405.SZA'] 出现跟踪止损状况
      日期: 2019-03-13 股票: ['600839.SHA'] 出现跟踪止损状况
      日期: 2019-03-14 股票: ['600408.SHA'] 出现跟踪止损状况
      日期: 2019-03-22 股票: ['300079.SZA'] 出现跟踪止损状况
      日期: 2019-03-26 股票: ['000066.SZA', '000518.SZA'] 出现跟踪止损状况
      日期: 2019-03-28 股票: ['600800.SHA'] 出现跟踪止损状况
      日期: 2019-04-08 股票: ['300725.SZA', '600482.SHA'] 出现跟踪止损状况
      日期: 2019-04-09 股票: ['000060.SZA'] 出现跟踪止损状况
      日期: 2019-04-15 股票: ['000830.SZA', '300107.SZA'] 出现跟踪止损状况
      日期: 2019-04-18 股票: ['002458.SZA'] 出现跟踪止损状况
      日期: 2019-04-22 股票: ['600620.SHA'] 出现跟踪止损状况
      日期: 2019-04-23 股票: ['000063.SZA'] 出现跟踪止损状况
      日期: 2019-04-26 股票: ['002739.SZA'] 出现跟踪止损状况
      日期: 2019-04-29 股票: ['600031.SHA'] 出现跟踪止损状况
      日期: 2019-05-06 股票: ['300526.SZA', '300079.SZA'] 出现跟踪止损状况
      日期: 2019-05-13 股票: ['000004.SZA'] 出现跟踪止损状况
      日期: 2019-05-17 股票: ['600745.SHA'] 出现跟踪止损状况
      日期: 2019-05-23 股票: ['002475.SZA'] 出现跟踪止损状况
      日期: 2019-05-27 股票: ['600776.SHA'] 出现跟踪止损状况
      日期: 2019-06-04 股票: ['002776.SZA'] 出现跟踪止损状况
      日期: 2019-06-05 股票: ['300674.SZA'] 出现跟踪止损状况
      日期: 2019-06-10 股票: ['300176.SZA'] 出现跟踪止损状况
      日期: 2019-06-11 股票: ['300176.SZA'] 出现跟踪止损状况
      日期: 2019-06-24 股票: ['300573.SZA'] 出现跟踪止损状况
      日期: 2019-06-25 股票: ['600422.SHA'] 出现跟踪止损状况
      日期: 2019-07-04 股票: ['002414.SZA'] 出现跟踪止损状况
      日期: 2019-07-15 股票: ['300709.SZA'] 出现跟踪止损状况
      日期: 2019-07-18 股票: ['002405.SZA'] 出现跟踪止损状况
      日期: 2019-07-22 股票: ['002291.SZA', '600500.SHA', '002409.SZA', '603169.SHA', '000876.SZA'] 出现跟踪止损状况
      日期: 2019-08-05 股票: ['002027.SZA', '600604.SHA', '601668.SHA', '300122.SZA'] 出现跟踪止损状况
      日期: 2019-08-08 股票: ['002776.SZA'] 出现跟踪止损状况
      日期: 2019-08-14 股票: ['603738.SHA'] 出现跟踪止损状况
      日期: 2019-08-26 股票: ['002751.SZA'] 出现跟踪止损状况
      日期: 2019-08-28 股票: ['000625.SZA'] 出现跟踪止损状况
      日期: 2019-09-02 股票: ['600048.SHA'] 出现跟踪止损状况
      日期: 2019-09-11 股票: ['603318.SHA'] 出现跟踪止损状况
      日期: 2019-09-16 股票: ['000858.SZA', '603859.SHA'] 出现跟踪止损状况
      日期: 2019-09-25 股票: ['300340.SZA'] 出现跟踪止损状况
      日期: 2019-09-30 股票: ['603605.SHA'] 出现跟踪止损状况
      日期: 2019-10-08 股票: ['002371.SZA'] 出现跟踪止损状况
      日期: 2019-10-17 股票: ['002552.SZA'] 出现跟踪止损状况
      日期: 2019-10-23 股票: ['000068.SZA', '002351.SZA', '002795.SZA'] 出现跟踪止损状况
      日期: 2019-10-24 股票: ['000538.SZA'] 出现跟踪止损状况
      日期: 2019-10-29 股票: ['000860.SZA', '600131.SHA', '300160.SZA'] 出现跟踪止损状况
      日期: 2019-10-31 股票: ['000066.SZA'] 出现跟踪止损状况
      日期: 2019-11-04 股票: ['300148.SZA', '002463.SZA'] 出现跟踪止损状况
      日期: 2019-11-06 股票: ['002291.SZA'] 出现跟踪止损状况
      日期: 2019-11-08 股票: ['002552.SZA', '300235.SZA'] 出现跟踪止损状况
      日期: 2019-11-18 股票: ['603318.SHA', '002291.SZA', '000004.SZA', '603690.SHA'] 出现跟踪止损状况
      日期: 2019-11-26 股票: ['300015.SZA'] 出现跟踪止损状况
      日期: 2019-12-02 股票: ['300015.SZA', '300598.SZA'] 出现跟踪止损状况
      日期: 2019-12-05 股票: ['300341.SZA'] 出现跟踪止损状况
      日期: 2019-12-09 股票: ['603318.SHA', '600800.SHA'] 出现跟踪止损状况
      日期: 2019-12-12 股票: ['300341.SZA'] 出现跟踪止损状况
      日期: 2019-12-13 股票: ['603318.SHA', '600800.SHA'] 出现跟踪止损状况
      日期: 2019-12-18 股票: ['002291.SZA'] 出现跟踪止损状况
      日期: 2019-12-20 股票: ['300341.SZA', '002291.SZA'] 出现跟踪止损状况
      日期: 2019-12-23 股票: ['002466.SZA', '000066.SZA'] 出现跟踪止损状况
      日期: 2019-12-24 股票: ['002466.SZA'] 出现跟踪止损状况
      日期: 2019-12-26 股票: ['002466.SZA'] 出现跟踪止损状况
      日期: 2019-12-30 股票: ['603738.SHA'] 出现跟踪止损状况
      日期: 2019-12-31 股票: ['601236.SHA'] 出现跟踪止损状况
      日期: 2020-01-07 股票: ['603608.SHA'] 出现跟踪止损状况
      日期: 2020-01-10 股票: ['603598.SHA'] 出现跟踪止损状况
      日期: 2020-01-14 股票: ['002239.SZA'] 出现跟踪止损状况
      日期: 2020-01-16 股票: ['603608.SHA', '002776.SZA'] 出现跟踪止损状况
      日期: 2020-01-20 股票: ['300725.SZA'] 出现跟踪止损状况
      日期: 2020-01-23 股票: ['002739.SZA', '000626.SZA'] 出现跟踪止损状况
      日期: 2020-02-03 股票: ['000425.SZA', '600031.SHA'] 出现跟踪止损状况
      日期: 2020-02-06 股票: ['603825.SHA'] 出现跟踪止损状况
      日期: 2020-02-11 股票: ['002747.SZA'] 出现跟踪止损状况
      日期: 2020-02-12 股票: ['600513.SHA'] 出现跟踪止损状况
      日期: 2020-02-17 股票: ['603601.SHA', '600513.SHA'] 出现跟踪止损状况
      日期: 2020-02-20 股票: ['300363.SZA'] 出现跟踪止损状况
      日期: 2020-02-21 股票: ['000652.SZA'] 出现跟踪止损状况
      日期: 2020-02-25 股票: ['300422.SZA'] 出现跟踪止损状况
      日期: 2020-02-27 股票: ['002460.SZA', '002635.SZA', '000518.SZA'] 出现跟踪止损状况
      日期: 2020-03-02 股票: ['300316.SZA'] 出现跟踪止损状况
      日期: 2020-03-06 股票: ['603598.SHA', '000652.SZA', '002613.SZA'] 出现跟踪止损状况
      日期: 2020-03-09 股票: ['603283.SHA'] 出现跟踪止损状况
      日期: 2020-03-16 股票: ['600438.SHA'] 出现跟踪止损状况
      日期: 2020-03-17 股票: ['002075.SZA'] 出现跟踪止损状况
      
      • 收益率70.03%
      • 年化收益率18.73%
      • 基准收益率12.07%
      • 阿尔法0.16
      • 贝塔0.59
      • 夏普比率0.7
      • 胜率0.52
      • 盈亏比1.14
      • 收益波动率24.72%
      • 信息比率0.04
      • 最大回撤20.63%
      bigcharts-data-start/{"__type":"tabs","__id":"bigchart-cb83f268bf124d8ea93c3b2e4ccf31e9"}/bigcharts-data-end

      (woshisilvio) #4

      谢谢老师!