数据标注与特征因子的疑问

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

(xinyan) #1

本人想实现一个上影线选股的策略
条件为:1、当日最大涨幅超过6%,收盘涨幅小于3.5% 2、10日涨幅小于15% 3、20日线往上走。
特征因子使用了当日最高价、开盘价、10日涨幅、20日线之间的关系,数据标注采用了示例里的未来5日收益做分类。
特征因子如下:
#成交量
amount_0/avg_amount_5
#K线关系
high_0/close_1
close_0/close_1
open_0/close_1
close_0/ts_max(close_0, 10)
ts_max(close_0, 10)/ts_min(close_0, 10)
#换手率
#rank_avg_turn_5/rank_avg_turn_10
avg_turn_5/avg_turn_10
#中期趋势
ta_sma_20_0/shift(ta_sma_20_0, 1)

下面是疑问:
1、标注里使用的表达式shift(close, -5) / shift(open, -1)是想利用未来5日收益做分类,但是我检查了下标注的数据,分高的往往了过去5日涨幅较大的,中等的大多数为0,用这个标注回测时发现很多买入都是过去5日涨幅较大之后买入而不是买入后5日涨幅较大,这是我检查的样本不够大吗?
2、我写的这些特征因子是否满足了上面所列的选股条件?
3、我有个想法是用逻辑判断去做标注(用代码实现上面的条件判断放到数据标注表达式里),是否可行?
请指点迷津,谢谢!

克隆策略
In [45]:
m2.plot_label_counts()
m2.data.read_df()
Out[45]:
date m:amount m:close m:open m:high m:low instrument label
0 2016-01-11 8.006836e+08 925.296326 945.934937 952.814453 918.416809 000001.SZA 9
1 2016-01-11 8.175388e+07 129.759109 139.390472 145.283066 129.759109 000004.SZA 18
2 2016-01-11 2.213477e+08 69.228973 75.623619 76.457703 69.228973 000005.SZA 11
3 2016-01-11 2.439680e+08 270.097260 297.619019 298.259064 269.457214 000006.SZA 13
4 2016-01-11 2.013380e+08 214.483810 219.989044 231.219711 209.198792 000008.SZA 10
5 2016-01-11 1.001228e+09 70.417595 75.327934 76.622971 70.417595 000009.SZA 14
6 2016-01-11 1.150239e+08 78.115471 84.041473 86.411873 78.115471 000010.SZA 14
7 2016-01-11 6.697253e+07 34.993042 37.540428 38.043201 34.993042 000011.SZA 15
8 2016-01-11 4.955523e+08 168.836639 180.823013 183.049057 168.836639 000012.SZA 13
9 2016-01-11 7.666122e+07 86.868401 94.375549 94.965393 86.868401 000014.SZA 16
10 2016-01-11 2.481951e+08 101.332115 110.170418 110.581497 101.332115 000016.SZA 14
11 2016-01-11 9.691552e+07 26.693243 29.241844 29.241844 26.693243 000017.SZA 14
12 2016-01-11 1.984801e+08 71.025887 73.484604 77.051483 70.264023 000018.SZA 12
13 2016-01-11 1.029156e+08 28.399963 30.723820 30.723820 28.399963 000019.SZA 18
14 2016-01-11 2.550066e+08 46.913872 49.909492 51.661320 46.913872 000020.SZA 6
15 2016-01-11 2.190600e+08 115.636116 122.965164 126.222519 115.500389 000021.SZA 16
16 2016-01-11 5.879512e+07 54.739456 59.784740 59.822674 54.663586 000022.SZA 12
17 2016-01-11 1.954210e+09 161.093903 166.196350 175.083252 156.782257 000025.SZA 3
18 2016-01-11 1.117598e+08 85.438667 88.192474 90.381401 82.119980 000026.SZA 15
19 2016-01-11 2.179769e+08 95.563560 102.702644 103.203636 94.185844 000027.SZA 11
20 2016-01-11 9.850522e+07 19.681297 21.195244 21.454777 19.681297 000029.SZA 16
21 2016-01-11 6.438335e+07 16.348505 17.507059 18.021973 16.262686 000030.SZA 14
22 2016-01-11 4.667201e+08 142.982407 156.455750 157.005676 142.982407 000031.SZA 12
23 2016-01-11 9.933010e+07 58.238838 63.177219 63.177219 58.238838 000032.SZA 19
24 2016-01-11 3.763868e+08 56.500294 56.778965 60.959011 55.664284 000036.SZA 8
25 2016-01-11 6.961969e+07 50.248253 54.888294 54.888294 50.248253 000037.SZA 17
26 2016-01-11 3.956649e+08 376.927063 413.921753 420.669189 376.927063 000039.SZA 10
27 2016-01-11 2.197473e+08 51.373714 55.826103 55.826103 51.373714 000040.SZA 7
28 2016-01-11 1.266190e+08 226.918091 246.429749 253.271500 226.537994 000042.SZA 7
29 2016-01-11 1.757490e+08 71.012283 78.902542 78.902542 71.012283 000043.SZA 13
... ... ... ... ... ... ... ... ...
623819 2016-12-30 2.237237e+07 46.929012 46.898834 47.110088 46.737877 603883.SHA 8
623820 2016-12-30 4.413900e+07 47.432766 47.473480 47.534554 47.025616 603885.SHA 10
623821 2016-12-30 4.026828e+07 54.299999 54.700001 54.970001 54.060001 603887.SHA 8
623822 2016-12-30 1.455701e+08 86.510628 87.754066 88.141365 86.480057 603888.SHA 9
623823 2016-12-30 2.061212e+07 46.180405 46.088657 46.425072 45.874577 603889.SHA 10
623824 2016-12-30 3.016118e+07 97.804436 94.359978 98.046150 94.359978 603898.SHA 10
623825 2016-12-30 3.860250e+07 37.341942 36.972626 37.690739 36.849522 603899.SHA 9
623826 2016-12-30 1.519039e+08 38.500000 38.139999 38.680000 37.880001 603900.SHA 9
623827 2016-12-30 3.177862e+07 56.886616 56.766350 57.287510 56.445637 603901.SHA 8
623828 2016-12-30 6.596393e+07 49.580326 51.031212 51.931763 49.150063 603909.SHA 12
623829 2016-12-30 6.854441e+07 58.883423 60.105572 60.466202 58.502754 603918.SHA 8
623830 2016-12-30 8.903522e+07 31.070000 30.480000 31.200001 30.260000 603919.SHA 9
623831 2016-12-30 1.767874e+08 27.850000 28.010000 28.350000 27.719999 603928.SHA 19
623832 2016-12-30 3.048930e+07 31.702589 31.982876 32.513420 31.692577 603936.SHA 8
623833 2016-12-30 1.783513e+07 59.646202 59.766945 59.948055 58.599777 603939.SHA 9
623834 2016-12-30 3.006780e+07 29.780001 30.200001 30.280001 29.709999 603958.SHA 10
623835 2016-12-30 2.204838e+07 28.730000 28.760000 29.020000 28.650000 603959.SHA 10
623836 2016-12-30 3.140020e+07 48.833344 48.591793 48.994377 48.491146 603968.SHA 8
623837 2016-12-30 1.997263e+07 28.292513 28.393991 28.495472 28.150440 603969.SHA 8
623838 2016-12-30 1.037837e+08 27.450001 27.450001 27.790001 27.180000 603977.SHA 9
623839 2016-12-30 3.151160e+07 21.468960 21.408756 21.553247 21.384674 603979.SHA 9
623840 2016-12-30 1.289479e+08 32.290001 32.200001 32.500000 31.670000 603987.SHA 10
623841 2016-12-30 2.614312e+07 68.392426 69.429131 69.630432 68.301834 603988.SHA 10
623842 2016-12-30 4.245172e+07 57.893776 56.808559 58.412788 56.808559 603989.SHA 7
623843 2016-12-30 4.705393e+08 55.060001 54.799999 56.880001 53.810001 603990.SHA 0
623844 2016-12-30 7.327321e+07 11.927711 11.991838 12.055966 11.895648 603993.SHA 9
623845 2016-12-30 7.447262e+07 30.212824 30.774006 30.925676 30.030819 603996.SHA 13
623846 2016-12-30 3.175641e+07 19.770798 19.881983 20.003277 19.609074 603997.SHA 8
623847 2016-12-30 4.160723e+07 69.178642 68.511192 69.885345 68.511192 603998.SHA 10
623848 2016-12-30 1.432123e+08 35.303860 35.942028 36.315292 35.231613 603999.SHA 9

623849 rows × 8 columns

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29: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":"287d2cb0-f53c-4101-bdf8-104b137c8601-29:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:model"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81:options_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:training_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:data","SourceOutputPortId":"-86:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2016-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":"","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)\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\nall_wbins(label, 20)\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na_label","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"#上影线策略特征\n#成交量\namount_0/avg_amount_5\n#K线关系\nhigh_0/close_1\nclose_0/close_1\nopen_0/close_1\nclose_0/ts_max(close_0, 10)\nts_max(close_0, 10)/ts_min(close_0, 10)\n#换手率\n#rank_avg_turn_5/rank_avg_turn_10\navg_turn_5/avg_turn_10\n#中期趋势\nta_sma_20_0/shift(ta_sma_20_0, 1)","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-29","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","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":"287d2cb0-f53c-4101-bdf8-104b137c8601-29"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43","ModuleId":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v5","ModuleParameters":[{"Name":"learning_algorithm","Value":"排序","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_leaves","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"minimum_docs_per_leaf","Value":1000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_trees","Value":20,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"learning_rate","Value":0.1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_bins","Value":1023,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"base_model","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"}],"OutputPortsInternal":[{"Name":"model","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43","OutputType":null},{"Name":"feature_gains","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43","OutputType":null},{"Name":"m_lazy_run","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"inner","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","ModuleId":"BigQuantSpace.stock_ranker_predict.stock_ranker_predict-v5","ModuleParameters":[{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"OutputPortsInternal":[{"Name":"predictions","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null},{"Name":"m_lazy_run","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"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":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","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":"287d2cb0-f53c-4101-bdf8-104b137c8601-70"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81","ModuleId":"BigQuantSpace.trade.trade-v3","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n\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 # 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 # print('rank order for sell %s' % instruments)\n for instrument in instruments:\n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n if cash_for_sell <= 0:\n break\n\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n buy_instruments = list(ranker_prediction.instrument[: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 pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\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 = 5\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.2\n context.options['hold_days'] = 5\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":0.025,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"close","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":1000000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","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":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"amount_integer","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":12,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-86","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-86"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-86","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true}],"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='211,64,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='70,183,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='765,21,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-29' Position='381,188,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-35' Position='385,280,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-43' Position='638,561,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='249,375,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='906,647,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1074,127,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-70' Position='1078,236,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-76' Position='1081,327,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-81' Position='1037,751,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='376,467,200,200'/><NodePosition Node='-86' Position='1078,418,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":false}
    In [46]:
    # 本代码由可视化策略环境自动生成 2018年4月4日 14:25
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.instruments.v2(
        start_date='2016-01-01',
        end_date='2017-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.advanced_auto_labeler.v2(
        instruments=m1.data,
        label_expr="""# #号开始的表示注释
    # 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
    # 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html
    #   添加benchmark_前缀,可使用对应的benchmark数据
    # 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_
    
    # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    shift(close, -5) / shift(open, -1)
    
    # 极值处理:用1%和99%分位的值做clip
    clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
    
    # 将分数映射到分类,这里使用20个分类
    all_wbins(label, 20)
    
    # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
    where(shift(high, -1) == shift(low, -1), NaN, label)
    """,
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=True,
        cast_label_int=True
    )
    
    m3 = M.input_features.v1(
        features="""#上影线策略特征
    #成交量
    amount_0/avg_amount_5
    #K线关系
    high_0/close_1
    close_0/close_1
    open_0/close_1
    close_0/ts_max(close_0, 10)
    ts_max(close_0, 10)/ts_min(close_0, 10)
    #换手率
    #rank_avg_turn_5/rank_avg_turn_10
    avg_turn_5/avg_turn_10
    #中期趋势
    ta_sma_20_0/shift(ta_sma_20_0, 1)"""
    )
    
    m4 = M.general_feature_extractor.v6(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m5 = M.derived_feature_extractor.v2(
        input_data=m4.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument'
    )
    
    m7 = M.join.v3(
        data1=m2.data,
        data2=m5.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m7.data
    )
    
    m6 = M.stock_ranker_train.v5(
        training_ds=m13.data,
        features=m3.data,
        learning_algorithm='排序',
        number_of_leaves=30,
        minimum_docs_per_leaf=1000,
        number_of_trees=20,
        learning_rate=0.1,
        max_bins=1023,
        feature_fraction=1,
        m_lazy_run=False
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2017-01-01'),
        end_date=T.live_run_param('trading_date', '2018-01-01'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m10 = M.general_feature_extractor.v6(
        instruments=m9.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m11 = M.derived_feature_extractor.v2(
        input_data=m10.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument'
    )
    
    m14 = M.dropnan.v1(
        input_data=m11.data
    )
    
    m8 = M.stock_ranker_predict.v5(
        model=m6.model,
        data=m14.data,
        m_lazy_run=False
    )
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m12_handle_data_bigquant_run(context, data):
        # 按日期过滤得到今日的预测数据
        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()}
    
        # 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]))])))
            # print('rank order for sell %s' % instruments)
            for instrument in instruments:
                context.order_target(context.symbol(instrument), 0)
                cash_for_sell -= positions[instrument]
                if cash_for_sell <= 0:
                    break
    
        # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
        buy_cash_weights = context.stock_weights
        buy_instruments = list(ranker_prediction.instrument[: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 m12_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:初始化函数,只执行一次
    def m12_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 = 5
        # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[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.2
        context.options['hold_days'] = 5
    
    m12 = M.trade.v3(
        instruments=m9.data,
        options_data=m8.predictions,
        start_date='',
        end_date='',
        handle_data=m12_handle_data_bigquant_run,
        prepare=m12_prepare_bigquant_run,
        initialize=m12_initialize_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=1000000,
        benchmark='000300.SHA',
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='后复权',
        plot_charts=True,
        backtest_only=False,
        amount_integer=False
    )
    
    [2018-04-04 14:04:25.227087] INFO: bigquant: instruments.v2 开始运行..
    [2018-04-04 14:04:25.231063] INFO: bigquant: 命中缓存
    [2018-04-04 14:04:25.231978] INFO: bigquant: instruments.v2 运行完成[0.004928s].
    [2018-04-04 14:04:25.242526] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
    [2018-04-04 14:04:25.245569] INFO: bigquant: 命中缓存
    [2018-04-04 14:04:25.246706] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.004204s].
    [2018-04-04 14:04:25.251590] INFO: bigquant: input_features.v1 开始运行..
    [2018-04-04 14:04:25.254926] INFO: bigquant: 命中缓存
    [2018-04-04 14:04:25.256195] INFO: bigquant: input_features.v1 运行完成[0.004582s].
    [2018-04-04 14:04:25.267358] INFO: bigquant: general_feature_extractor.v6 开始运行..
    [2018-04-04 14:04:33.273986] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
    [2018-04-04 14:04:50.538727] INFO: 基础特征抽取: 年份 2017, 特征行数=0
    [2018-04-04 14:04:50.554708] INFO: 基础特征抽取: 总行数: 641546
    [2018-04-04 14:04:50.558681] INFO: bigquant: general_feature_extractor.v6 运行完成[25.291332s].
    [2018-04-04 14:04:50.571613] INFO: bigquant: derived_feature_extractor.v2 开始运行..
    [2018-04-04 14:04:50.895188] INFO: derived_feature_extractor: 提取完成 amount_0/avg_amount_5, 0.003s
    [2018-04-04 14:04:50.899211] INFO: derived_feature_extractor: 提取完成 avg_turn_5/avg_turn_10, 0.002s
    [2018-04-04 14:04:50.903642] INFO: derived_feature_extractor: 提取完成 close_0/close_1, 0.003s
    [2018-04-04 14:04:53.269900] INFO: derived_feature_extractor: 提取完成 close_0/ts_max(close_0, 10), 2.365s
    [2018-04-04 14:04:53.273623] INFO: derived_feature_extractor: 提取完成 high_0/close_1, 0.002s
    [2018-04-04 14:04:53.276724] INFO: derived_feature_extractor: 提取完成 open_0/close_1, 0.002s
    [2018-04-04 14:04:53.357195] INFO: derived_feature_extractor: 提取完成 ta_sma_20_0/shift(ta_sma_20_0, 1), 0.079s
    [2018-04-04 14:04:57.290394] INFO: derived_feature_extractor: 提取完成 ts_max(close_0, 10)/ts_min(close_0, 10), 3.931s
    [2018-04-04 14:04:57.479335] INFO: derived_feature_extractor: /y_2016, 641546
    [2018-04-04 14:04:59.610592] INFO: bigquant: derived_feature_extractor.v2 运行完成[9.039069s].
    [2018-04-04 14:04:59.620618] INFO: bigquant: join.v3 开始运行..
    [2018-04-04 14:05:03.374136] INFO: join: /y_2016, 行数=623849/641546, 耗时=3.555188s
    [2018-04-04 14:05:03.432584] INFO: join: 最终行数: 623849
    [2018-04-04 14:05:03.436494] INFO: bigquant: join.v3 运行完成[3.815882s].
    [2018-04-04 14:05:03.505259] INFO: bigquant: dropnan.v1 开始运行..
    [2018-04-04 14:05:04.862470] INFO: dropnan: /y_2016, 611111/623849
    [2018-04-04 14:05:04.876282] INFO: dropnan: 行数: 611111/623849
    [2018-04-04 14:05:04.910197] INFO: bigquant: dropnan.v1 运行完成[1.404946s].
    [2018-04-04 14:05:04.922139] INFO: bigquant: stock_ranker_train.v5 开始运行..
    [2018-04-04 14:05:06.144086] INFO: df2bin: prepare bins ..
    [2018-04-04 14:05:06.604982] INFO: df2bin: prepare data: training ..
    [2018-04-04 14:05:07.150810] INFO: df2bin: sort ..
    [2018-04-04 14:05:14.806478] INFO: stock_ranker_train: 1e7f8d12 准备训练: 611111 行数
    [2018-04-04 14:10:28.722553] INFO: bigquant: stock_ranker_train.v5 运行完成[323.800396s].
    [2018-04-04 14:10:28.731567] INFO: bigquant: instruments.v2 开始运行..
    [2018-04-04 14:10:28.736082] INFO: bigquant: 命中缓存
    [2018-04-04 14:10:28.737475] INFO: bigquant: instruments.v2 运行完成[0.005915s].
    [2018-04-04 14:10:28.749867] INFO: bigquant: general_feature_extractor.v6 开始运行..
    [2018-04-04 14:10:46.061846] INFO: 基础特征抽取: 年份 2017, 特征行数=743233
    [2018-04-04 14:10:50.218827] INFO: 基础特征抽取: 年份 2018, 特征行数=0
    [2018-04-04 14:10:50.232732] INFO: 基础特征抽取: 总行数: 743233
    [2018-04-04 14:10:50.235483] INFO: bigquant: general_feature_extractor.v6 运行完成[21.485649s].
    [2018-04-04 14:10:50.243218] INFO: bigquant: derived_feature_extractor.v2 开始运行..
    [2018-04-04 14:10:51.462134] INFO: derived_feature_extractor: 提取完成 amount_0/avg_amount_5, 0.003s
    [2018-04-04 14:10:51.466028] INFO: derived_feature_extractor: 提取完成 avg_turn_5/avg_turn_10, 0.003s
    [2018-04-04 14:10:51.469858] INFO: derived_feature_extractor: 提取完成 close_0/close_1, 0.003s
    [2018-04-04 14:10:54.062095] INFO: derived_feature_extractor: 提取完成 close_0/ts_max(close_0, 10), 2.591s
    [2018-04-04 14:10:54.066610] INFO: derived_feature_extractor: 提取完成 high_0/close_1, 0.003s
    [2018-04-04 14:10:54.070506] INFO: derived_feature_extractor: 提取完成 open_0/close_1, 0.003s
    [2018-04-04 14:10:54.254500] INFO: derived_feature_extractor: 提取完成 ta_sma_20_0/shift(ta_sma_20_0, 1), 0.183s
    [2018-04-04 14:10:59.428845] INFO: derived_feature_extractor: 提取完成 ts_max(close_0, 10)/ts_min(close_0, 10), 5.173s
    [2018-04-04 14:11:01.805367] INFO: derived_feature_extractor: /y_2017, 743233
    [2018-04-04 14:11:06.263844] INFO: bigquant: derived_feature_extractor.v2 运行完成[16.020585s].
    [2018-04-04 14:11:06.272399] INFO: bigquant: dropnan.v1 开始运行..
    [2018-04-04 14:11:07.217379] INFO: dropnan: /y_2017, 707341/743233
    [2018-04-04 14:11:07.229882] INFO: dropnan: 行数: 707341/743233
    [2018-04-04 14:11:07.258645] INFO: bigquant: dropnan.v1 运行完成[0.986229s].
    [2018-04-04 14:11:07.268962] INFO: bigquant: stock_ranker_predict.v5 开始运行..
    [2018-04-04 14:11:08.433525] INFO: df2bin: prepare data: prediction ..
    [2018-04-04 14:11:20.018056] INFO: stock_ranker_predict: 准备预测: 707341 行
    [2018-04-04 14:11:54.523726] INFO: bigquant: stock_ranker_predict.v5 运行完成[47.254743s].
    [2018-04-04 14:11:54.554792] INFO: bigquant: backtest.v7 开始运行..
    [2018-04-04 14:11:54.664223] INFO: algo: set price type:backward_adjusted
    [2018-04-04 14:12:25.869777] INFO: Performance: Simulated 244 trading days out of 244.
    [2018-04-04 14:12:25.871464] INFO: Performance: first open: 2017-01-03 01:30:00+00:00
    [2018-04-04 14:12:25.872827] INFO: Performance: last close: 2017-12-29 07:00:00+00:00
    
    • 收益率-48.45%
    • 年化收益率-49.56%
    • 基准收益率21.78%
    • 阿尔法-0.67
    • 贝塔0.7
    • 夏普比率-1.95
    • 胜率0.466
    • 盈亏比0.725
    • 收益波动率27.71%
    • 信息比率-2.68
    • 最大回撤52.63%
    [2018-04-04 14:12:27.758336] INFO: bigquant: backtest.v7 运行完成[33.203559s].
    

    (iQuant) #2

    首先,你如果是基于一定的规则选股,那么就是传统的量化策略,与直接把相关因子纳入AI模型是不一样的。
    标注语句如果是shift(close,-5)/shift(close,-1),表明用样本未来五日的收益率作为标注。具体的标注过程和细节你可以参考:数据标注。看了下你的标注结果,并没有很多是0的。
    如果你觉得选出的股票大多是过去五日涨幅较高的股票,那么你可以做一个统计,看看是否真的如此。

    如果对于标注,你有更多定制的一些需求,你可以参考:学院-自定义标注,通过代码的方式实现更灵活的标注。