为啥超级会员计算速度没变化

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

(luojinzh) #1
克隆策略

    {"Description":"实验创建于2019/12/22","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-141:options_data","SourceOutputPortId":"-113:predictions"},{"DestinationInputPortId":"-113:model","SourceOutputPortId":"-753:model"},{"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":"-6653: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":"-753:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-133: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":"-6653:input_data","SourceOutputPortId":"-106:data"},{"DestinationInputPortId":"-129:input_data","SourceOutputPortId":"-122:data"},{"DestinationInputPortId":"-414:input_data","SourceOutputPortId":"-129:data"},{"DestinationInputPortId":"-137:input_data","SourceOutputPortId":"-414:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-6653:data"},{"DestinationInputPortId":"-753:training_ds","SourceOutputPortId":"-133:data"},{"DestinationInputPortId":"-113:data","SourceOutputPortId":"-137:data"}],"ModuleNodes":[{"Id":"-113","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":"-113"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data","NodeId":"-113"}],"OutputPortsInternal":[{"Name":"predictions","NodeId":"-113","OutputType":null},{"Name":"m_lazy_run","NodeId":"-113","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-753","ModuleId":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v6","ModuleParameters":[{"Name":"learning_algorithm","Value":"排序","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_leaves","Value":"30","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"minimum_docs_per_leaf","Value":"1000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_trees","Value":"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":"data_row_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ndcg_discount_base","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-753"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-753"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-753"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"base_model","NodeId":"-753"}],"OutputPortsInternal":[{"Name":"model","NodeId":"-753","OutputType":null},{"Name":"feature_gains","NodeId":"-753","OutputType":null},{"Name":"m_lazy_run","NodeId":"-753","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"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":"2018-12-31","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":20,"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, -10) / 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\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":"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":21,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"open_0\nclose_0\nturn_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":22,"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":23,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2020-04-10","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":24,"IsPartOfPartialRun":null,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":true},{"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":"90","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":25,"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":"90","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":27,"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":28,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-414","ModuleId":"BigQuantSpace.chinaa_stock_filter.chinaa_stock_filter-v1","ModuleParameters":[{"Name":"index_constituent_cond","Value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E4%B8%8A%E8%AF%8150%22%2C%22displayValue%22%3A%22%E4%B8%8A%E8%AF%8150%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%B2%AA%E6%B7%B1300%22%2C%22displayValue%22%3A%22%E6%B2%AA%E6%B7%B1300%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%AD%E8%AF%81500%22%2C%22displayValue%22%3A%22%E4%B8%AD%E8%AF%81500%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%AD%E8%AF%81800%22%2C%22displayValue%22%3A%22%E4%B8%AD%E8%AF%81800%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%8A%E8%AF%81180%22%2C%22displayValue%22%3A%22%E4%B8%8A%E8%AF%81180%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%AD%E8%AF%81100%22%2C%22displayValue%22%3A%22%E4%B8%AD%E8%AF%81100%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%B7%B1%E8%AF%81100%22%2C%22displayValue%22%3A%22%E6%B7%B1%E8%AF%81100%22%2C%22selected%22%3Afalse%7D%5D%7D","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"board_cond","Value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%B8%8A%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22displayValue%22%3A%22%E4%B8%8A%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E6%B7%B1%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22displayValue%22%3A%22%E6%B7%B1%E8%AF%81%E4%B8%BB%E6%9D%BF%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%88%9B%E4%B8%9A%E6%9D%BF%22%2C%22displayValue%22%3A%22%E5%88%9B%E4%B8%9A%E6%9D%BF%22%2C%22selected%22%3Afalse%7D%5D%7D","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"industry_cond","Value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E4%BA%A4%E9%80%9A%E8%BF%90%E8%BE%93%22%2C%22displayValue%22%3A%22%E4%BA%A4%E9%80%9A%E8%BF%90%E8%BE%93%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%BC%91%E9%97%B2%E6%9C%8D%E5%8A%A1%22%2C%22displayValue%22%3A%22%E4%BC%91%E9%97%B2%E6%9C%8D%E5%8A%A1%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E4%BC%A0%E5%AA%92%2F%E4%BF%A1%E6%81%AF%E6%9C%8D%E5%8A%A1%22%2C%22displayValue%22%3A%22%E4%BC%A0%E5%AA%92%2F%E4%BF%A1%E6%81%AF%E6%9C%8D%E5%8A%A1%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%85%AC%E7%94%A8%E4%BA%8B%E4%B8%9A%22%2C%22displayValue%22%3A%22%E5%85%AC%E7%94%A8%E4%BA%8B%E4%B8%9A%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%86%9C%E6%9E%97%E7%89%A7%E6%B8%94%22%2C%22displayValue%22%3A%22%E5%86%9C%E6%9E%97%E7%89%A7%E6%B8%94%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%8C%96%E5%B7%A5%22%2C%22displayValue%22%3A%22%E5%8C%96%E5%B7%A5%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%8C%BB%E8%8D%AF%E7%94%9F%E7%89%A9%22%2C%22displayValue%22%3A%22%E5%8C%BB%E8%8D%AF%E7%94%9F%E7%89%A9%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%95%86%E4%B8%9A%E8%B4%B8%E6%98%93%22%2C%22displayValue%22%3A%22%E5%95%86%E4%B8%9A%E8%B4%B8%E6%98%93%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%9B%BD%E9%98%B2%E5%86%9B%E5%B7%A5%22%2C%22displayValue%22%3A%22%E5%9B%BD%E9%98%B2%E5%86%9B%E5%B7%A5%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%AE%B6%E7%94%A8%E7%94%B5%E5%99%A8%22%2C%22displayValue%22%3A%22%E5%AE%B6%E7%94%A8%E7%94%B5%E5%99%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%BB%BA%E7%AD%91%E6%9D%90%E6%96%99%2F%E5%BB%BA%E7%AD%91%E5%BB%BA%E6%9D%90%22%2C%22displayValue%22%3A%22%E5%BB%BA%E7%AD%91%E6%9D%90%E6%96%99%2F%E5%BB%BA%E7%AD%91%E5%BB%BA%E6%9D%90%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E5%BB%BA%E7%AD%91%E8%A3%85%E9%A5%B0%22%2C%22displayValue%22%3A%22%E5%BB%BA%E7%AD%91%E8%A3%85%E9%A5%B0%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%88%BF%E5%9C%B0%E4%BA%A7%22%2C%22displayValue%22%3A%22%E6%88%BF%E5%9C%B0%E4%BA%A7%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%9C%89%E8%89%B2%E9%87%91%E5%B1%9E%22%2C%22displayValue%22%3A%22%E6%9C%89%E8%89%B2%E9%87%91%E5%B1%9E%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%9C%BA%E6%A2%B0%E8%AE%BE%E5%A4%87%22%2C%22displayValue%22%3A%22%E6%9C%BA%E6%A2%B0%E8%AE%BE%E5%A4%87%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%B1%BD%E8%BD%A6%2F%E4%BA%A4%E8%BF%90%E8%AE%BE%E5%A4%87%22%2C%22displayValue%22%3A%22%E6%B1%BD%E8%BD%A6%2F%E4%BA%A4%E8%BF%90%E8%AE%BE%E5%A4%87%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%94%B5%E5%AD%90%22%2C%22displayValue%22%3A%22%E7%94%B5%E5%AD%90%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%94%B5%E6%B0%94%E8%AE%BE%E5%A4%87%22%2C%22displayValue%22%3A%22%E7%94%B5%E6%B0%94%E8%AE%BE%E5%A4%87%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%BA%BA%E7%BB%87%E6%9C%8D%E8%A3%85%22%2C%22displayValue%22%3A%22%E7%BA%BA%E7%BB%87%E6%9C%8D%E8%A3%85%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E7%BB%BC%E5%90%88%22%2C%22displayValue%22%3A%22%E7%BB%BC%E5%90%88%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E8%AE%A1%E7%AE%97%E6%9C%BA%22%2C%22displayValue%22%3A%22%E8%AE%A1%E7%AE%97%E6%9C%BA%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E8%BD%BB%E5%B7%A5%E5%88%B6%E9%80%A0%22%2C%22displayValue%22%3A%22%E8%BD%BB%E5%B7%A5%E5%88%B6%E9%80%A0%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%80%9A%E4%BF%A1%22%2C%22displayValue%22%3A%22%E9%80%9A%E4%BF%A1%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%87%87%E6%8E%98%22%2C%22displayValue%22%3A%22%E9%87%87%E6%8E%98%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%92%A2%E9%93%81%22%2C%22displayValue%22%3A%22%E9%92%A2%E9%93%81%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%93%B6%E8%A1%8C%22%2C%22displayValue%22%3A%22%E9%93%B6%E8%A1%8C%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%9D%9E%E9%93%B6%E9%87%91%E8%9E%8D%22%2C%22displayValue%22%3A%22%E9%9D%9E%E9%93%B6%E9%87%91%E8%9E%8D%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%A3%9F%E5%93%81%E9%A5%AE%E6%96%99%22%2C%22displayValue%22%3A%22%E9%A3%9F%E5%93%81%E9%A5%AE%E6%96%99%22%2C%22selected%22%3Afalse%7D%5D%7D","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"st_cond","Value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%AD%A3%E5%B8%B8%22%2C%22displayValue%22%3A%22%E6%AD%A3%E5%B8%B8%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22ST%22%2C%22displayValue%22%3A%22ST%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22*ST%22%2C%22displayValue%22%3A%22*ST%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E6%9A%82%E5%81%9C%E4%B8%8A%E5%B8%82%22%2C%22displayValue%22%3A%22%E6%9A%82%E5%81%9C%E4%B8%8A%E5%B8%82%22%2C%22selected%22%3Afalse%7D%5D%7D","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"delist_cond","Value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22displayValue%22%3A%22%E5%85%A8%E9%83%A8%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%80%80%E5%B8%82%22%2C%22displayValue%22%3A%22%E9%80%80%E5%B8%82%22%2C%22selected%22%3Afalse%7D%2C%7B%22value%22%3A%22%E9%9D%9E%E9%80%80%E5%B8%82%22%2C%22displayValue%22%3A%22%E9%9D%9E%E9%80%80%E5%B8%82%22%2C%22selected%22%3Atrue%7D%5D%7D","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_left_data","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-414"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-414","OutputType":null},{"Name":"left_data","NodeId":"-414","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":33,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-6653","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":"-6653"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-6653"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6653","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":26,"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 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 = 3\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.9\n context.options['hold_days'] = 2\n \n #------------------------计算确定买卖限值----------------------------\n #分位数95%以上的才买,62%以上的不卖\n dpre = context.ranker_prediction.score\n context.pre_buy = dpre.quantile(q=0.998)\n context.pre_sell = dpre.quantile(q=0.96)\n ","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n #------------------------START:加入下面if的两行代码到之前到主函数的最前部分-------------------\n # 相隔几天(以5天举例)运行一下handle_data函数\n # if context.trading_day_index % 2 != 0:\n # return \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 # 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 # 预测值大于某值时,虽然排在最后也不卖\n no_sell_instruments = ranker_prediction[ranker_prediction.score > context.pre_sell]\n no_sell_instruments = no_sell_instruments.instrument\n instruments = list(set(instruments) - (set(instruments) & set(no_sell_instruments)))\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 dd = ranker_prediction[:len(buy_cash_weights)]\n # 当预测值大于一定的数值才买\n buy_instruments = [x for x in dd.instrument if dd[dd.instrument.isin([x])].score.iloc[0] > context.pre_buy ]\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":"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":"200000","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":1,"IsPartOfPartialRun":null,"Comment":"不含zhisun","CommentCollapsed":false},{"Id":"-37","ModuleId":"BigQuantSpace.hyper_run.hyper_run-v1","ModuleParameters":[{"Name":"run","Value":"###该模块对策略进行循环运行,可以对因子进行加一个(Model=0)或减一个(Model=1)计算\n#加一个计算时,features1内放置基础因子,features内放置将要增加的因子\n#减一个计算时,features1不用,features内放置基本因子\n#-------------------------\n\ndef bigquant_run(bq_graph, inputs):\n g = bq_graph\n features = [\n'ts_argmin(low_0,10)',\n'in_csi800_0',\n'open_0/close_1',\n'in_csi500_0',\n'industry_sw_level1_0',\n'in_szse100_0',\n'beta_csi300_20_0',\n'rank_swing_volatility_20_0',\n'in_sse50_0',\n'swing_volatility_20_0',\n'in_sse180_0',\n'daily_return_20',\n'amount_1/amount_5',\n'daily_return_10',\n'daily_return_5',\n'ta_sma_10_0',\n'close_1/close_5',\n'daily_return_1',\n'ta_bbands_middleband_14_0',\n'ts_argmax(high_0,20)',\n'ta_mfi_14_0',\n'open_1',\n'ta_aroon_down_14_0',\n'ta_ema_10_0',\n'amount_20',\n'low_1',\n'mf_net_amount_s_0',\n'avg_amount_5',\n'high_1/high_5',\n'deal_number_20',\n'mean(low_0,10)',\n'mf_net_amount_l_0',\n'group_sum(industry_sw_level1_0,pb_lf_0)',\n'mean(abs(close_0-mean(close_0,6)),6)',\n'ta_wma_20_0',\n'turn_10',\n'ta_mom(return_0,30)',\n'high_1',\n'ta_aroon_down_28_0',\n ]\n \n###----------------------------------------------------------------------------------------------\n \n features1=[\n'avg_amount_20',\n'open_1/open_5',\n'ta_mom_10_0',\n'ta_macd_macdsignal_12_26_9_0',\n'ts_argmax(high_0,60)',\n'std(amount_0,5)',\n'ta_aroon_up_14_0',\n'industry_sw_level2_0',\n'turn_0',\n'fs_financial_expenses_0',\n'ts_min(low_0,10)/low_0',\n'in_csi100_0',\n'ts_min(low_0,5)',\n'mf_net_amount_xl_0',\n'return_10/return_0',\n'rank_beta_sse180_5_0',\n'fs_bps_0',\n'close_1',\n'turn_5',\n'mean(close_0,10)',\n'fs_income_tax_0',\n'rank_market_cap_float_0',\n'fs_total_equity_0',\n'swing_volatility_5_0',\n 'ts_min(low_0,10)',\n 'rank_fs_operating_revenue_qoq_0',\n 'beta_csi300_5_0',\n 'amount_10',\n 'beta_gem_20_0',\n]\n\n\n Model = 0 #增加参数运算为0,减少参数运算为1\n parameters_list = []\n\n###-----增减参数运算\n for feature in features: \n parameters = {}\n temp = []\n if Model == 0:\n temp = features1.copy()\n temp.append(feature)\n temp = list(set(temp))\n else:\n temp = list(set(features) - set([feature]))\n parameters['m22.features'] = '\\n'.join(temp)\n parameters_list.append({'parameters': parameters})\n###------------------\n \n #print( parameters_list)\n \n def run(parameters):\n try:\n print(parameters)\n result = g.run(parameters)\n return result\n except Exception as e:\n print('ERROR --------', e)\n return None\n results = T.parallel_map(run, parameters_list, max_workers=4, remote_run=False,silent=True)\n \n return results\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"run_now","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"bq_graph","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"bq_graph_port","NodeId":"-37"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-37"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-37"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-37"}],"OutputPortsInternal":[{"Name":"result","NodeId":"-37","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"增减因子循环计算","CommentCollapsed":false},{"Id":"-133","ModuleId":"BigQuantSpace.dropnan.dropnan-v2","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-133"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-133"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-133","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-137","ModuleId":"BigQuantSpace.dropnan.dropnan-v2","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-137"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-137"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-137","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"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='-113' Position='488,764,200,200'/><NodePosition Node='-753' Position='327,651,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='139,13,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='116,222,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='581,-17,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='216,405,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1033,102,200,200'/><NodePosition Node='-106' Position='417,194,200,200'/><NodePosition Node='-122' Position='1006,271,200,200'/><NodePosition Node='-129' Position='1004,352,200,200'/><NodePosition Node='-414' Position='1003,442,200,200'/><NodePosition Node='-6653' Position='422,267,200,200'/><NodePosition Node='-141' Position='651,884,200,200'/><NodePosition Node='-37' Position='967,-15,200,200'/><NodePosition Node='-133' Position='219,511,200,200'/><NodePosition Node='-137' Position='950,524,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 [ ]:
    # 本代码由可视化策略环境自动生成 2020年8月5日 10:07
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m1_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 = 3
        # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[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.9
        context.options['hold_days'] = 2
        
        #------------------------计算确定买卖限值----------------------------
        #分位数95%以上的才买,62%以上的不卖
        dpre = context.ranker_prediction.score
        context.pre_buy = dpre.quantile(q=0.998)
        context.pre_sell = dpre.quantile(q=0.96)
        
    # 回测引擎:每日数据处理函数,每天执行一次
    def m1_handle_data_bigquant_run(context, data):
         #------------------------START:加入下面if的两行代码到之前到主函数的最前部分-------------------
        # 相隔几天(以5天举例)运行一下handle_data函数
        # if context.trading_day_index % 2 != 0:
        #    return 
        #------------------------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()}
    
        # 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]))])))
            # 预测值大于某值时,虽然排在最后也不卖
            no_sell_instruments = ranker_prediction[ranker_prediction.score > context.pre_sell]
            no_sell_instruments = no_sell_instruments.instrument
            instruments = list(set(instruments) - (set(instruments) & set(no_sell_instruments)))
            # 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)])
        dd = ranker_prediction[:len(buy_cash_weights)]
        # 当预测值大于一定的数值才买
        buy_instruments = [x for x in dd.instrument if dd[dd.instrument.isin([x])].score.iloc[0] > context.pre_buy ]
        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 m1_prepare_bigquant_run(context):
        pass
    
    
    g = T.Graph({
    
        'm20': 'M.instruments.v2',
        'm20.start_date': '2015-01-01',
        'm20.end_date': '2018-12-31',
        'm20.market': 'CN_STOCK_A',
        'm20.instrument_list': '',
        'm20.max_count': 0,
    
        'm21': 'M.advanced_auto_labeler.v2',
        'm21.instruments': T.Graph.OutputPort('m20.data'),
        'm21.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, -10) / 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)
    """,
        'm21.start_date': '',
        'm21.end_date': '',
        'm21.benchmark': '000300.SHA',
        'm21.drop_na_label': True,
        'm21.cast_label_int': False,
    
        'm22': 'M.input_features.v1',
        'm22.features': """open_0
    close_0
    turn_0""",
    
        'm25': 'M.general_feature_extractor.v7',
        'm25.instruments': T.Graph.OutputPort('m20.data'),
        'm25.features': T.Graph.OutputPort('m22.data'),
        'm25.start_date': '',
        'm25.end_date': '',
        'm25.before_start_days': 90,
    
        'm26': 'M.derived_feature_extractor.v3',
        'm26.input_data': T.Graph.OutputPort('m25.data'),
        'm26.features': T.Graph.OutputPort('m22.data'),
        'm26.date_col': 'date',
        'm26.instrument_col': 'instrument',
        'm26.drop_na': True,
        'm26.remove_extra_columns': False,
    
        'm23': 'M.join.v3',
        'm23.data1': T.Graph.OutputPort('m21.data'),
        'm23.data2': T.Graph.OutputPort('m26.data'),
        'm23.on': 'date,instrument',
        'm23.how': 'inner',
        'm23.sort': False,
    
        'm3': 'M.dropnan.v2',
        'm3.input_data': T.Graph.OutputPort('m23.data'),
    
        'm17': 'M.stock_ranker_train.v6',
        'm17.training_ds': T.Graph.OutputPort('m3.data'),
        'm17.features': T.Graph.OutputPort('m22.data'),
        'm17.learning_algorithm': '排序',
        'm17.number_of_leaves': 30,
        'm17.minimum_docs_per_leaf': 1000,
        'm17.number_of_trees': 20,
        'm17.learning_rate': 0.1,
        'm17.max_bins': 1023,
        'm17.feature_fraction': 1,
        'm17.data_row_fraction': 1,
        'm17.ndcg_discount_base': 1,
        'm17.m_lazy_run': False,
    
        'm24': 'M.instruments.v2',
        'm24.start_date': T.live_run_param('trading_date', '2019-01-01'),
        'm24.end_date': T.live_run_param('trading_date', '2020-04-10'),
        'm24.market': 'CN_STOCK_A',
        'm24.instrument_list': '',
        'm24.max_count': 0,
    
        'm27': 'M.general_feature_extractor.v7',
        'm27.instruments': T.Graph.OutputPort('m24.data'),
        'm27.features': T.Graph.OutputPort('m22.data'),
        'm27.start_date': '',
        'm27.end_date': '',
        'm27.before_start_days': 90,
    
        'm28': 'M.derived_feature_extractor.v3',
        'm28.input_data': T.Graph.OutputPort('m27.data'),
        'm28.features': T.Graph.OutputPort('m22.data'),
        'm28.date_col': 'date',
        'm28.instrument_col': 'instrument',
        'm28.drop_na': True,
        'm28.remove_extra_columns': False,
    
        'm33': 'M.chinaa_stock_filter.v1',
        'm33.input_data': T.Graph.OutputPort('m28.data'),
        'm33.index_constituent_cond': ['全部'],
        'm33.board_cond': ['上证主板', '深证主板'],
        'm33.industry_cond': ['全部'],
        'm33.st_cond': ['正常'],
        'm33.delist_cond': ['非退市'],
        'm33.output_left_data': False,
    
        'm4': 'M.dropnan.v2',
        'm4.input_data': T.Graph.OutputPort('m33.data'),
    
        'm13': 'M.stock_ranker_predict.v5',
        'm13.model': T.Graph.OutputPort('m17.model'),
        'm13.data': T.Graph.OutputPort('m4.data'),
        'm13.m_lazy_run': False,
    
        'm1': 'M.trade.v4',
        'm1.instruments': T.Graph.OutputPort('m24.data'),
        'm1.options_data': T.Graph.OutputPort('m13.predictions'),
        'm1.start_date': '',
        'm1.end_date': '',
        'm1.initialize': m1_initialize_bigquant_run,
        'm1.handle_data': m1_handle_data_bigquant_run,
        'm1.prepare': m1_prepare_bigquant_run,
        'm1.volume_limit': 0.025,
        'm1.order_price_field_buy': 'open',
        'm1.order_price_field_sell': 'close',
        'm1.capital_base': 200000,
        'm1.auto_cancel_non_tradable_orders': True,
        'm1.data_frequency': 'daily',
        'm1.price_type': '真实价格',
        'm1.product_type': '股票',
        'm1.plot_charts': True,
        'm1.backtest_only': False,
        'm1.benchmark': '000300.SHA',
    })
    
    # g.run({})
    
    
    ###该模块对策略进行循环运行,可以对因子进行加一个(Model=0)或减一个(Model=1)计算
    #加一个计算时,features1内放置基础因子,features内放置将要增加的因子
    #减一个计算时,features1不用,features内放置基本因子
    #-------------------------
    
    def m2_run_bigquant_run(bq_graph, inputs):
        g = bq_graph
        features = [
    'ts_argmin(low_0,10)',
    'in_csi800_0',
    'open_0/close_1',
    'in_csi500_0',
    'industry_sw_level1_0',
    'in_szse100_0',
    'beta_csi300_20_0',
    'rank_swing_volatility_20_0',
    'in_sse50_0',
    'swing_volatility_20_0',
    'in_sse180_0',
    'daily_return_20',
    'amount_1/amount_5',
    'daily_return_10',
    'daily_return_5',
    'ta_sma_10_0',
    'close_1/close_5',
    'daily_return_1',
    'ta_bbands_middleband_14_0',
    'ts_argmax(high_0,20)',
    'ta_mfi_14_0',
    'open_1',
    'ta_aroon_down_14_0',
    'ta_ema_10_0',
    'amount_20',
    'low_1',
    'mf_net_amount_s_0',
    'avg_amount_5',
    'high_1/high_5',
    'deal_number_20',
    'mean(low_0,10)',
    'mf_net_amount_l_0',
    'group_sum(industry_sw_level1_0,pb_lf_0)',
    'mean(abs(close_0-mean(close_0,6)),6)',
    'ta_wma_20_0',
    'turn_10',
    'ta_mom(return_0,30)',
    'high_1',
    'ta_aroon_down_28_0',
        ]
            
    ###----------------------------------------------------------------------------------------------
        
        features1=[
    'avg_amount_20',
    'open_1/open_5',
    'ta_mom_10_0',
    'ta_macd_macdsignal_12_26_9_0',
    'ts_argmax(high_0,60)',
    'std(amount_0,5)',
    'ta_aroon_up_14_0',
    'industry_sw_level2_0',
    'turn_0',
    'fs_financial_expenses_0',
    'ts_min(low_0,10)/low_0',
    'in_csi100_0',
    'ts_min(low_0,5)',
    'mf_net_amount_xl_0',
    'return_10/return_0',
    'rank_beta_sse180_5_0',
    'fs_bps_0',
    'close_1',
    'turn_5',
    'mean(close_0,10)',
    'fs_income_tax_0',
    'rank_market_cap_float_0',
    'fs_total_equity_0',
    'swing_volatility_5_0',
            'ts_min(low_0,10)',
            'rank_fs_operating_revenue_qoq_0',
            'beta_csi300_5_0',
            'amount_10',
            'beta_gem_20_0',
    ]
    
    
        Model = 0   #增加参数运算为0,减少参数运算为1
        parameters_list = []
    
    ###-----增减参数运算
        for feature in features: 
            parameters = {}
            temp = []
            if Model == 0:
                temp = features1.copy()
                temp.append(feature)
                temp = list(set(temp))
            else:
                temp = list(set(features) - set([feature]))
            parameters['m22.features'] = '\n'.join(temp)
            parameters_list.append({'parameters': parameters})
    ###------------------
      
        #print( parameters_list)
        
        def run(parameters):
            try:
                print(parameters)
                result = g.run(parameters)
                return result
            except Exception as e:
                print('ERROR --------', e)
                return None
        results = T.parallel_map(run, parameters_list, max_workers=4, remote_run=False,silent=True)
        
        return results
    
    
    m2 = M.hyper_run.v1(
        run=m2_run_bigquant_run,
        run_now=True,
        bq_graph=g
    )
    
    [Parallel(n_jobs=4)]: Using backend LokyBackend with 4 concurrent workers.
    [Parallel(n_jobs=4)]: Done   1 tasks      | elapsed: 10.6min
    [Parallel(n_jobs=4)]: Done   2 tasks      | elapsed: 10.8min
    [Parallel(n_jobs=4)]: Done   3 tasks      | elapsed: 12.3min
    [Parallel(n_jobs=4)]: Done   4 tasks      | elapsed: 13.8min
    [Parallel(n_jobs=4)]: Done   5 tasks      | elapsed: 20.6min
    [Parallel(n_jobs=4)]: Done   6 tasks      | elapsed: 23.0min
    [Parallel(n_jobs=4)]: Done   7 tasks      | elapsed: 24.2min
    [Parallel(n_jobs=4)]: Done   8 tasks      | elapsed: 24.3min
    
    In [ ]:
    m2.result[11]['m1'].display()
    
    In [ ]:
    #m2.result[-3]['m1'].raw_perf.read_df().tail()#columns.values
    days=(pd.to_datetime("2020-04-10")-pd.to_datetime("2019-01-01"))
    d=(days.days-17.447)/365
    y=(1+0.8418)**(1/d)-1
    print(d,y)
    
    In [ ]:
    #m2.result[0]['m1'].display()
    for n in range(0,len(m2.result)):
        try:
            tol_sy = m2.result[n]['m1'].raw_perf.read_df()['algorithm_period_return'][-1]
        except:
            tol_sy =0
        year_sy = 100*((1+tol_sy)**(1/d) -1)
        print(year_sy)
    
    In [ ]:
     
    

    (iQuant) #2

    开通超级会员后需重启策略开发环境后,资源自动生效,您可以尝试一下。


    (bigrzz) #4

    超级会员可以通过增加并行任务数来减少整个画布运行时间,在remote_run=False即使用网站分配资源进行并行计算,超级会员可以启动6个并行任务,能明显缩短整个策略的运行时间


    (zzzdtz) #5

    借楼问一下,自定义运行开启remote_run=False后,m2.result[11][‘m1’].display() 无法显示运行结果,remote_run的运行结果要怎么获取?