把两个策略合并成一个出错,求助。

策略分享
新手专区
标签: #<Tag:0x00007fc070d5f010> #<Tag:0x00007fc070d5eea8>

(tkyz) #1

出错,还有我想加入滚动训练可以同时滚动训练两个模块吗?还有我想把预测结果合并,选出的股既符合策略一又符合策略二,同时满足两个策略预测结果。

克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-351: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":"-171:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-175:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:model"},{"DestinationInputPortId":"-1348:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-595:input_1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"-365:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-382:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62: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"},{"DestinationInputPortId":"-459:training_ds","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-358:features","SourceOutputPortId":"-351:data"},{"DestinationInputPortId":"-9001:input_data","SourceOutputPortId":"-358:data"},{"DestinationInputPortId":"-372:features","SourceOutputPortId":"-365:data"},{"DestinationInputPortId":"-9453:features","SourceOutputPortId":"-372:data"},{"DestinationInputPortId":"-8132:features_ds","SourceOutputPortId":"-506:data"},{"DestinationInputPortId":"-11798:features_ds","SourceOutputPortId":"-506:data"},{"DestinationInputPortId":"-555:data2","SourceOutputPortId":"-518:data"},{"DestinationInputPortId":"-365:features","SourceOutputPortId":"-532:data_1"},{"DestinationInputPortId":"-9916:features","SourceOutputPortId":"-548:data"},{"DestinationInputPortId":"-12301:input_data","SourceOutputPortId":"-555:data"},{"DestinationInputPortId":"-459:model","SourceOutputPortId":"-561:data"},{"DestinationInputPortId":"-382:options_data","SourceOutputPortId":"-595:data_1"},{"DestinationInputPortId":"-518:instruments","SourceOutputPortId":"-510:data"},{"DestinationInputPortId":"-13369:features","SourceOutputPortId":"-510:data"},{"DestinationInputPortId":"-532:input_1","SourceOutputPortId":"-171:data"},{"DestinationInputPortId":"-351:features","SourceOutputPortId":"-171:data"},{"DestinationInputPortId":"-532:input_2","SourceOutputPortId":"-8132:data"},{"DestinationInputPortId":"-13369:instruments","SourceOutputPortId":"-8132:data"},{"DestinationInputPortId":"-9932:input_1","SourceOutputPortId":"-45:data"},{"DestinationInputPortId":"-358:input_data","SourceOutputPortId":"-45:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-9001:data"},{"DestinationInputPortId":"-9001:features","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-10806:input_1","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-12892:input_data","SourceOutputPortId":"-9453:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:features","SourceOutputPortId":"-175:data"},{"DestinationInputPortId":"-555:data1","SourceOutputPortId":"-9916:data"},{"DestinationInputPortId":"-548:features","SourceOutputPortId":"-9924:data"},{"DestinationInputPortId":"-9932:input_2","SourceOutputPortId":"-9924:data"},{"DestinationInputPortId":"-372:input_data","SourceOutputPortId":"-9932:data_1"},{"DestinationInputPortId":"-9453:input_data","SourceOutputPortId":"-10806:data_1"},{"DestinationInputPortId":"-10806:input_2","SourceOutputPortId":"-10814:data"},{"DestinationInputPortId":"-9916:input_data","SourceOutputPortId":"-10814:data"},{"DestinationInputPortId":"-459:features","SourceOutputPortId":"-11798:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"-1348:data"},{"DestinationInputPortId":"-561:input_data","SourceOutputPortId":"-12301:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-12892:data"},{"DestinationInputPortId":"-548:input_data","SourceOutputPortId":"-13369:data"},{"DestinationInputPortId":"-595:input_2","SourceOutputPortId":"-459:output_model"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-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, -2) / 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# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_0\nreturn_4\nreturn_5","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-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":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2017-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-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-86","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-86"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-86","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-351","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-351"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-351"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-351","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-358","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":"-358"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-358"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-358","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-365","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-365"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-365"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-365","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-372","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":"-372"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-372"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-372","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-382","ModuleId":"BigQuantSpace.trade.trade-v4","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 # 获取今日的日期\n today = data.current_dt.strftime('%Y-%m-%d') \n \n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions ] \n \n # 按日期过滤得到今日的预测数据,和买入备选股票列表\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n stock_to_buy = list(ranker_prediction.instrument)\n \n # 需要卖出的股票:已有持仓中不在买入列表的股票\n stock_to_sell = [ i for i in stock_hold_now if i not in stock_to_buy]\n \n # 生成卖出订单:\n if len(stock_to_sell)>0:\n for instrument in stock_to_sell:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n cur_position = context.portfolio.positions[sid].amount # 持仓\n if cur_position > 0 and data.can_trade(sid):\n context.order_target_percent(sid, 0) # 全部卖出 \n \n \n # 生成买入订单:买入每天两个策略前两名的股票\n if len(stock_to_buy)>0:\n if len(stock_to_buy)>0:\n weight = 1/4 # 每只股票的比重为等资金比例持有1/4仓位\n for instrument in stock_to_buy:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n if data.can_trade(sid):\n context.order_target_percent(sid, weight) # 买入\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 = 4\n # 每只的股票等资金分配\n context.stock_weights = [1/stock_count for i in range(4)]\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":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"后复权","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-382"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-382","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":19,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-506","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_0\nreturn_4\nreturn_5","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-506"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-506","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-518","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nwhere(shift(close, -2) / shift(open, -1)-1>0.01, 1, 0)\n\n# 极值处理:用1%和99%分位的值做clip\n#clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\n#all_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":"-518"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-518","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-532","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-532"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-532"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-532"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-532","OutputType":null},{"Name":"data_2","NodeId":"-532","OutputType":null},{"Name":"data_3","NodeId":"-532","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-548","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":"-548"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-548"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-548","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":20,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-555","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":"-555"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-555"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-555","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":21,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-561","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-561"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-561","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":22,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-595","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 df1=input_1.read_df()\n df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)\n df2=input_2.read_df()\n df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)\n df=pd.concat([df1_filter,df2_filter]).sort_values(['date','position'])\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1, 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":"-595"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-595"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-595"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-595","OutputType":null},{"Name":"data_2","NodeId":"-595","OutputType":null},{"Name":"data_3","NodeId":"-595","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":25,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-510","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-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":"-510"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-510","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-171","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nst_status_0\nreturn_90\nreturn_10\nreturn_80\nreturn_0\nhigh_0\nlow_0\nclose_0\nopen_0\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-171"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-171","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":26,"IsPartOfPartialRun":null,"Comment":"辅助计算的因子,不参与训练","CommentCollapsed":false},{"Id":"-8132","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nst_status_0\nreturn_90\nreturn_10\nreturn_80\nhigh_0\nlow_0\nclose_0\nopen_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-8132"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-8132","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":27,"IsPartOfPartialRun":null,"Comment":"辅助计算的因子,不参与训练","CommentCollapsed":false},{"Id":"-45","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmid=mean(close_0,14)\natr=ta_atr(high_0, low_0, close_0, 14)\nret1=return_90/return_10\nret2=return_80/return_10\nret3=return_5/return_0\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-45"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-45","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":28,"IsPartOfPartialRun":null,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9001","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":"-9001"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9001"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9001","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":29,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-32","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ncond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-32"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-32","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":30,"IsPartOfPartialRun":null,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9453","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":"-9453"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9453"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9453","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":31,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-175","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# 输入参与训练的自定义列\n\nret1\nret2\nret3\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-175"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-175","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":32,"IsPartOfPartialRun":null,"Comment":"自定义的因子,也参与模型训练","CommentCollapsed":true},{"Id":"-9916","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":"-9916"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9916"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9916","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":33,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-9924","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmid=mean(close_0,14)\natr=ta_atr(high_0, low_0, close_0, 14)\nret1=return_90/return_10\nret2=return_80/return_10\nret3=return_5/return_0\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-9924"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9924","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":34,"IsPartOfPartialRun":null,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9932","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-9932"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-9932"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-9932"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-9932","OutputType":null},{"Name":"data_2","NodeId":"-9932","OutputType":null},{"Name":"data_3","NodeId":"-9932","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":35,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-10806","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-10806"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-10806"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-10806"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-10806","OutputType":null},{"Name":"data_2","NodeId":"-10806","OutputType":null},{"Name":"data_3","NodeId":"-10806","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":36,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-10814","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ncond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-10814"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-10814","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":37,"IsPartOfPartialRun":null,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-11798","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# 输入参与训练的自定义列\n\nret1\nret2\nret3\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-11798"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-11798","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":38,"IsPartOfPartialRun":null,"Comment":"自定义的因子,也参与模型训练","CommentCollapsed":true},{"Id":"-1348","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-1348"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1348","OutputType":null},{"Name":"left_data","NodeId":"-1348","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":39,"IsPartOfPartialRun":null,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-12301","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-12301"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12301","OutputType":null},{"Name":"left_data","NodeId":"-12301","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":40,"IsPartOfPartialRun":null,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-12892","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-12892"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12892","OutputType":null},{"Name":"left_data","NodeId":"-12892","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":41,"IsPartOfPartialRun":null,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-13369","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-13369"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-13369"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-13369","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":42,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-459","ModuleId":"BigQuantSpace.random_forest_classifier.random_forest_classifier-v1","ModuleParameters":[{"Name":"iterations","Value":10,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_depth","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"min_samples_per_leaf","Value":200,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"key_cols","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"workers","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"other_train_parameters","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"predict_ds","NodeId":"-459"}],"OutputPortsInternal":[{"Name":"output_model","NodeId":"-459","OutputType":null},{"Name":"predictions","NodeId":"-459","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":12,"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='43,-185,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='38,-93,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='287,-313,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-43' Position='227,681,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='95,366,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='395,801,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='764,290,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='95,548,200,200'/><NodePosition Node='-86' Position='785,753,200,200'/><NodePosition Node='-351' Position='409,-99,200,200'/><NodePosition Node='-358' Position='100,155,200,200'/><NodePosition Node='-365' Position='776,412,200,200'/><NodePosition Node='-372' Position='779,507,200,200'/><NodePosition Node='-382' Position='716,984,200,200'/><NodePosition Node='-506' Position='1311,-320,200,200'/><NodePosition Node='-518' Position='1545,-102,200,200'/><NodePosition Node='-532' Position='778,-40,200,200'/><NodePosition Node='-548' Position='1454,163,200,200'/><NodePosition Node='-555' Position='1463,374,200,200'/><NodePosition Node='-561' Position='1466,568,200,200'/><NodePosition Node='-595' Position='780,883,200,200'/><NodePosition Node='-510' Position='1543,-193,200,200'/><NodePosition Node='-171' Position='546,-217,200,200'/><NodePosition Node='-8132' Position='1056,-219,200,200'/><NodePosition Node='-45' Position='413,-2,200,200'/><NodePosition Node='-9001' Position='107,260,200,200'/><NodePosition Node='-32' Position='414,114,200,200'/><NodePosition Node='-9453' Position='779,591,200,200'/><NodePosition Node='-175' Position='387,405,200,200'/><NodePosition Node='-9916' Position='1462,272,200,200'/><NodePosition Node='-9924' Position='1159,-13,200,200'/><NodePosition Node='-9932' Position='775,53,200,200'/><NodePosition Node='-10806' Position='779,168,200,200'/><NodePosition Node='-10814' Position='1157,108,200,200'/><NodePosition Node='-11798' Position='1158,425,200,200'/><NodePosition Node='-1348' Position='99,455,200,200'/><NodePosition Node='-12301' Position='1458,472,200,200'/><NodePosition Node='-12892' Position='776,670,200,200'/><NodePosition Node='-13369' Position='1157,-99,200,200'/><NodePosition Node='-459' Position='1196,797,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 [29]:
    # 本代码由可视化策略环境自动生成 2019年1月29日 12:48
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m11_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        f1 = input_1.read_pickle()
        f2 = input_2.read_pickle()
        factors = [ k for k in set(f1 + f2)]
        data_1 = DataSource.write_pickle(factors)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m11_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m35_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        f1 = input_1.read_pickle()
        f2 = input_2.read_pickle()
        factors = [ k for k in set(f1 + f2)]
        data_1 = DataSource.write_pickle(factors)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m35_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m36_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        f1 = input_1.read_pickle()
        f2 = input_2.read_pickle()
        factors = [ k for k in set(f1 + f2)]
        data_1 = DataSource.write_pickle(factors)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m36_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m25_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df1=input_1.read_df()
        df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)
        df2=input_2.read_df()
        df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)
        df=pd.concat([df1_filter,df2_filter]).sort_values(['date','position'])
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m25_post_run_bigquant_run(outputs):
        return outputs
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m19_handle_data_bigquant_run(context, data):
    
        # 获取今日的日期
        today = data.current_dt.strftime('%Y-%m-%d')  
        
        # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
        stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]      
        
        # 按日期过滤得到今日的预测数据,和买入备选股票列表
        ranker_prediction = context.ranker_prediction[
            context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
        stock_to_buy = list(ranker_prediction.instrument)
        
        # 需要卖出的股票:已有持仓中不在买入列表的股票
        stock_to_sell = [ i for i in stock_hold_now if i not in stock_to_buy]
        
        # 生成卖出订单:
        if len(stock_to_sell)>0:
            for instrument in stock_to_sell:
                sid = context.symbol(instrument) # 将标的转化为equity格式
                cur_position = context.portfolio.positions[sid].amount # 持仓
                if cur_position > 0 and data.can_trade(sid):
                    context.order_target_percent(sid, 0) # 全部卖出   
        
        
        # 生成买入订单:买入每天两个策略前两名的股票
        if len(stock_to_buy)>0:
            if len(stock_to_buy)>0:
                weight = 1/4 # 每只股票的比重为等资金比例持有1/4仓位
                for instrument in stock_to_buy:
                    sid = context.symbol(instrument) # 将标的转化为equity格式
                    if  data.can_trade(sid):
                        context.order_target_percent(sid, weight) # 买入
    
    # 回测引擎:准备数据,只执行一次
    def m19_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:初始化函数,只执行一次
    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
        # 每只的股票等资金分配
        context.stock_weights = [1/stock_count for i in range(4)]
    
    
    m1 = M.instruments.v2(
        start_date='2010-01-01',
        end_date='2015-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, -2) / 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="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    return_0
    return_4
    return_5"""
    )
    
    m26 = M.input_features.v1(
        features_ds=m3.data,
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    st_status_0
    return_90
    return_10
    return_80
    return_0
    high_0
    low_0
    close_0
    open_0
    
    
    """
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m26.data,
        start_date='',
        end_date=''
    )
    
    m32 = M.input_features.v1(
        features_ds=m3.data,
        features="""
    # 输入参与训练的自定义列
    
    ret1
    ret2
    ret3
    """
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2015-01-01'),
        end_date=T.live_run_param('trading_date', '2017-01-01'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m4 = M.input_features.v1(
        features="""
    # #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    return_0
    return_4
    return_5"""
    )
    
    m27 = M.input_features.v1(
        features_ds=m4.data,
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    st_status_0
    return_90
    return_10
    return_80
    high_0
    low_0
    close_0
    open_0"""
    )
    
    m11 = M.cached.v3(
        input_1=m26.data,
        input_2=m27.data,
        run=m11_run_bigquant_run,
        post_run=m11_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m17 = M.general_feature_extractor.v7(
        instruments=m9.data,
        features=m11.data_1,
        start_date='',
        end_date=''
    )
    
    m38 = M.input_features.v1(
        features_ds=m4.data,
        features="""
    # 输入参与训练的自定义列
    
    ret1
    ret2
    ret3
    """
    )
    
    m5 = M.instruments.v2(
        start_date='2010-01-01',
        end_date='2015-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m10 = M.advanced_auto_labeler.v2(
        instruments=m5.data,
        label_expr="""
    
    # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    where(shift(close, -2) / shift(open, -1)-1>0.01, 1, 0)
    
    # 极值处理:用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,
        user_functions={}
    )
    
    m42 = M.general_feature_extractor.v7(
        instruments=m27.data,
        features=m5.data,
        start_date='',
        end_date=''
    )
    
    m28 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    mid=mean(close_0,14)
    atr=ta_atr(high_0, low_0, close_0, 14)
    ret1=return_90/return_10
    ret2=return_80/return_10
    ret3=return_5/return_0
    
    """
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m28.data,
        features=m15.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False
    )
    
    m30 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    cond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))
    """
    )
    
    m29 = M.derived_feature_extractor.v3(
        input_data=m16.data,
        features=m30.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False
    )
    
    m7 = M.join.v3(
        data1=m2.data,
        data2=m29.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m39 = M.filter.v3(
        input_data=m7.data,
        expr='st_status_0 == 0 and cond2>0',
        output_left_data=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m39.data
    )
    
    m6 = M.stock_ranker_train.v5(
        training_ds=m13.data,
        features=m32.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
    )
    
    m34 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    mid=mean(close_0,14)
    atr=ta_atr(high_0, low_0, close_0, 14)
    ret1=return_90/return_10
    ret2=return_80/return_10
    ret3=return_5/return_0
    
    """
    )
    
    m20 = M.derived_feature_extractor.v3(
        input_data=m42.data,
        features=m34.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m35 = M.cached.v3(
        input_1=m28.data,
        input_2=m34.data,
        run=m35_run_bigquant_run,
        post_run=m35_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m18 = M.derived_feature_extractor.v3(
        input_data=m35.data_1,
        features=m17.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False
    )
    
    m37 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    cond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))
    
    
    """
    )
    
    m36 = M.cached.v3(
        input_1=m30.data,
        input_2=m37.data,
        run=m36_run_bigquant_run,
        post_run=m36_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m31 = M.derived_feature_extractor.v3(
        input_data=m36.data_1,
        features=m18.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False
    )
    
    m41 = M.filter.v3(
        input_data=m31.data,
        expr='st_status_0 == 0 and cond2>0',
        output_left_data=False
    )
    
    m14 = M.dropnan.v1(
        input_data=m41.data
    )
    
    m8 = M.stock_ranker_predict.v5(
        model=m6.model,
        data=m14.data,
        m_lazy_run=False
    )
    
    m33 = M.derived_feature_extractor.v3(
        input_data=m37.data,
        features=m20.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=False
    )
    
    m21 = M.join.v3(
        data1=m33.data,
        data2=m10.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m40 = M.filter.v3(
        input_data=m21.data,
        expr='st_status_0 == 0 and cond2>0',
        output_left_data=False
    )
    
    m22 = M.dropnan.v1(
        input_data=m40.data
    )
    
    m12 = M.random_forest_classifier.v1(
        training_ds=m14.data,
        features=m38.data,
        model=m22.data,
        iterations=10,
        feature_fraction=1,
        max_depth=30,
        min_samples_per_leaf=200,
        key_cols='date,instrument',
        workers=1,
        other_train_parameters={}
    )
    
    m25 = M.cached.v3(
        input_1=m8.predictions,
        input_2=m12.output_model,
        run=m25_run_bigquant_run,
        post_run=m25_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m19 = M.trade.v4(
        instruments=m9.data,
        options_data=m25.data_1,
        start_date='',
        end_date='',
        handle_data=m19_handle_data_bigquant_run,
        prepare=m19_prepare_bigquant_run,
        initialize=m19_initialize_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=1000000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='后复权',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark=''
    )
    
    [2019-01-29 12:43:10.874421] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-29 12:43:10.880720] INFO: bigquant: 命中缓存
    [2019-01-29 12:43:10.881945] INFO: bigquant: instruments.v2 运行完成[0.007538s].
    [2019-01-29 12:43:10.884847] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
    [2019-01-29 12:43:10.890903] INFO: bigquant: 命中缓存
    [2019-01-29 12:43:10.892167] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.007317s].
    [2019-01-29 12:43:10.894720] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-29 12:43:10.901934] INFO: bigquant: input_features.v1 运行完成[0.007196s].
    [2019-01-29 12:43:10.904315] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-29 12:43:10.912704] INFO: bigquant: input_features.v1 运行完成[0.008387s].
    [2019-01-29 12:43:10.917691] INFO: bigquant: general_feature_extractor.v7 开始运行..
    [2019-01-29 12:43:33.741295] INFO: 基础特征抽取: 年份 2009, 特征行数=95020
    [2019-01-29 12:44:03.498392] INFO: 基础特征抽取: 年份 2010, 特征行数=431567
    [2019-01-29 12:44:28.403593] INFO: 基础特征抽取: 年份 2011, 特征行数=511455
    [2019-01-29 12:44:50.090374] INFO: 基础特征抽取: 年份 2012, 特征行数=565675
    [2019-01-29 12:45:19.170816] INFO: 基础特征抽取: 年份 2013, 特征行数=564168
    [2019-01-29 12:45:43.084878] INFO: 基础特征抽取: 年份 2014, 特征行数=569948
    [2019-01-29 12:46:06.921556] INFO: 基础特征抽取: 年份 2015, 特征行数=0
    [2019-01-29 12:46:06.935935] INFO: 基础特征抽取: 总行数: 2737833
    [2019-01-29 12:46:06.938269] INFO: bigquant: general_feature_extractor.v7 运行完成[176.020563s].
    [2019-01-29 12:46:06.940433] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-29 12:46:06.947379] INFO: bigquant: input_features.v1 运行完成[0.006936s].
    [2019-01-29 12:46:06.949873] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-29 12:46:06.954462] INFO: bigquant: 命中缓存
    [2019-01-29 12:46:06.955585] INFO: bigquant: instruments.v2 运行完成[0.005696s].
    [2019-01-29 12:46:06.958581] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-29 12:46:06.964454] INFO: bigquant: 命中缓存
    [2019-01-29 12:46:06.965481] INFO: bigquant: input_features.v1 运行完成[0.006898s].
    [2019-01-29 12:46:06.968463] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-29 12:46:06.977897] INFO: bigquant: input_features.v1 运行完成[0.009432s].
    [2019-01-29 12:46:06.981566] INFO: bigquant: cached.v3 开始运行..
    [2019-01-29 12:46:06.989760] INFO: bigquant: cached.v3 运行完成[0.008196s].
    [2019-01-29 12:46:06.994981] INFO: bigquant: general_feature_extractor.v7 开始运行..
    [2019-01-29 12:46:10.452926] INFO: 基础特征抽取: 年份 2014, 特征行数=141569
    [2019-01-29 12:46:15.155142] INFO: 基础特征抽取: 年份 2015, 特征行数=569698
    [2019-01-29 12:46:18.792326] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
    [2019-01-29 12:46:29.271234] INFO: 基础特征抽取: 年份 2017, 特征行数=0
    [2019-01-29 12:46:29.304829] INFO: 基础特征抽取: 总行数: 1352813
    [2019-01-29 12:46:29.342790] INFO: bigquant: general_feature_extractor.v7 运行完成[22.347764s].
    [2019-01-29 12:46:29.345725] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-29 12:46:29.350892] INFO: bigquant: 命中缓存
    [2019-01-29 12:46:29.351840] INFO: bigquant: input_features.v1 运行完成[0.00613s].
    [2019-01-29 12:46:29.354679] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-29 12:46:29.359328] INFO: bigquant: 命中缓存
    [2019-01-29 12:46:29.360464] INFO: bigquant: instruments.v2 运行完成[0.005781s].
    [2019-01-29 12:46:29.363406] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
    [2019-01-29 12:46:29.367688] INFO: bigquant: 命中缓存
    [2019-01-29 12:46:29.368969] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.005566s].
    
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-29-cf4b0b00c397> in <module>()
        286     features=m5.data,
        287     start_date='',
    --> 288     end_date=''
        289 )
        290 
    
    TypeError: compile() arg 1 must be a string, bytes or AST object

    如何合并两个可视化策略
    (iQuant) #2

    收到您的提问,已提交给策略工程师,会尽快为您解答。


    (XiaoyuDu) #3

    tkyz,您好,对你的策略debug后运行结果和指导如下:

    需要注意的几点分别是:

    固定模块输入输出

    image ,已经封装好的可视化界面的模块输入和输出大部分分别有其固定的输入和输出数据种类,如图中左边接收特征,右边接收证券列表。将鼠标移到该小点上会有提示哦。 你的大部分错误都是这里

    调试与debug

    我们可以在可视化界面上下新开一格对可视化界面的输入输出数据进行查看debug,就像我在分享中做的一样,image ,将在模块内写的代码先在外面跑一下可以更加稳妥。

    错误1:

    image
    在这里,需要用鼠标放在小点上看到输入和输出分别是什么才能正确连线

    错误2

    在我们可视化策略的上方的代码模块中我们看到输入的两个预测表格列名不一致所以无法按position,concat,于是我们用merge取了交集。然后将所有被两个模型选出的股票进行交易。

    收益效果还是不错,恭喜

    克隆策略
    In [95]:
    m8.predictions.read().head()
    
    Out[95]:
    score date instrument position
    0 1.206727 2014-10-29 600035.SHA 1
    1 0.970216 2014-10-29 600004.SHA 2
    2 0.948796 2014-10-29 600486.SHA 3
    3 0.939215 2014-10-29 601555.SHA 4
    4 0.938887 2014-10-29 002598.SZA 5
    In [100]:
    m12.predictions.read().head()
    
    Out[100]:
    classes_prob_0 classes_prob_1 pred_label date instrument
    2 0.640431 0.359569 0 2014-10-30 000001.SZA
    21 0.679217 0.320783 0 2014-11-26 000001.SZA
    35 0.571991 0.428009 0 2014-12-16 000001.SZA
    39 0.699138 0.300862 0 2014-12-22 000001.SZA
    46 0.650829 0.349171 0 2014-12-31 000001.SZA
    In [103]:
    df1 = m8.predictions.read_df()
    df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)
    df1.head()
    
    Out[103]:
    score date instrument position
    0 1.206727 2014-10-29 600035.SHA 1
    1 0.970216 2014-10-29 600004.SHA 2
    2 0.948796 2014-10-29 600486.SHA 3
    3 0.939215 2014-10-29 601555.SHA 4
    4 0.938887 2014-10-29 002598.SZA 5
    In [121]:
    df2 = m12.predictions.read_df()
    
    df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('classes_prob_0')[:2]).reset_index(drop=True)
    df2_filter.head()
    
    Out[121]:
    classes_prob_0 classes_prob_1 pred_label date instrument
    0 0.522840 0.477160 0 2014-10-29 600834.SHA
    1 0.526359 0.473641 0 2014-10-29 002682.SZA
    2 0.549988 0.450012 0 2014-10-30 000657.SZA
    3 0.566365 0.433635 0 2014-10-30 300093.SZA
    4 0.563091 0.436909 0 2014-10-31 600259.SHA
    In [125]:
    df=pd.merge(df1_filter,df2_filter,left_on=['date','instrument'],right_on=['date','instrument']).sort_values(['date','position'])
    df.head()
    
    Out[125]:
    score date instrument position classes_prob_0 classes_prob_1 pred_label
    0 1.155616 2014-10-31 600259.SHA 1 0.563091 0.436909 0
    1 0.787467 2014-11-04 600359.SHA 1 0.543182 0.456818 0
    2 1.261694 2014-11-07 600446.SHA 1 0.519923 0.480077 0
    3 1.308929 2014-11-13 002274.SZA 2 0.551363 0.448637 0
    4 1.252863 2014-11-14 600100.SHA 2 0.533990 0.466010 0

      {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-351: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":"-171:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-175:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:model"},{"DestinationInputPortId":"-1348:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-595:input_1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"-365:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-382:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62: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"},{"DestinationInputPortId":"-459:predict_ds","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-358:input_data","SourceOutputPortId":"-351:data"},{"DestinationInputPortId":"-9001:input_data","SourceOutputPortId":"-358:data"},{"DestinationInputPortId":"-372:input_data","SourceOutputPortId":"-365:data"},{"DestinationInputPortId":"-9453:input_data","SourceOutputPortId":"-372:data"},{"DestinationInputPortId":"-8132:features_ds","SourceOutputPortId":"-506:data"},{"DestinationInputPortId":"-11798:features_ds","SourceOutputPortId":"-506:data"},{"DestinationInputPortId":"-555:data2","SourceOutputPortId":"-518:data"},{"DestinationInputPortId":"-365:features","SourceOutputPortId":"-532:data_1"},{"DestinationInputPortId":"-9916:input_data","SourceOutputPortId":"-548:data"},{"DestinationInputPortId":"-12301:input_data","SourceOutputPortId":"-555:data"},{"DestinationInputPortId":"-459:training_ds","SourceOutputPortId":"-561:data"},{"DestinationInputPortId":"-382:options_data","SourceOutputPortId":"-595:data_1"},{"DestinationInputPortId":"-518:instruments","SourceOutputPortId":"-510:data"},{"DestinationInputPortId":"-13369:instruments","SourceOutputPortId":"-510:data"},{"DestinationInputPortId":"-532:input_1","SourceOutputPortId":"-171:data"},{"DestinationInputPortId":"-351:features","SourceOutputPortId":"-171:data"},{"DestinationInputPortId":"-532:input_2","SourceOutputPortId":"-8132:data"},{"DestinationInputPortId":"-13369:features","SourceOutputPortId":"-8132:data"},{"DestinationInputPortId":"-9932:input_1","SourceOutputPortId":"-45:data"},{"DestinationInputPortId":"-358:features","SourceOutputPortId":"-45:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-9001:data"},{"DestinationInputPortId":"-9001:features","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-10806:input_1","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-12892:input_data","SourceOutputPortId":"-9453:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:features","SourceOutputPortId":"-175:data"},{"DestinationInputPortId":"-555:data1","SourceOutputPortId":"-9916:data"},{"DestinationInputPortId":"-548:features","SourceOutputPortId":"-9924:data"},{"DestinationInputPortId":"-9932:input_2","SourceOutputPortId":"-9924:data"},{"DestinationInputPortId":"-372:features","SourceOutputPortId":"-9932:data_1"},{"DestinationInputPortId":"-9453:features","SourceOutputPortId":"-10806:data_1"},{"DestinationInputPortId":"-10806:input_2","SourceOutputPortId":"-10814:data"},{"DestinationInputPortId":"-9916:features","SourceOutputPortId":"-10814:data"},{"DestinationInputPortId":"-459:features","SourceOutputPortId":"-11798:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"-1348:data"},{"DestinationInputPortId":"-561:input_data","SourceOutputPortId":"-12301:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-12892:data"},{"DestinationInputPortId":"-548:input_data","SourceOutputPortId":"-13369:data"},{"DestinationInputPortId":"-595:input_2","SourceOutputPortId":"-459:predictions"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-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,"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, -2) / 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,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_0\nreturn_4\nreturn_5","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-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,"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-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,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2019-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,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"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,"Comment":"","CommentCollapsed":true},{"Id":"-351","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-351"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-351"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-351","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"Comment":"","CommentCollapsed":true},{"Id":"-358","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":"-358"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-358"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-358","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"Comment":"","CommentCollapsed":true},{"Id":"-365","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-365"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-365"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-365","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"Comment":"","CommentCollapsed":true},{"Id":"-372","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":"-372"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-372"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-372","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"Comment":"","CommentCollapsed":true},{"Id":"-382","ModuleId":"BigQuantSpace.trade.trade-v4","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 # 获取今日的日期\n today = data.current_dt.strftime('%Y-%m-%d') \n \n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions ] \n \n # 按日期过滤得到今日的预测数据,和买入备选股票列表\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n stock_to_buy = list(ranker_prediction.instrument)\n \n # 需要卖出的股票:已有持仓中不在买入列表的股票\n stock_to_sell = [ i for i in stock_hold_now if i not in stock_to_buy]\n \n # 生成卖出订单:\n if len(stock_to_sell)>0:\n for instrument in stock_to_sell:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n cur_position = context.portfolio.positions[sid].amount # 持仓\n if cur_position > 0 and data.can_trade(sid):\n context.order_target_percent(sid, 0) # 全部卖出 \n \n \n # 生成买入订单:买入每天两个策略前两名的股票\n if len(stock_to_buy)>0:\n if len(stock_to_buy)>0:\n weight = 1/4 # 每只股票的比重为等资金比例持有1/4仓位\n for instrument in stock_to_buy:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n if data.can_trade(sid):\n context.order_target_percent(sid, weight) # 买入\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 = 4\n # 每只的股票等资金分配\n context.stock_weights = [1/stock_count for i in range(4)]\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":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"后复权","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-382"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-382","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":19,"Comment":"","CommentCollapsed":true},{"Id":"-506","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_0\nreturn_4\nreturn_5","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-506"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-506","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-518","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nwhere(shift(close, -2) / shift(open, -1)-1>0.01, 1, 0)\n\n# 极值处理:用1%和99%分位的值做clip\n#clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\n#all_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":"-518"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-518","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"","CommentCollapsed":true},{"Id":"-532","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-532"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-532"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-532"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-532","OutputType":null},{"Name":"data_2","NodeId":"-532","OutputType":null},{"Name":"data_3","NodeId":"-532","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"","CommentCollapsed":true},{"Id":"-548","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":"-548"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-548"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-548","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":20,"Comment":"","CommentCollapsed":true},{"Id":"-555","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":"-555"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-555"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-555","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":21,"Comment":"","CommentCollapsed":true},{"Id":"-561","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-561"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-561","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":22,"Comment":"","CommentCollapsed":true},{"Id":"-595","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 df1=input_1.read_df()\n df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)\n df2=input_2.read_df()\n df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('classes_prob_0')[:2]).reset_index(drop=True)\n \n df=pd.merge(df1_filter,df2_filter,left_on=['date','instrument'],right_on=['date','instrument']).sort_values(['date','position'])\n \n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1, 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":"-595"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-595"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-595"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-595","OutputType":null},{"Name":"data_2","NodeId":"-595","OutputType":null},{"Name":"data_3","NodeId":"-595","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":25,"Comment":"","CommentCollapsed":true},{"Id":"-510","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-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":"-510"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-510","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-171","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nst_status_0\nreturn_90\nreturn_10\nreturn_80\nreturn_0\nhigh_0\nlow_0\nclose_0\nopen_0\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-171"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-171","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":26,"Comment":"辅助计算的因子,不参与训练","CommentCollapsed":false},{"Id":"-8132","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nst_status_0\nreturn_90\nreturn_10\nreturn_80\nhigh_0\nlow_0\nclose_0\nopen_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-8132"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-8132","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":27,"Comment":"辅助计算的因子,不参与训练","CommentCollapsed":false},{"Id":"-45","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmid=mean(close_0,14)\natr=ta_atr(high_0, low_0, close_0, 14)\nret1=return_90/return_10\nret2=return_80/return_10\nret3=return_5/return_0\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-45"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-45","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":28,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9001","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":"-9001"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9001"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9001","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":29,"Comment":"","CommentCollapsed":true},{"Id":"-32","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ncond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-32"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-32","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":30,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9453","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":"-9453"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9453"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9453","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":31,"Comment":"","CommentCollapsed":true},{"Id":"-175","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# 输入参与训练的自定义列\n\nret1\nret2\nret3\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-175"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-175","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":32,"Comment":"自定义的因子,也参与模型训练","CommentCollapsed":true},{"Id":"-9916","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":"-9916"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9916"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9916","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":33,"Comment":"","CommentCollapsed":true},{"Id":"-9924","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmid=mean(close_0,14)\natr=ta_atr(high_0, low_0, close_0, 14)\nret1=return_90/return_10\nret2=return_80/return_10\nret3=return_5/return_0\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-9924"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9924","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":34,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9932","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-9932"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-9932"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-9932"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-9932","OutputType":null},{"Name":"data_2","NodeId":"-9932","OutputType":null},{"Name":"data_3","NodeId":"-9932","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":35,"Comment":"","CommentCollapsed":true},{"Id":"-10806","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-10806"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-10806"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-10806"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-10806","OutputType":null},{"Name":"data_2","NodeId":"-10806","OutputType":null},{"Name":"data_3","NodeId":"-10806","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":36,"Comment":"","CommentCollapsed":true},{"Id":"-10814","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ncond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-10814"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-10814","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":37,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-11798","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# 输入参与训练的自定义列\n\nret1\nret2\nret3\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-11798"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-11798","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":38,"Comment":"自定义的因子,也参与模型训练","CommentCollapsed":true},{"Id":"-1348","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-1348"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1348","OutputType":null},{"Name":"left_data","NodeId":"-1348","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":39,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-12301","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-12301"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12301","OutputType":null},{"Name":"left_data","NodeId":"-12301","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":40,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-12892","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-12892"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12892","OutputType":null},{"Name":"left_data","NodeId":"-12892","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":41,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-13369","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-13369"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-13369"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-13369","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":42,"Comment":"","CommentCollapsed":true},{"Id":"-459","ModuleId":"BigQuantSpace.random_forest_classifier.random_forest_classifier-v1","ModuleParameters":[{"Name":"iterations","Value":10,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_depth","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"min_samples_per_leaf","Value":200,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"key_cols","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"workers","Value":"2","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"other_train_parameters","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"predict_ds","NodeId":"-459"}],"OutputPortsInternal":[{"Name":"output_model","NodeId":"-459","OutputType":null},{"Name":"predictions","NodeId":"-459","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":12,"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='43,-185,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='38,-93,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='287,-313,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-43' Position='227,681,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='95,366,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='395,801,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='571.1720581054688,296.2581481933594,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='95,548,200,200'/><NodePosition Node='-86' Position='841,876,200,200'/><NodePosition Node='-351' Position='409,-99,200,200'/><NodePosition Node='-358' Position='100,155,200,200'/><NodePosition Node='-365' Position='776,412,200,200'/><NodePosition Node='-372' Position='873,524,200,200'/><NodePosition Node='-382' Position='766,1171,200,200'/><NodePosition Node='-506' Position='1311,-320,200,200'/><NodePosition Node='-518' Position='1545,-102,200,200'/><NodePosition Node='-532' Position='778,-40,200,200'/><NodePosition Node='-548' Position='1454,163,200,200'/><NodePosition Node='-555' Position='1463,374,200,200'/><NodePosition Node='-561' Position='1466,568,200,200'/><NodePosition Node='-595' Position='851,1058,200,200'/><NodePosition Node='-510' Position='1543,-193,200,200'/><NodePosition Node='-171' Position='546,-217,200,200'/><NodePosition Node='-8132' Position='1056,-219,200,200'/><NodePosition Node='-45' Position='391,-9,200,200'/><NodePosition Node='-9001' Position='107,260,200,200'/><NodePosition Node='-32' Position='414,114,200,200'/><NodePosition Node='-9453' Position='850,685,200,200'/><NodePosition Node='-175' Position='387,405,200,200'/><NodePosition Node='-9916' Position='1462,272,200,200'/><NodePosition Node='-9924' Position='1159,-13,200,200'/><NodePosition Node='-9932' Position='790.827880859375,60.91395568847656,200,200'/><NodePosition Node='-10806' Position='779,168,200,200'/><NodePosition Node='-10814' Position='1157,108,200,200'/><NodePosition Node='-11798' Position='1158,425,200,200'/><NodePosition Node='-1348' Position='99,455,200,200'/><NodePosition Node='-12301' Position='1458,472,200,200'/><NodePosition Node='-12892' Position='820,772,200,200'/><NodePosition Node='-13369' Position='1157,-99,200,200'/><NodePosition Node='-459' Position='1327.1290283203125,977.5015869140625,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 [132]:
      # 本代码由可视化策略环境自动生成 2019年1月29日 17:15
      # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
      
      
      # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
      def m11_run_bigquant_run(input_1, input_2, input_3):
          # 示例代码如下。在这里编写您的代码
          f1 = input_1.read_pickle()
          f2 = input_2.read_pickle()
          factors = [ k for k in set(f1 + f2)]
          data_1 = DataSource.write_pickle(factors)
          return Outputs(data_1=data_1, data_2=None, data_3=None)
      
      # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
      def m11_post_run_bigquant_run(outputs):
          return outputs
      
      # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
      def m35_run_bigquant_run(input_1, input_2, input_3):
          # 示例代码如下。在这里编写您的代码
          f1 = input_1.read_pickle()
          f2 = input_2.read_pickle()
          factors = [ k for k in set(f1 + f2)]
          data_1 = DataSource.write_pickle(factors)
          return Outputs(data_1=data_1, data_2=None, data_3=None)
      
      # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
      def m35_post_run_bigquant_run(outputs):
          return outputs
      
      # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
      def m36_run_bigquant_run(input_1, input_2, input_3):
          # 示例代码如下。在这里编写您的代码
          f1 = input_1.read_pickle()
          f2 = input_2.read_pickle()
          factors = [ k for k in set(f1 + f2)]
          data_1 = DataSource.write_pickle(factors)
          return Outputs(data_1=data_1, data_2=None, data_3=None)
      
      # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
      def m36_post_run_bigquant_run(outputs):
          return outputs
      
      # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
      def m25_run_bigquant_run(input_1, input_2, input_3):
          # 示例代码如下。在这里编写您的代码
          df1=input_1.read_df()
          df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)
          df2=input_2.read_df()
          df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('classes_prob_0')[:2]).reset_index(drop=True)
          
          df=pd.merge(df1_filter,df2_filter,left_on=['date','instrument'],right_on=['date','instrument']).sort_values(['date','position'])
          
          data_1 = DataSource.write_df(df)
          return Outputs(data_1=data_1, data_2=None, data_3=None)
      
      # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
      def m25_post_run_bigquant_run(outputs):
          return outputs
      
      # 回测引擎:每日数据处理函数,每天执行一次
      def m19_handle_data_bigquant_run(context, data):
      
          # 获取今日的日期
          today = data.current_dt.strftime('%Y-%m-%d')  
          
          # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
          stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]      
          
          # 按日期过滤得到今日的预测数据,和买入备选股票列表
          ranker_prediction = context.ranker_prediction[
              context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
          stock_to_buy = list(ranker_prediction.instrument)
          
          # 需要卖出的股票:已有持仓中不在买入列表的股票
          stock_to_sell = [ i for i in stock_hold_now if i not in stock_to_buy]
          
          # 生成卖出订单:
          if len(stock_to_sell)>0:
              for instrument in stock_to_sell:
                  sid = context.symbol(instrument) # 将标的转化为equity格式
                  cur_position = context.portfolio.positions[sid].amount # 持仓
                  if cur_position > 0 and data.can_trade(sid):
                      context.order_target_percent(sid, 0) # 全部卖出   
          
          
          # 生成买入订单:买入每天两个策略前两名的股票
          if len(stock_to_buy)>0:
              if len(stock_to_buy)>0:
                  weight = 1/4 # 每只股票的比重为等资金比例持有1/4仓位
                  for instrument in stock_to_buy:
                      sid = context.symbol(instrument) # 将标的转化为equity格式
                      if  data.can_trade(sid):
                          context.order_target_percent(sid, weight) # 买入
      
      # 回测引擎:准备数据,只执行一次
      def m19_prepare_bigquant_run(context):
          pass
      
      # 回测引擎:初始化函数,只执行一次
      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
          # 每只的股票等资金分配
          context.stock_weights = [1/stock_count for i in range(4)]
      
      
      m1 = M.instruments.v2(
          start_date='2010-01-01',
          end_date='2015-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, -2) / 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="""# #号开始的表示注释
      # 多个特征,每行一个,可以包含基础特征和衍生特征
      return_0
      return_4
      return_5"""
      )
      
      m26 = M.input_features.v1(
          features_ds=m3.data,
          features="""
      # #号开始的表示注释,注释需单独一行
      # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
      st_status_0
      return_90
      return_10
      return_80
      return_0
      high_0
      low_0
      close_0
      open_0
      
      
      """
      )
      
      m15 = M.general_feature_extractor.v7(
          instruments=m1.data,
          features=m26.data,
          start_date='',
          end_date=''
      )
      
      m32 = M.input_features.v1(
          features_ds=m3.data,
          features="""
      # 输入参与训练的自定义列
      
      ret1
      ret2
      ret3
      """
      )
      
      m9 = M.instruments.v2(
          start_date=T.live_run_param('trading_date', '2015-01-01'),
          end_date=T.live_run_param('trading_date', '2019-01-01'),
          market='CN_STOCK_A',
          instrument_list='',
          max_count=0
      )
      
      m4 = M.input_features.v1(
          features="""
      # #号开始的表示注释
      # 多个特征,每行一个,可以包含基础特征和衍生特征
      return_0
      return_4
      return_5"""
      )
      
      m27 = M.input_features.v1(
          features_ds=m4.data,
          features="""
      # #号开始的表示注释,注释需单独一行
      # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
      st_status_0
      return_90
      return_10
      return_80
      high_0
      low_0
      close_0
      open_0"""
      )
      
      m11 = M.cached.v3(
          input_1=m26.data,
          input_2=m27.data,
          run=m11_run_bigquant_run,
          post_run=m11_post_run_bigquant_run,
          input_ports='',
          params='{}',
          output_ports=''
      )
      
      m17 = M.general_feature_extractor.v7(
          instruments=m9.data,
          features=m11.data_1,
          start_date='',
          end_date=''
      )
      
      m38 = M.input_features.v1(
          features_ds=m4.data,
          features="""
      # 输入参与训练的自定义列
      
      ret1
      ret2
      ret3
      """
      )
      
      m5 = M.instruments.v2(
          start_date='2010-01-01',
          end_date='2015-01-01',
          market='CN_STOCK_A',
          instrument_list='',
          max_count=0
      )
      
      m10 = M.advanced_auto_labeler.v2(
          instruments=m5.data,
          label_expr="""
      
      # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
      where(shift(close, -2) / shift(open, -1)-1>0.01, 1, 0)
      
      # 极值处理:用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,
          user_functions={}
      )
      
      m42 = M.general_feature_extractor.v7(
          instruments=m5.data,
          features=m27.data,
          start_date='',
          end_date=''
      )
      
      m28 = M.input_features.v1(
          features="""
      # #号开始的表示注释,注释需单独一行
      # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
      mid=mean(close_0,14)
      atr=ta_atr(high_0, low_0, close_0, 14)
      ret1=return_90/return_10
      ret2=return_80/return_10
      ret3=return_5/return_0
      
      """
      )
      
      m16 = M.derived_feature_extractor.v3(
          input_data=m15.data,
          features=m28.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False
      )
      
      m30 = M.input_features.v1(
          features="""
      # #号开始的表示注释,注释需单独一行
      # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
      cond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))
      """
      )
      
      m29 = M.derived_feature_extractor.v3(
          input_data=m16.data,
          features=m30.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False
      )
      
      m7 = M.join.v3(
          data1=m2.data,
          data2=m29.data,
          on='date,instrument',
          how='inner',
          sort=False
      )
      
      m39 = M.filter.v3(
          input_data=m7.data,
          expr='st_status_0 == 0 and cond2>0',
          output_left_data=False
      )
      
      m13 = M.dropnan.v1(
          input_data=m39.data
      )
      
      m6 = M.stock_ranker_train.v5(
          training_ds=m13.data,
          features=m32.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
      )
      
      m34 = M.input_features.v1(
          features="""
      # #号开始的表示注释,注释需单独一行
      # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
      mid=mean(close_0,14)
      atr=ta_atr(high_0, low_0, close_0, 14)
      ret1=return_90/return_10
      ret2=return_80/return_10
      ret3=return_5/return_0
      
      """
      )
      
      m20 = M.derived_feature_extractor.v3(
          input_data=m42.data,
          features=m34.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False,
          user_functions={}
      )
      
      m35 = M.cached.v3(
          input_1=m28.data,
          input_2=m34.data,
          run=m35_run_bigquant_run,
          post_run=m35_post_run_bigquant_run,
          input_ports='',
          params='{}',
          output_ports=''
      )
      
      m18 = M.derived_feature_extractor.v3(
          input_data=m17.data,
          features=m35.data_1,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False
      )
      
      m37 = M.input_features.v1(
          features="""
      # #号开始的表示注释,注释需单独一行
      # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
      cond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))
      
      
      """
      )
      
      m36 = M.cached.v3(
          input_1=m30.data,
          input_2=m37.data,
          run=m36_run_bigquant_run,
          post_run=m36_post_run_bigquant_run,
          input_ports='',
          params='{}',
          output_ports=''
      )
      
      m31 = M.derived_feature_extractor.v3(
          input_data=m18.data,
          features=m36.data_1,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False
      )
      
      m41 = M.filter.v3(
          input_data=m31.data,
          expr='st_status_0 == 0 and cond2>0',
          output_left_data=False
      )
      
      m14 = M.dropnan.v1(
          input_data=m41.data
      )
      
      m8 = M.stock_ranker_predict.v5(
          model=m6.model,
          data=m14.data,
          m_lazy_run=False
      )
      
      m33 = M.derived_feature_extractor.v3(
          input_data=m20.data,
          features=m37.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=True,
          remove_extra_columns=False
      )
      
      m21 = M.join.v3(
          data1=m33.data,
          data2=m10.data,
          on='date,instrument',
          how='inner',
          sort=False
      )
      
      m40 = M.filter.v3(
          input_data=m21.data,
          expr='st_status_0 == 0 and cond2>0',
          output_left_data=False
      )
      
      m22 = M.dropnan.v1(
          input_data=m40.data
      )
      
      m12 = M.random_forest_classifier.v1(
          training_ds=m22.data,
          features=m38.data,
          predict_ds=m14.data,
          iterations=10,
          feature_fraction=1,
          max_depth=30,
          min_samples_per_leaf=200,
          key_cols='date,instrument',
          workers=2,
          other_train_parameters={}
      )
      
      m25 = M.cached.v3(
          input_1=m8.predictions,
          input_2=m12.predictions,
          run=m25_run_bigquant_run,
          post_run=m25_post_run_bigquant_run,
          input_ports='',
          params='{}',
          output_ports=''
      )
      
      m19 = M.trade.v4(
          instruments=m9.data,
          options_data=m25.data_1,
          start_date='',
          end_date='',
          handle_data=m19_handle_data_bigquant_run,
          prepare=m19_prepare_bigquant_run,
          initialize=m19_initialize_bigquant_run,
          volume_limit=0.025,
          order_price_field_buy='open',
          order_price_field_sell='close',
          capital_base=1000000,
          auto_cancel_non_tradable_orders=True,
          data_frequency='daily',
          price_type='后复权',
          product_type='股票',
          plot_charts=True,
          backtest_only=False,
          benchmark=''
      )
      
      [2019-01-29 17:08:05.456702] INFO: bigquant: instruments.v2 开始运行..
      [2019-01-29 17:08:05.463487] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.465099] INFO: bigquant: instruments.v2 运行完成[0.008419s].
      [2019-01-29 17:08:05.468339] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
      [2019-01-29 17:08:05.473832] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.475361] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.007017s].
      [2019-01-29 17:08:05.478080] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:08:05.483138] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.484320] INFO: bigquant: input_features.v1 运行完成[0.006275s].
      [2019-01-29 17:08:05.486660] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:08:05.491766] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.492765] INFO: bigquant: input_features.v1 运行完成[0.006078s].
      [2019-01-29 17:08:05.500425] INFO: bigquant: general_feature_extractor.v7 开始运行..
      [2019-01-29 17:08:05.505565] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.506614] INFO: bigquant: general_feature_extractor.v7 运行完成[0.006162s].
      [2019-01-29 17:08:05.509472] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:08:05.514366] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.515247] INFO: bigquant: input_features.v1 运行完成[0.005764s].
      [2019-01-29 17:08:05.518065] INFO: bigquant: instruments.v2 开始运行..
      [2019-01-29 17:08:05.523972] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.524952] INFO: bigquant: instruments.v2 运行完成[0.006908s].
      [2019-01-29 17:08:05.527103] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:08:05.531198] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.531925] INFO: bigquant: input_features.v1 运行完成[0.004821s].
      [2019-01-29 17:08:05.534311] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:08:05.538189] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.538919] INFO: bigquant: input_features.v1 运行完成[0.004604s].
      [2019-01-29 17:08:05.543024] INFO: bigquant: cached.v3 开始运行..
      [2019-01-29 17:08:05.549438] INFO: bigquant: 命中缓存
      [2019-01-29 17:08:05.551093] INFO: bigquant: cached.v3 运行完成[0.00808s].
      [2019-01-29 17:08:05.557968] INFO: bigquant: general_feature_extractor.v7 开始运行..
      [2019-01-29 17:08:52.258840] INFO: 基础特征抽取: 年份 2014, 特征行数=141569
      [2019-01-29 17:09:35.642926] INFO: 基础特征抽取: 年份 2015, 特征行数=569698
      [2019-01-29 17:10:13.367252] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
      [2019-01-29 17:11:32.565460] INFO: 基础特征抽取: 年份 2017, 特征行数=743233
      [2019-01-29 17:11:44.714231] INFO: 基础特征抽取: 年份 2018, 特征行数=816977
      [2019-01-29 17:11:47.276421] INFO: 基础特征抽取: 年份 2019, 特征行数=0
      [2019-01-29 17:11:47.305215] INFO: 基础特征抽取: 总行数: 2913023
      [2019-01-29 17:11:47.308502] INFO: bigquant: general_feature_extractor.v7 运行完成[221.750514s].
      [2019-01-29 17:11:47.312266] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:11:47.325354] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.326730] INFO: bigquant: input_features.v1 运行完成[0.014477s].
      [2019-01-29 17:11:47.329545] INFO: bigquant: instruments.v2 开始运行..
      [2019-01-29 17:11:47.334760] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.335963] INFO: bigquant: instruments.v2 运行完成[0.006419s].
      [2019-01-29 17:11:47.338829] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
      [2019-01-29 17:11:47.345261] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.346888] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.008043s].
      [2019-01-29 17:11:47.358525] INFO: bigquant: general_feature_extractor.v7 开始运行..
      [2019-01-29 17:11:47.365145] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.366228] INFO: bigquant: general_feature_extractor.v7 运行完成[0.007696s].
      [2019-01-29 17:11:47.369365] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:11:47.378227] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.379417] INFO: bigquant: input_features.v1 运行完成[0.01004s].
      [2019-01-29 17:11:47.383103] INFO: bigquant: derived_feature_extractor.v3 开始运行..
      [2019-01-29 17:11:47.388892] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.389915] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.006859s].
      [2019-01-29 17:11:47.392943] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:11:47.399194] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.400186] INFO: bigquant: input_features.v1 运行完成[0.007238s].
      [2019-01-29 17:11:47.403454] INFO: bigquant: derived_feature_extractor.v3 开始运行..
      [2019-01-29 17:11:47.408570] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.409510] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.006062s].
      [2019-01-29 17:11:47.412413] INFO: bigquant: join.v3 开始运行..
      [2019-01-29 17:11:47.429635] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.430752] INFO: bigquant: join.v3 运行完成[0.018311s].
      [2019-01-29 17:11:47.433516] INFO: bigquant: filter.v3 开始运行..
      [2019-01-29 17:11:47.528756] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.529836] INFO: bigquant: filter.v3 运行完成[0.096307s].
      [2019-01-29 17:11:47.532978] INFO: bigquant: dropnan.v1 开始运行..
      [2019-01-29 17:11:47.538862] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.539921] INFO: bigquant: dropnan.v1 运行完成[0.006915s].
      [2019-01-29 17:11:47.549994] INFO: bigquant: stock_ranker_train.v5 开始运行..
      [2019-01-29 17:11:47.645773] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.648050] INFO: bigquant: stock_ranker_train.v5 运行完成[0.098022s].
      [2019-01-29 17:11:47.651050] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:11:47.658371] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.659557] INFO: bigquant: input_features.v1 运行完成[0.00853s].
      [2019-01-29 17:11:47.662536] INFO: bigquant: derived_feature_extractor.v3 开始运行..
      [2019-01-29 17:11:47.668840] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.670248] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.00771s].
      [2019-01-29 17:11:47.674402] INFO: bigquant: cached.v3 开始运行..
      [2019-01-29 17:11:47.731124] INFO: bigquant: 命中缓存
      [2019-01-29 17:11:47.732752] INFO: bigquant: cached.v3 运行完成[0.058339s].
      [2019-01-29 17:11:47.735513] INFO: bigquant: derived_feature_extractor.v3 开始运行..
      [2019-01-29 17:11:50.038413] INFO: derived_feature_extractor: 提取完成 ret1=return_90/return_10, 0.021s
      [2019-01-29 17:11:50.061002] INFO: derived_feature_extractor: 提取完成 ret2=return_80/return_10, 0.021s
      [2019-01-29 17:11:50.074692] INFO: derived_feature_extractor: 提取完成 ret3=return_5/return_0, 0.012s
      [2019-01-29 17:11:54.244030] INFO: derived_feature_extractor: 提取完成 mid=mean(close_0,14), 4.168s
      [2019-01-29 17:12:01.152997] INFO: derived_feature_extractor: 提取完成 atr=ta_atr(high_0, low_0, close_0, 14), 6.906s
      [2019-01-29 17:12:02.297576] INFO: derived_feature_extractor: /y_2014, 141569
      [2019-01-29 17:12:02.574686] INFO: derived_feature_extractor: /y_2015, 569698
      [2019-01-29 17:12:03.463373] INFO: derived_feature_extractor: /y_2016, 641546
      [2019-01-29 17:12:04.362990] INFO: derived_feature_extractor: /y_2017, 743233
      [2019-01-29 17:12:05.877658] INFO: derived_feature_extractor: /y_2018, 816977
      [2019-01-29 17:12:07.412928] INFO: bigquant: derived_feature_extractor.v3 运行完成[19.677385s].
      [2019-01-29 17:12:07.416398] INFO: bigquant: input_features.v1 开始运行..
      [2019-01-29 17:12:07.422133] INFO: bigquant: 命中缓存
      [2019-01-29 17:12:07.423153] INFO: bigquant: input_features.v1 运行完成[0.006755s].
      [2019-01-29 17:12:07.427898] INFO: bigquant: cached.v3 开始运行..
      [2019-01-29 17:12:07.434072] INFO: bigquant: 命中缓存
      [2019-01-29 17:12:07.434968] INFO: bigquant: cached.v3 运行完成[0.007081s].
      [2019-01-29 17:12:07.438233] INFO: bigquant: derived_feature_extractor.v3 开始运行..
      [2019-01-29 17:12:09.874992] INFO: derived_feature_extractor: 提取完成 cond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1)), 1.286s
      [2019-01-29 17:12:09.953130] INFO: derived_feature_extractor: /y_2014, 104572
      [2019-01-29 17:12:10.424702] INFO: derived_feature_extractor: /y_2015, 547984
      [2019-01-29 17:12:11.318960] INFO: derived_feature_extractor: /y_2016, 625475
      [2019-01-29 17:12:12.269310] INFO: derived_feature_extractor: /y_2017, 702247
      [2019-01-29 17:12:13.792519] INFO: derived_feature_extractor: /y_2018, 802730
      [2019-01-29 17:12:15.355325] INFO: bigquant: derived_feature_extractor.v3 运行完成[7.917064s].
      [2019-01-29 17:12:15.357993] INFO: bigquant: filter.v3 开始运行..
      [2019-01-29 17:12:15.365446] INFO: filter: 使用表达式 st_status_0 == 0 and cond2>0 过滤
      [2019-01-29 17:12:15.505925] INFO: filter: 过滤 /y_2014, 6130/0/104572
      [2019-01-29 17:12:15.725592] INFO: filter: 过滤 /y_2015, 36187/0/547984
      [2019-01-29 17:12:16.011539] INFO: filter: 过滤 /y_2016, 34463/0/625475
      [2019-01-29 17:12:16.334279] INFO: filter: 过滤 /y_2017, 33863/0/702247
      [2019-01-29 17:12:16.785000] INFO: filter: 过滤 /y_2018, 34973/0/802730
      [2019-01-29 17:12:16.864148] INFO: bigquant: filter.v3 运行完成[1.506103s].
      [2019-01-29 17:12:16.867888] INFO: bigquant: dropnan.v1 开始运行..
      [2019-01-29 17:12:16.995810] INFO: dropnan: /y_2014, 6130/6130
      [2019-01-29 17:12:17.074006] INFO: dropnan: /y_2015, 36187/36187
      [2019-01-29 17:12:17.144360] INFO: dropnan: /y_2016, 34463/34463
      [2019-01-29 17:12:17.231165] INFO: dropnan: /y_2017, 33863/33863
      [2019-01-29 17:12:17.340479] INFO: dropnan: /y_2018, 34973/34973
      [2019-01-29 17:12:17.364744] INFO: dropnan: 行数: 145616/145616
      [2019-01-29 17:12:17.368467] INFO: bigquant: dropnan.v1 运行完成[0.500596s].
      [2019-01-29 17:12:17.371480] INFO: bigquant: stock_ranker_predict.v5 开始运行..
      [2019-01-29 17:12:17.771399] INFO: StockRanker: prepare data: prediction ..
      [2019-01-29 17:12:21.054196] INFO: stock_ranker_predict: 准备预测: 145616 行
      [2019-01-29 17:12:21.055395] INFO: stock_ranker_predict: 正在预测 ..
      [2019-01-29 17:12:31.237077] INFO: bigquant: stock_ranker_predict.v5 运行完成[13.865554s].
      [2019-01-29 17:12:31.239465] INFO: bigquant: derived_feature_extractor.v3 开始运行..
      [2019-01-29 17:12:31.245102] INFO: bigquant: 命中缓存
      [2019-01-29 17:12:31.246445] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.006961s].
      [2019-01-29 17:12:31.249115] INFO: bigquant: join.v3 开始运行..
      [2019-01-29 17:12:31.254464] INFO: bigquant: 命中缓存
      [2019-01-29 17:12:31.255420] INFO: bigquant: join.v3 运行完成[0.006295s].
      [2019-01-29 17:12:31.258163] INFO: bigquant: filter.v3 开始运行..
      [2019-01-29 17:12:31.262993] INFO: bigquant: 命中缓存
      [2019-01-29 17:12:31.263968] INFO: bigquant: filter.v3 运行完成[0.005798s].
      [2019-01-29 17:12:31.266204] INFO: bigquant: dropnan.v1 开始运行..
      [2019-01-29 17:12:31.270962] INFO: bigquant: 命中缓存
      [2019-01-29 17:12:31.271786] INFO: bigquant: dropnan.v1 运行完成[0.005569s].
      [2019-01-29 17:12:31.274915] INFO: bigquant: random_forest_classifier.v1 开始运行..
      [2019-01-29 17:12:32.009287] INFO: bigquant: random_forest_classifier.v1 运行完成[0.734349s].
      [2019-01-29 17:12:32.013537] INFO: bigquant: cached.v3 开始运行..
      [2019-01-29 17:12:34.034605] INFO: bigquant: cached.v3 运行完成[2.021031s].
      [2019-01-29 17:12:34.052695] INFO: bigquant: backtest.v8 开始运行..
      [2019-01-29 17:12:34.055187] INFO: bigquant: biglearning backtest:V8.1.8
      [2019-01-29 17:12:34.056415] INFO: bigquant: product_type:stock by specified
      [2019-01-29 17:12:52.103332] INFO: bigquant: 读取股票行情完成:3646127
      [2019-01-29 17:13:32.329825] INFO: algo: TradingAlgorithm V1.4.5
      [2019-01-29 17:13:45.321664] INFO: algo: trading transform...
      [2019-01-29 17:13:49.432240] INFO: Performance: Simulated 975 trading days out of 975.
      [2019-01-29 17:13:49.433796] INFO: Performance: first open: 2015-01-05 09:30:00+00:00
      [2019-01-29 17:13:49.434680] INFO: Performance: last close: 2018-12-28 15:00:00+00:00
      
      • 收益率143.65%
      • 年化收益率25.88%
      • 基准收益率-14.8%
      • 阿尔法0.22
      • 贝塔0.21
      • 夏普比率1.35
      • 胜率0.58
      • 盈亏比1.12
      • 收益波动率15.81%
      • 信息比率0.06
      • 最大回撤21.77%
      [2019-01-29 17:13:53.885310] INFO: bigquant: backtest.v8 运行完成[79.832587s].
      

      【宽客学院】AI策略开发
      (tkyz) #4

      可以加入滚动训练吗?如果可以是不是弄两个滚动训练,然后分别设置参数?


      (iQuant) #5

      收到您的提问,我们已提交给策略工程师,会尽快给您回复。


      (XiaoyuDu) #6

      不能弄两个滚动训练,因为滚动训练模块一个就是从训练到预测到回测的整体,我们先看一看怎么让你这个跑起来,因为你这个是两个训练模型取交集,比较不常见。


      (tkyz) #7

      好的,等你答复


      (XiaoyuDu) #8

      我们只需要一个滚动训练模块就可以,滚动训练的模块里面的代码需要做一点点微调,
      因为有两个训练模块,所以我们需要把训练模型传进去
      image
      并且在后面滚动的时候也需要加进去:
      image

      注意,我们不要勾选延迟运行,如图

      最后点击运行即可,滚动训练模块里面的参数可以按需要修改
      image

      克隆策略
      In [95]:
      m8.predictions.read().head()
      
      Out[95]:
      score date instrument position
      0 1.206727 2014-10-29 600035.SHA 1
      1 0.970216 2014-10-29 600004.SHA 2
      2 0.948796 2014-10-29 600486.SHA 3
      3 0.939215 2014-10-29 601555.SHA 4
      4 0.938887 2014-10-29 002598.SZA 5
      In [100]:
      m12.predictions.read().head()
      
      Out[100]:
      classes_prob_0 classes_prob_1 pred_label date instrument
      2 0.640431 0.359569 0 2014-10-30 000001.SZA
      21 0.679217 0.320783 0 2014-11-26 000001.SZA
      35 0.571991 0.428009 0 2014-12-16 000001.SZA
      39 0.699138 0.300862 0 2014-12-22 000001.SZA
      46 0.650829 0.349171 0 2014-12-31 000001.SZA
      In [103]:
      df1 = m8.predictions.read_df()
      df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)
      df1.head()
      
      Out[103]:
      score date instrument position
      0 1.206727 2014-10-29 600035.SHA 1
      1 0.970216 2014-10-29 600004.SHA 2
      2 0.948796 2014-10-29 600486.SHA 3
      3 0.939215 2014-10-29 601555.SHA 4
      4 0.938887 2014-10-29 002598.SZA 5
      In [121]:
      df2 = m12.predictions.read_df()
      
      df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('classes_prob_0')[:2]).reset_index(drop=True)
      df2_filter.head()
      
      Out[121]:
      classes_prob_0 classes_prob_1 pred_label date instrument
      0 0.522840 0.477160 0 2014-10-29 600834.SHA
      1 0.526359 0.473641 0 2014-10-29 002682.SZA
      2 0.549988 0.450012 0 2014-10-30 000657.SZA
      3 0.566365 0.433635 0 2014-10-30 300093.SZA
      4 0.563091 0.436909 0 2014-10-31 600259.SHA
      In [125]:
      df=pd.merge(df1_filter,df2_filter,left_on=['date','instrument'],right_on=['date','instrument']).sort_values(['date','position'])
      df.head()
      
      Out[125]:
      score date instrument position classes_prob_0 classes_prob_1 pred_label
      0 1.155616 2014-10-31 600259.SHA 1 0.563091 0.436909 0
      1 0.787467 2014-11-04 600359.SHA 1 0.543182 0.456818 0
      2 1.261694 2014-11-07 600446.SHA 1 0.519923 0.480077 0
      3 1.308929 2014-11-13 002274.SZA 2 0.551363 0.448637 0
      4 1.252863 2014-11-14 600100.SHA 2 0.533990 0.466010 0

        {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-351: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":"-171:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-175:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:model"},{"DestinationInputPortId":"-1348:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-595:input_1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"-365:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-382:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62: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"},{"DestinationInputPortId":"-459:predict_ds","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-358:input_data","SourceOutputPortId":"-351:data"},{"DestinationInputPortId":"-9001:input_data","SourceOutputPortId":"-358:data"},{"DestinationInputPortId":"-372:input_data","SourceOutputPortId":"-365:data"},{"DestinationInputPortId":"-9453:input_data","SourceOutputPortId":"-372:data"},{"DestinationInputPortId":"-8132:features_ds","SourceOutputPortId":"-506:data"},{"DestinationInputPortId":"-11798:features_ds","SourceOutputPortId":"-506:data"},{"DestinationInputPortId":"-555:data2","SourceOutputPortId":"-518:data"},{"DestinationInputPortId":"-365:features","SourceOutputPortId":"-532:data_1"},{"DestinationInputPortId":"-9916:input_data","SourceOutputPortId":"-548:data"},{"DestinationInputPortId":"-12301:input_data","SourceOutputPortId":"-555:data"},{"DestinationInputPortId":"-459:training_ds","SourceOutputPortId":"-561:data"},{"DestinationInputPortId":"-382:options_data","SourceOutputPortId":"-595:data_1"},{"DestinationInputPortId":"-518:instruments","SourceOutputPortId":"-510:data"},{"DestinationInputPortId":"-13369:instruments","SourceOutputPortId":"-510:data"},{"DestinationInputPortId":"-532:input_1","SourceOutputPortId":"-171:data"},{"DestinationInputPortId":"-351:features","SourceOutputPortId":"-171:data"},{"DestinationInputPortId":"-532:input_2","SourceOutputPortId":"-8132:data"},{"DestinationInputPortId":"-13369:features","SourceOutputPortId":"-8132:data"},{"DestinationInputPortId":"-9932:input_1","SourceOutputPortId":"-45:data"},{"DestinationInputPortId":"-358:features","SourceOutputPortId":"-45:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-9001:data"},{"DestinationInputPortId":"-9001:features","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-10806:input_1","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-12892:input_data","SourceOutputPortId":"-9453:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:features","SourceOutputPortId":"-175:data"},{"DestinationInputPortId":"-555:data1","SourceOutputPortId":"-9916:data"},{"DestinationInputPortId":"-548:features","SourceOutputPortId":"-9924:data"},{"DestinationInputPortId":"-9932:input_2","SourceOutputPortId":"-9924:data"},{"DestinationInputPortId":"-372:features","SourceOutputPortId":"-9932:data_1"},{"DestinationInputPortId":"-9453:features","SourceOutputPortId":"-10806:data_1"},{"DestinationInputPortId":"-10806:input_2","SourceOutputPortId":"-10814:data"},{"DestinationInputPortId":"-9916:features","SourceOutputPortId":"-10814:data"},{"DestinationInputPortId":"-459:features","SourceOutputPortId":"-11798:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"-1348:data"},{"DestinationInputPortId":"-561:input_data","SourceOutputPortId":"-12301:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-12892:data"},{"DestinationInputPortId":"-548:input_data","SourceOutputPortId":"-13369:data"},{"DestinationInputPortId":"-595:input_2","SourceOutputPortId":"-459:predictions"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-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,"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, -2) / 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,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_0\nreturn_4\nreturn_5","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-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,"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-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,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2019-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,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"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,"Comment":"","CommentCollapsed":true},{"Id":"-351","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-351"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-351"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-351","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"Comment":"","CommentCollapsed":true},{"Id":"-358","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":"-358"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-358"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-358","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"Comment":"","CommentCollapsed":true},{"Id":"-365","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-365"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-365"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-365","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"Comment":"","CommentCollapsed":true},{"Id":"-372","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":"-372"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-372"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-372","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"Comment":"","CommentCollapsed":true},{"Id":"-382","ModuleId":"BigQuantSpace.trade.trade-v4","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 # 获取今日的日期\n today = data.current_dt.strftime('%Y-%m-%d') \n \n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions ] \n \n # 按日期过滤得到今日的预测数据,和买入备选股票列表\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n stock_to_buy = list(ranker_prediction.instrument)\n \n # 需要卖出的股票:已有持仓中不在买入列表的股票\n stock_to_sell = [ i for i in stock_hold_now if i not in stock_to_buy]\n \n # 生成卖出订单:\n if len(stock_to_sell)>0:\n for instrument in stock_to_sell:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n cur_position = context.portfolio.positions[sid].amount # 持仓\n if cur_position > 0 and data.can_trade(sid):\n context.order_target_percent(sid, 0) # 全部卖出 \n \n \n # 生成买入订单:买入每天两个策略前两名的股票\n if len(stock_to_buy)>0:\n if len(stock_to_buy)>0:\n weight = 1/4 # 每只股票的比重为等资金比例持有1/4仓位\n for instrument in stock_to_buy:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n if data.can_trade(sid):\n context.order_target_percent(sid, weight) # 买入\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 = 4\n # 每只的股票等资金分配\n context.stock_weights = [1/stock_count for i in range(4)]\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":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"后复权","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-382"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-382"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-382","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":19,"Comment":"","CommentCollapsed":true},{"Id":"-506","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_0\nreturn_4\nreturn_5","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-506"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-506","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-518","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nwhere(shift(close, -2) / shift(open, -1)-1>0.01, 1, 0)\n\n# 极值处理:用1%和99%分位的值做clip\n#clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\n#all_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":"-518"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-518","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"","CommentCollapsed":true},{"Id":"-532","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-532"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-532"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-532"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-532","OutputType":null},{"Name":"data_2","NodeId":"-532","OutputType":null},{"Name":"data_3","NodeId":"-532","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"","CommentCollapsed":true},{"Id":"-548","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":"-548"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-548"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-548","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":20,"Comment":"","CommentCollapsed":true},{"Id":"-555","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":"-555"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-555"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-555","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":21,"Comment":"","CommentCollapsed":true},{"Id":"-561","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-561"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-561","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":22,"Comment":"","CommentCollapsed":true},{"Id":"-595","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 df1=input_1.read_df()\n df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)\n df2=input_2.read_df()\n df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('classes_prob_0')[:2]).reset_index(drop=True)\n \n df=pd.merge(df1_filter,df2_filter,left_on=['date','instrument'],right_on=['date','instrument']).sort_values(['date','position'])\n \n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1, 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":"-595"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-595"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-595"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-595","OutputType":null},{"Name":"data_2","NodeId":"-595","OutputType":null},{"Name":"data_3","NodeId":"-595","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":25,"Comment":"","CommentCollapsed":true},{"Id":"-510","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2011-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":"-510"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-510","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-171","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nst_status_0\nreturn_90\nreturn_10\nreturn_80\nreturn_0\nhigh_0\nlow_0\nclose_0\nopen_0\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-171"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-171","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":26,"Comment":"辅助计算的因子,不参与训练","CommentCollapsed":false},{"Id":"-8132","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nst_status_0\nreturn_90\nreturn_10\nreturn_80\nhigh_0\nlow_0\nclose_0\nopen_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-8132"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-8132","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":27,"Comment":"辅助计算的因子,不参与训练","CommentCollapsed":false},{"Id":"-45","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmid=mean(close_0,14)\natr=ta_atr(high_0, low_0, close_0, 14)\nret1=return_90/return_10\nret2=return_80/return_10\nret3=return_5/return_0\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-45"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-45","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":28,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9001","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":"-9001"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9001"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9001","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":29,"Comment":"","CommentCollapsed":true},{"Id":"-32","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ncond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-32"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-32","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":30,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9453","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":"-9453"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9453"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9453","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":31,"Comment":"","CommentCollapsed":true},{"Id":"-175","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# 输入参与训练的自定义列\n\nret1\nret2\nret3\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-175"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-175","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":32,"Comment":"自定义的因子,也参与模型训练","CommentCollapsed":true},{"Id":"-9916","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":"-9916"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9916"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9916","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":33,"Comment":"","CommentCollapsed":true},{"Id":"-9924","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmid=mean(close_0,14)\natr=ta_atr(high_0, low_0, close_0, 14)\nret1=return_90/return_10\nret2=return_80/return_10\nret3=return_5/return_0\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-9924"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9924","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":34,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-9932","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-9932"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-9932"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-9932"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-9932","OutputType":null},{"Name":"data_2","NodeId":"-9932","OutputType":null},{"Name":"data_3","NodeId":"-9932","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":35,"Comment":"","CommentCollapsed":true},{"Id":"-10806","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 f1 = input_1.read_pickle()\n f2 = input_2.read_pickle()\n factors = [ k for k in set(f1 + f2)]\n data_1 = DataSource.write_pickle(factors)\n return Outputs(data_1=data_1, 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":"-10806"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-10806"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-10806"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-10806","OutputType":null},{"Name":"data_2","NodeId":"-10806","OutputType":null},{"Name":"data_3","NodeId":"-10806","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":36,"Comment":"","CommentCollapsed":true},{"Id":"-10814","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ncond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))\n\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-10814"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-10814","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":37,"Comment":"自己定义的因子","CommentCollapsed":false},{"Id":"-11798","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# 输入参与训练的自定义列\n\nret1\nret2\nret3\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-11798"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-11798","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":38,"Comment":"自定义的因子,也参与模型训练","CommentCollapsed":true},{"Id":"-1348","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-1348"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1348","OutputType":null},{"Name":"left_data","NodeId":"-1348","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":39,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-12301","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-12301"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12301","OutputType":null},{"Name":"left_data","NodeId":"-12301","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":40,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-12892","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"st_status_0 == 0 and cond2>0","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":"-12892"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12892","OutputType":null},{"Name":"left_data","NodeId":"-12892","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":41,"Comment":"过滤上市天数不足120天以及ST的股票","CommentCollapsed":true},{"Id":"-13369","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-13369"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-13369"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-13369","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":42,"Comment":"","CommentCollapsed":true},{"Id":"-459","ModuleId":"BigQuantSpace.random_forest_classifier.random_forest_classifier-v1","ModuleParameters":[{"Name":"iterations","Value":10,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_depth","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"min_samples_per_leaf","Value":200,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"key_cols","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"workers","Value":"2","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"other_train_parameters","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"-459"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"predict_ds","NodeId":"-459"}],"OutputPortsInternal":[{"Name":"output_model","NodeId":"-459","OutputType":null},{"Name":"predictions","NodeId":"-459","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":12,"Comment":"","CommentCollapsed":true},{"Id":"-666","ModuleId":"BigQuantSpace.hyper_rolling_train.hyper_rolling_train-v1","ModuleParameters":[{"Name":"run","Value":"def bigquant_run(\n bq_graph,\n inputs,\n trading_days_market='CN', # 使用那个市场的交易日历, TODO\n train_instruments_mid1='m1', # 训练数据 证券代码列表 模块id\n train_instruments_mid2='m5', # 训练数据 证券代码列表 模块id\n test_instruments_mid='m9', # 测试数据 证券代码列表 模块id\n predict_mid='m25', # 预测 模块id\n trade_mid='m19', # 回测 模块id\n start_date='2015-01-01', # 数据开始日期\n end_date=T.live_run_param('trading_date', '2019-01-01'), # 数据结束日期\n train_update_days=250, # 更新周期,按交易日计算,每多少天更新一次\n train_update_days_for_live=None, #模拟实盘模式下的更新周期,按交易日计算,每多少天更新一次。如果需要在模拟实盘阶段使用不同的模型更新周期,可以设置这个参数\n train_data_min_days=250, # 最小数据天数,按交易日计算,所以第一个滚动的结束日期是 从开始日期到开始日期+最小数据天数\n train_data_max_days=250, # 最大数据天数,按交易日计算,0,表示没有限制,否则每一个滚动的开始日期=max(此滚动的结束日期-最大数据天数, 开始日期\n rolling_count_for_live=1, #实盘模式下滚动次数,模拟实盘模式下,取最后多少次滚动。一般在模拟实盘模式下,只用到最后一次滚动训练的模型,这里可以设置为1;如果你的滚动训练数据时间段很短,以至于期间可能没有训练数据,这里可以设置大一点。0表示没有限制\n):\n def merge_datasources(input_1):\n df_list = [ds.read_df() for ds in input_1]\n df = pd.concat(df_list)\n instrument_data = {\n 'start_date': df['date'].min().strftime('%Y-%m-%d'),\n 'end_date': df['date'].max().strftime('%Y-%m-%d'),\n 'instruments': list(set(df['instrument'])),\n }\n return Outputs(data=DataSource.write_df(df), instrument_data=DataSource.write_pickle(instrument_data))\n\n def gen_rolling_dates(trading_days_market, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live):\n # 是否实盘模式\n tdays = list(D.trading_days(market=trading_days_market, start_date=start_date, end_date=end_date)['date'])\n is_live_run = T.live_run_param('trading_date', None) is not None\n\n if is_live_run and train_update_days_for_live:\n train_update_days = train_update_days_for_live\n\n rollings = []\n train_end_date = train_data_min_days\n while train_end_date < len(tdays):\n if train_data_max_days is not None:\n train_start_date = max(train_end_date - train_data_max_days, 0)\n else:\n train_start_date = start_date\n rollings.append({\n 'train_start_date': tdays[train_start_date].strftime('%Y-%m-%d'),\n 'train_end_date': tdays[train_end_date - 1].strftime('%Y-%m-%d'),\n 'test_start_date': tdays[train_end_date].strftime('%Y-%m-%d'),\n 'test_end_date': tdays[min(train_end_date + train_update_days, len(tdays)) - 1].strftime('%Y-%m-%d'),\n })\n train_end_date += train_update_days\n\n if not rollings:\n raise Exception('没有滚动需要执行,请检查配置')\n\n if is_live_run and rolling_count_for_live:\n rollings = rollings[-rolling_count_for_live:]\n\n return rollings\n\n g = bq_graph\n\n rolling_dates = gen_rolling_dates(\n trading_days_market, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live)\n\n # 训练和预测\n results = []\n for rolling in rolling_dates:\n parameters = {}\n # 先禁用回测\n parameters[trade_mid + '.__enabled__'] = False\n parameters[train_instruments_mid1 + '.start_date'] = rolling['train_start_date']\n parameters[train_instruments_mid1 + '.end_date'] = rolling['train_end_date']\n parameters[train_instruments_mid2 + '.start_date'] = rolling['train_start_date']\n parameters[train_instruments_mid2 + '.end_date'] = rolling['train_end_date']\n parameters[test_instruments_mid + '.start_date'] = rolling['test_start_date']\n parameters[test_instruments_mid + '.end_date'] = rolling['test_end_date']\n print('------ rolling_train:', parameters)\n results.append(g.run(parameters))\n\n # 合并预测结果并回测\n mx = M.cached.v3(run=merge_datasources, input_1=[result[predict_mid].data_1 for result in results])\n parameters = {}\n parameters['*.__enabled__'] = False\n parameters[trade_mid + '.__enabled__'] = True\n parameters[trade_mid + '.instruments'] = mx.instrument_data\n parameters[trade_mid + '.options_data'] = mx.data\n\n trade = g.run(parameters)\n\n return {'rollings': results, 'trade': trade}\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":"-666"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-666"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-666"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-666"}],"OutputPortsInternal":[{"Name":"result","NodeId":"-666","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":23,"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='43,-179,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='38,-93,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='287,-313,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-43' Position='227,681,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='95,366,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='395,801,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='572.3189697265625,296,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='92.36199951171875,548,200,200'/><NodePosition Node='-86' Position='841,876,200,200'/><NodePosition Node='-351' Position='409,-99,200,200'/><NodePosition Node='-358' Position='100,155,200,200'/><NodePosition Node='-365' Position='776,412,200,200'/><NodePosition Node='-372' Position='873,524,200,200'/><NodePosition Node='-382' Position='766,1171,200,200'/><NodePosition Node='-506' Position='1311,-320,200,200'/><NodePosition Node='-518' Position='1545,-102,200,200'/><NodePosition Node='-532' Position='778,-40,200,200'/><NodePosition Node='-548' Position='1454,163,200,200'/><NodePosition Node='-555' Position='1463,374,200,200'/><NodePosition Node='-561' Position='1466,568,200,200'/><NodePosition Node='-595' Position='851,1058,200,200'/><NodePosition Node='-510' Position='1543,-193,200,200'/><NodePosition Node='-171' Position='546,-217,200,200'/><NodePosition Node='-8132' Position='1056,-219,200,200'/><NodePosition Node='-45' Position='391,-9,200,200'/><NodePosition Node='-9001' Position='107,260,200,200'/><NodePosition Node='-32' Position='414,111.36201477050781,200,200'/><NodePosition Node='-9453' Position='850,685,200,200'/><NodePosition Node='-175' Position='387,405,200,200'/><NodePosition Node='-9916' Position='1462,272,200,200'/><NodePosition Node='-9924' Position='1159,-13,200,200'/><NodePosition Node='-9932' Position='790,60,200,200'/><NodePosition Node='-10806' Position='779,168,200,200'/><NodePosition Node='-10814' Position='1157,108,200,200'/><NodePosition Node='-11798' Position='1158,425,200,200'/><NodePosition Node='-1348' Position='99,455,200,200'/><NodePosition Node='-12301' Position='1458,472,200,200'/><NodePosition Node='-12892' Position='820,772,200,200'/><NodePosition Node='-13369' Position='1157,-99,200,200'/><NodePosition Node='-459' Position='1327,977,200,200'/><NodePosition Node='-666' Position='1711.0682373046875,866.8436431884766,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 [54]:
        # 本代码由可视化策略环境自动生成 2019年1月30日 11:59
        # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
        
        
        # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
        def m11_run_bigquant_run(input_1, input_2, input_3):
            # 示例代码如下。在这里编写您的代码
            f1 = input_1.read_pickle()
            f2 = input_2.read_pickle()
            factors = [ k for k in set(f1 + f2)]
            data_1 = DataSource.write_pickle(factors)
            return Outputs(data_1=data_1, data_2=None, data_3=None)
        
        # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
        def m11_post_run_bigquant_run(outputs):
            return outputs
        
        # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
        def m35_run_bigquant_run(input_1, input_2, input_3):
            # 示例代码如下。在这里编写您的代码
            f1 = input_1.read_pickle()
            f2 = input_2.read_pickle()
            factors = [ k for k in set(f1 + f2)]
            data_1 = DataSource.write_pickle(factors)
            return Outputs(data_1=data_1, data_2=None, data_3=None)
        
        # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
        def m35_post_run_bigquant_run(outputs):
            return outputs
        
        # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
        def m36_run_bigquant_run(input_1, input_2, input_3):
            # 示例代码如下。在这里编写您的代码
            f1 = input_1.read_pickle()
            f2 = input_2.read_pickle()
            factors = [ k for k in set(f1 + f2)]
            data_1 = DataSource.write_pickle(factors)
            return Outputs(data_1=data_1, data_2=None, data_3=None)
        
        # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
        def m36_post_run_bigquant_run(outputs):
            return outputs
        
        # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
        def m25_run_bigquant_run(input_1, input_2, input_3):
            # 示例代码如下。在这里编写您的代码
            df1=input_1.read_df()
            df1_filter=df1.groupby('date',group_keys=False).apply(lambda x:x.sort_values('position')[:2]).reset_index(drop=True)
            df2=input_2.read_df()
            df2_filter=df2.groupby('date',group_keys=False).apply(lambda x:x.sort_values('classes_prob_0')[:2]).reset_index(drop=True)
            
            df=pd.merge(df1_filter,df2_filter,left_on=['date','instrument'],right_on=['date','instrument']).sort_values(['date','position'])
            
            data_1 = DataSource.write_df(df)
            return Outputs(data_1=data_1, data_2=None, data_3=None)
        
        # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
        def m25_post_run_bigquant_run(outputs):
            return outputs
        
        # 回测引擎:每日数据处理函数,每天执行一次
        def m19_handle_data_bigquant_run(context, data):
        
            # 获取今日的日期
            today = data.current_dt.strftime('%Y-%m-%d')  
            
            # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
            stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]      
            
            # 按日期过滤得到今日的预测数据,和买入备选股票列表
            ranker_prediction = context.ranker_prediction[
                context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
            stock_to_buy = list(ranker_prediction.instrument)
            
            # 需要卖出的股票:已有持仓中不在买入列表的股票
            stock_to_sell = [ i for i in stock_hold_now if i not in stock_to_buy]
            
            # 生成卖出订单:
            if len(stock_to_sell)>0:
                for instrument in stock_to_sell:
                    sid = context.symbol(instrument) # 将标的转化为equity格式
                    cur_position = context.portfolio.positions[sid].amount # 持仓
                    if cur_position > 0 and data.can_trade(sid):
                        context.order_target_percent(sid, 0) # 全部卖出   
            
            
            # 生成买入订单:买入每天两个策略前两名的股票
            if len(stock_to_buy)>0:
                if len(stock_to_buy)>0:
                    weight = 1/4 # 每只股票的比重为等资金比例持有1/4仓位
                    for instrument in stock_to_buy:
                        sid = context.symbol(instrument) # 将标的转化为equity格式
                        if  data.can_trade(sid):
                            context.order_target_percent(sid, weight) # 买入
        
        # 回测引擎:准备数据,只执行一次
        def m19_prepare_bigquant_run(context):
            pass
        
        # 回测引擎:初始化函数,只执行一次
        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
            # 每只的股票等资金分配
            context.stock_weights = [1/stock_count for i in range(4)]
        
        
        g = T.Graph({
        
            'm1': 'M.instruments.v2',
            'm1.start_date': '2010-01-01',
            'm1.end_date': '2015-01-01',
            'm1.market': 'CN_STOCK_A',
            'm1.instrument_list': '',
            'm1.max_count': 0,
        
            'm2': 'M.advanced_auto_labeler.v2',
            'm2.instruments': T.Graph.OutputPort('m1.data'),
            'm2.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, -2) / 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)
        """,
            'm2.start_date': '',
            'm2.end_date': '',
            'm2.benchmark': '000300.SHA',
            'm2.drop_na_label': True,
            'm2.cast_label_int': True,
        
            'm3': 'M.input_features.v1',
            'm3.features': """# #号开始的表示注释
        # 多个特征,每行一个,可以包含基础特征和衍生特征
        return_0
        return_4
        return_5""",
        
            'm26': 'M.input_features.v1',
            'm26.features_ds': T.Graph.OutputPort('m3.data'),
            'm26.features': """
        # #号开始的表示注释,注释需单独一行
        # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
        st_status_0
        return_90
        return_10
        return_80
        return_0
        high_0
        low_0
        close_0
        open_0
        
        
        """,
        
            'm15': 'M.general_feature_extractor.v7',
            'm15.instruments': T.Graph.OutputPort('m1.data'),
            'm15.features': T.Graph.OutputPort('m26.data'),
            'm15.start_date': '',
            'm15.end_date': '',
        
            'm32': 'M.input_features.v1',
            'm32.features_ds': T.Graph.OutputPort('m3.data'),
            'm32.features': """
        # 输入参与训练的自定义列
        
        ret1
        ret2
        ret3
        """,
        
            'm9': 'M.instruments.v2',
            'm9.start_date': T.live_run_param('trading_date', '2015-01-01'),
            'm9.end_date': T.live_run_param('trading_date', '2019-01-01'),
            'm9.market': 'CN_STOCK_A',
            'm9.instrument_list': '',
            'm9.max_count': 0,
        
            'm4': 'M.input_features.v1',
            'm4.features': """
        # #号开始的表示注释
        # 多个特征,每行一个,可以包含基础特征和衍生特征
        return_0
        return_4
        return_5""",
        
            'm27': 'M.input_features.v1',
            'm27.features_ds': T.Graph.OutputPort('m4.data'),
            'm27.features': """
        # #号开始的表示注释,注释需单独一行
        # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
        st_status_0
        return_90
        return_10
        return_80
        high_0
        low_0
        close_0
        open_0""",
        
            'm11': 'M.cached.v3',
            'm11.input_1': T.Graph.OutputPort('m26.data'),
            'm11.input_2': T.Graph.OutputPort('m27.data'),
            'm11.run': m11_run_bigquant_run,
            'm11.post_run': m11_post_run_bigquant_run,
            'm11.input_ports': '',
            'm11.params': '{}',
            'm11.output_ports': '',
        
            'm17': 'M.general_feature_extractor.v7',
            'm17.instruments': T.Graph.OutputPort('m9.data'),
            'm17.features': T.Graph.OutputPort('m11.data_1'),
            'm17.start_date': '',
            'm17.end_date': '',
        
            'm38': 'M.input_features.v1',
            'm38.features_ds': T.Graph.OutputPort('m4.data'),
            'm38.features': """
        # 输入参与训练的自定义列
        
        ret1
        ret2
        ret3
        """,
        
            'm5': 'M.instruments.v2',
            'm5.start_date': '2010-01-01',
            'm5.end_date': '2011-01-01',
            'm5.market': 'CN_STOCK_A',
            'm5.instrument_list': '',
            'm5.max_count': 0,
        
            'm10': 'M.advanced_auto_labeler.v2',
            'm10.instruments': T.Graph.OutputPort('m5.data'),
            'm10.label_expr': """
        
        # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
        where(shift(close, -2) / shift(open, -1)-1>0.01, 1, 0)
        
        # 极值处理:用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)
        """,
            'm10.start_date': '',
            'm10.end_date': '',
            'm10.benchmark': '000300.SHA',
            'm10.drop_na_label': True,
            'm10.cast_label_int': True,
            'm10.user_functions': {},
        
            'm42': 'M.general_feature_extractor.v7',
            'm42.instruments': T.Graph.OutputPort('m5.data'),
            'm42.features': T.Graph.OutputPort('m27.data'),
            'm42.start_date': '',
            'm42.end_date': '',
        
            'm28': 'M.input_features.v1',
            'm28.features': """
        # #号开始的表示注释,注释需单独一行
        # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
        mid=mean(close_0,14)
        atr=ta_atr(high_0, low_0, close_0, 14)
        ret1=return_90/return_10
        ret2=return_80/return_10
        ret3=return_5/return_0
        
        """,
        
            'm16': 'M.derived_feature_extractor.v3',
            'm16.input_data': T.Graph.OutputPort('m15.data'),
            'm16.features': T.Graph.OutputPort('m28.data'),
            'm16.date_col': 'date',
            'm16.instrument_col': 'instrument',
            'm16.drop_na': True,
            'm16.remove_extra_columns': False,
        
            'm30': 'M.input_features.v1',
            'm30.features': """
        # #号开始的表示注释,注释需单独一行
        # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
        cond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))
        """,
        
            'm29': 'M.derived_feature_extractor.v3',
            'm29.input_data': T.Graph.OutputPort('m16.data'),
            'm29.features': T.Graph.OutputPort('m30.data'),
            'm29.date_col': 'date',
            'm29.instrument_col': 'instrument',
            'm29.drop_na': True,
            'm29.remove_extra_columns': False,
        
            'm7': 'M.join.v3',
            'm7.data1': T.Graph.OutputPort('m2.data'),
            'm7.data2': T.Graph.OutputPort('m29.data'),
            'm7.on': 'date,instrument',
            'm7.how': 'inner',
            'm7.sort': False,
        
            'm39': 'M.filter.v3',
            'm39.input_data': T.Graph.OutputPort('m7.data'),
            'm39.expr': 'st_status_0 == 0 and cond2>0',
            'm39.output_left_data': False,
        
            'm13': 'M.dropnan.v1',
            'm13.input_data': T.Graph.OutputPort('m39.data'),
        
            'm6': 'M.stock_ranker_train.v5',
            'm6.training_ds': T.Graph.OutputPort('m13.data'),
            'm6.features': T.Graph.OutputPort('m32.data'),
            'm6.learning_algorithm': '排序',
            'm6.number_of_leaves': 30,
            'm6.minimum_docs_per_leaf': 1000,
            'm6.number_of_trees': 20,
            'm6.learning_rate': 0.1,
            'm6.max_bins': 1023,
            'm6.feature_fraction': 1,
            'm6.m_lazy_run': False,
        
            'm34': 'M.input_features.v1',
            'm34.features': """
        # #号开始的表示注释,注释需单独一行
        # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
        mid=mean(close_0,14)
        atr=ta_atr(high_0, low_0, close_0, 14)
        ret1=return_90/return_10
        ret2=return_80/return_10
        ret3=return_5/return_0
        
        """,
        
            'm20': 'M.derived_feature_extractor.v3',
            'm20.input_data': T.Graph.OutputPort('m42.data'),
            'm20.features': T.Graph.OutputPort('m34.data'),
            'm20.date_col': 'date',
            'm20.instrument_col': 'instrument',
            'm20.drop_na': True,
            'm20.remove_extra_columns': False,
            'm20.user_functions': {},
        
            'm35': 'M.cached.v3',
            'm35.input_1': T.Graph.OutputPort('m28.data'),
            'm35.input_2': T.Graph.OutputPort('m34.data'),
            'm35.run': m35_run_bigquant_run,
            'm35.post_run': m35_post_run_bigquant_run,
            'm35.input_ports': '',
            'm35.params': '{}',
            'm35.output_ports': '',
        
            'm18': 'M.derived_feature_extractor.v3',
            'm18.input_data': T.Graph.OutputPort('m17.data'),
            'm18.features': T.Graph.OutputPort('m35.data_1'),
            'm18.date_col': 'date',
            'm18.instrument_col': 'instrument',
            'm18.drop_na': True,
            'm18.remove_extra_columns': False,
        
            'm37': 'M.input_features.v1',
            'm37.features': """
        # #号开始的表示注释,注释需单独一行
        # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
        cond2=(close_0>atr+mid) & (shift(close_0, 1) < shift(atr+mid, 1))
        
        
        """,
        
            'm36': 'M.cached.v3',
            'm36.input_1': T.Graph.OutputPort('m30.data'),
            'm36.input_2': T.Graph.OutputPort('m37.data'),
            'm36.run': m36_run_bigquant_run,
            'm36.post_run': m36_post_run_bigquant_run,
            'm36.input_ports': '',
            'm36.params': '{}',
            'm36.output_ports': '',
        
            'm31': 'M.derived_feature_extractor.v3',
            'm31.input_data': T.Graph.OutputPort('m18.data'),
            'm31.features': T.Graph.OutputPort('m36.data_1'),
            'm31.date_col': 'date',
            'm31.instrument_col': 'instrument',
            'm31.drop_na': True,
            'm31.remove_extra_columns': False,
        
            'm41': 'M.filter.v3',
            'm41.input_data': T.Graph.OutputPort('m31.data'),
            'm41.expr': 'st_status_0 == 0 and cond2>0',
            'm41.output_left_data': False,
        
            'm14': 'M.dropnan.v1',
            'm14.input_data': T.Graph.OutputPort('m41.data'),
        
            'm8': 'M.stock_ranker_predict.v5',
            'm8.model': T.Graph.OutputPort('m6.model'),
            'm8.data': T.Graph.OutputPort('m14.data'),
            'm8.m_lazy_run': False,
        
            'm33': 'M.derived_feature_extractor.v3',
            'm33.input_data': T.Graph.OutputPort('m20.data'),
            'm33.features': T.Graph.OutputPort('m37.data'),
            'm33.date_col': 'date',
            'm33.instrument_col': 'instrument',
            'm33.drop_na': True,
            'm33.remove_extra_columns': False,
        
            'm21': 'M.join.v3',
            'm21.data1': T.Graph.OutputPort('m33.data'),
            'm21.data2': T.Graph.OutputPort('m10.data'),
            'm21.on': 'date,instrument',
            'm21.how': 'inner',
            'm21.sort': False,
        
            'm40': 'M.filter.v3',
            'm40.input_data': T.Graph.OutputPort('m21.data'),
            'm40.expr': 'st_status_0 == 0 and cond2>0',
            'm40.output_left_data': False,
        
            'm22': 'M.dropnan.v1',
            'm22.input_data': T.Graph.OutputPort('m40.data'),
        
            'm12': 'M.random_forest_classifier.v1',
            'm12.training_ds': T.Graph.OutputPort('m22.data'),
            'm12.features': T.Graph.OutputPort('m38.data'),
            'm12.predict_ds': T.Graph.OutputPort('m14.data'),
            'm12.iterations': 10,
            'm12.feature_fraction': 1,
            'm12.max_depth': 30,
            'm12.min_samples_per_leaf': 200,
            'm12.key_cols': 'date,instrument',
            'm12.workers': 2,
            'm12.other_train_parameters': {},
        
            'm25': 'M.cached.v3',
            'm25.input_1': T.Graph.OutputPort('m8.predictions'),
            'm25.input_2': T.Graph.OutputPort('m12.predictions'),
            'm25.run': m25_run_bigquant_run,
            'm25.post_run': m25_post_run_bigquant_run,
            'm25.input_ports': '',
            'm25.params': '{}',
            'm25.output_ports': '',
        
            'm19': 'M.trade.v4',
            'm19.instruments': T.Graph.OutputPort('m9.data'),
            'm19.options_data': T.Graph.OutputPort('m25.data_1'),
            'm19.start_date': '',
            'm19.end_date': '',
            'm19.handle_data': m19_handle_data_bigquant_run,
            'm19.prepare': m19_prepare_bigquant_run,
            'm19.initialize': m19_initialize_bigquant_run,
            'm19.volume_limit': 0.025,
            'm19.order_price_field_buy': 'open',
            'm19.order_price_field_sell': 'close',
            'm19.capital_base': 1000000,
            'm19.auto_cancel_non_tradable_orders': True,
            'm19.data_frequency': 'daily',
            'm19.price_type': '后复权',
            'm19.product_type': '股票',
            'm19.plot_charts': True,
            'm19.backtest_only': False,
            'm19.benchmark': '',
        })
        
        # g.run({})
        
        
        def m23_run_bigquant_run(
            bq_graph,
            inputs,
            trading_days_market='CN', # 使用那个市场的交易日历, TODO
            train_instruments_mid1='m1', # 训练数据 证券代码列表 模块id
            train_instruments_mid2='m5', # 训练数据 证券代码列表 模块id
            test_instruments_mid='m9', # 测试数据 证券代码列表 模块id
            predict_mid='m25', # 预测 模块id
            trade_mid='m19', # 回测 模块id
            start_date='2015-01-01', # 数据开始日期
            end_date=T.live_run_param('trading_date', '2019-01-01'), # 数据结束日期
            train_update_days=250, # 更新周期,按交易日计算,每多少天更新一次
            train_update_days_for_live=None, #模拟实盘模式下的更新周期,按交易日计算,每多少天更新一次。如果需要在模拟实盘阶段使用不同的模型更新周期,可以设置这个参数
            train_data_min_days=250, # 最小数据天数,按交易日计算,所以第一个滚动的结束日期是 从开始日期到开始日期+最小数据天数
            train_data_max_days=250, # 最大数据天数,按交易日计算,0,表示没有限制,否则每一个滚动的开始日期=max(此滚动的结束日期-最大数据天数, 开始日期
            rolling_count_for_live=1, #实盘模式下滚动次数,模拟实盘模式下,取最后多少次滚动。一般在模拟实盘模式下,只用到最后一次滚动训练的模型,这里可以设置为1;如果你的滚动训练数据时间段很短,以至于期间可能没有训练数据,这里可以设置大一点。0表示没有限制
        ):
            def merge_datasources(input_1):
                df_list = [ds.read_df() for ds in input_1]
                df = pd.concat(df_list)
                instrument_data = {
                    'start_date': df['date'].min().strftime('%Y-%m-%d'),
                    'end_date': df['date'].max().strftime('%Y-%m-%d'),
                    'instruments': list(set(df['instrument'])),
                }
                return Outputs(data=DataSource.write_df(df), instrument_data=DataSource.write_pickle(instrument_data))
        
            def gen_rolling_dates(trading_days_market, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live):
                # 是否实盘模式
                tdays = list(D.trading_days(market=trading_days_market, start_date=start_date, end_date=end_date)['date'])
                is_live_run = T.live_run_param('trading_date', None) is not None
        
                if is_live_run and train_update_days_for_live:
                    train_update_days = train_update_days_for_live
        
                rollings = []
                train_end_date = train_data_min_days
                while train_end_date < len(tdays):
                    if train_data_max_days is not None:
                        train_start_date = max(train_end_date - train_data_max_days, 0)
                    else:
                        train_start_date = start_date
                    rollings.append({
                        'train_start_date': tdays[train_start_date].strftime('%Y-%m-%d'),
                        'train_end_date': tdays[train_end_date - 1].strftime('%Y-%m-%d'),
                        'test_start_date': tdays[train_end_date].strftime('%Y-%m-%d'),
                        'test_end_date': tdays[min(train_end_date + train_update_days, len(tdays)) - 1].strftime('%Y-%m-%d'),
                    })
                    train_end_date += train_update_days
        
                if not rollings:
                    raise Exception('没有滚动需要执行,请检查配置')
        
                if is_live_run and rolling_count_for_live:
                    rollings = rollings[-rolling_count_for_live:]
        
                return rollings
        
            g = bq_graph
        
            rolling_dates = gen_rolling_dates(
                trading_days_market, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live)
        
            # 训练和预测
            results = []
            for rolling in rolling_dates:
                parameters = {}
                # 先禁用回测
                parameters[trade_mid + '.__enabled__'] = False
                parameters[train_instruments_mid1 + '.start_date'] = rolling['train_start_date']
                parameters[train_instruments_mid1 + '.end_date'] = rolling['train_end_date']
                parameters[train_instruments_mid2 + '.start_date'] = rolling['train_start_date']
                parameters[train_instruments_mid2 + '.end_date'] = rolling['train_end_date']
                parameters[test_instruments_mid + '.start_date'] = rolling['test_start_date']
                parameters[test_instruments_mid + '.end_date'] = rolling['test_end_date']
                print('------ rolling_train:', parameters)
                results.append(g.run(parameters))
        
            # 合并预测结果并回测
            mx = M.cached.v3(run=merge_datasources, input_1=[result[predict_mid].data_1 for result in results])
            parameters = {}
            parameters['*.__enabled__'] = False
            parameters[trade_mid + '.__enabled__'] = True
            parameters[trade_mid + '.instruments'] = mx.instrument_data
            parameters[trade_mid + '.options_data'] = mx.data
        
            trade = g.run(parameters)
        
            return {'rollings': results, 'trade': trade}
        
        
        m23 = M.hyper_rolling_train.v1(
            run=m23_run_bigquant_run,
            run_now=True,
            bq_graph=g
        )
        
        ------ rolling_train: {'m19.__enabled__': False, 'm1.end_date': '2016-01-11', 'm5.start_date': '2015-01-05', 'm9.end_date': '2017-01-18', 'm5.end_date': '2016-01-11', 'm9.start_date': '2016-01-12', 'm1.start_date': '2015-01-05'}
        [2019-01-30 11:59:22.581066] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:22.585986] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.586902] INFO: bigquant: instruments.v2 运行完成[0.005884s].
        [2019-01-30 11:59:22.588668] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.592298] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.593120] INFO: bigquant: input_features.v1 运行完成[0.004454s].
        [2019-01-30 11:59:22.595020] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:22.599152] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.599965] INFO: bigquant: instruments.v2 运行完成[0.00496s].
        [2019-01-30 11:59:22.601480] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.605419] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.606245] INFO: bigquant: input_features.v1 运行完成[0.004759s].
        [2019-01-30 11:59:22.608327] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.611957] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.612660] INFO: bigquant: input_features.v1 运行完成[0.00433s].
        [2019-01-30 11:59:22.614732] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.618311] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.618999] INFO: bigquant: input_features.v1 运行完成[0.004273s].
        [2019-01-30 11:59:22.621143] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:22.624790] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.625495] INFO: bigquant: instruments.v2 运行完成[0.004351s].
        [2019-01-30 11:59:22.627277] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.631044] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.631749] INFO: bigquant: input_features.v1 运行完成[0.00446s].
        [2019-01-30 11:59:22.633464] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.637514] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.638388] INFO: bigquant: input_features.v1 运行完成[0.00491s].
        [2019-01-30 11:59:22.641165] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
        [2019-01-30 11:59:22.652556] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.653844] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.012688s].
        [2019-01-30 11:59:22.656334] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
        [2019-01-30 11:59:22.660745] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.661753] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.005411s].
        [2019-01-30 11:59:22.664698] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:22.668929] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.669645] INFO: bigquant: cached.v3 运行完成[0.004949s].
        [2019-01-30 11:59:22.671430] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.675372] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.676149] INFO: bigquant: input_features.v1 运行完成[0.004701s].
        [2019-01-30 11:59:22.678168] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.682553] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.683385] INFO: bigquant: input_features.v1 运行完成[0.005208s].
        [2019-01-30 11:59:22.685608] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.689554] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.690295] INFO: bigquant: input_features.v1 运行完成[0.004692s].
        [2019-01-30 11:59:22.692426] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.696097] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.696935] INFO: bigquant: input_features.v1 运行完成[0.004506s].
        [2019-01-30 11:59:22.699997] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:22.703556] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.704258] INFO: bigquant: cached.v3 运行完成[0.004272s].
        [2019-01-30 11:59:22.709570] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:22.713668] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.714426] INFO: bigquant: general_feature_extractor.v7 运行完成[0.004868s].
        [2019-01-30 11:59:22.718835] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:22.722790] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.723936] INFO: bigquant: general_feature_extractor.v7 运行完成[0.005086s].
        [2019-01-30 11:59:22.726857] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:22.745693] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.752684] INFO: bigquant: cached.v3 运行完成[0.025768s].
        [2019-01-30 11:59:22.755772] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:22.760511] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.761562] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.005823s].
        [2019-01-30 11:59:22.763438] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:22.767109] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.767846] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004405s].
        [2019-01-30 11:59:22.773160] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:22.776850] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.777542] INFO: bigquant: general_feature_extractor.v7 运行完成[0.004381s].
        [2019-01-30 11:59:22.779797] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:22.783111] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.783864] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004065s].
        [2019-01-30 11:59:22.785505] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:22.789272] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.790337] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004823s].
        [2019-01-30 11:59:22.792316] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:22.795761] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.796612] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004293s].
        [2019-01-30 11:59:22.798818] INFO: bigquant: join.v3 开始运行..
        [2019-01-30 11:59:22.802558] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.803447] INFO: bigquant: join.v3 运行完成[0.004618s].
        [2019-01-30 11:59:22.805671] INFO: bigquant: join.v3 开始运行..
        [2019-01-30 11:59:22.809471] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.810246] INFO: bigquant: join.v3 运行完成[0.004578s].
        [2019-01-30 11:59:22.812620] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:22.816218] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.816937] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004313s].
        [2019-01-30 11:59:22.818982] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:22.822259] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.823064] INFO: bigquant: filter.v3 运行完成[0.004078s].
        [2019-01-30 11:59:22.824757] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:22.828260] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.829113] INFO: bigquant: filter.v3 运行完成[0.004369s].
        [2019-01-30 11:59:22.831075] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:22.834457] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.835324] INFO: bigquant: filter.v3 运行完成[0.004257s].
        [2019-01-30 11:59:22.837251] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:22.852916] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.854134] INFO: bigquant: dropnan.v1 运行完成[0.016858s].
        [2019-01-30 11:59:22.856691] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:22.861108] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.861845] INFO: bigquant: dropnan.v1 运行完成[0.005154s].
        [2019-01-30 11:59:22.864095] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:22.867995] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.868750] INFO: bigquant: dropnan.v1 运行完成[0.00465s].
        [2019-01-30 11:59:22.870977] INFO: bigquant: stock_ranker_train.v5 开始运行..
        [2019-01-30 11:59:22.876189] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.877370] INFO: bigquant: stock_ranker_train.v5 运行完成[0.006386s].
        [2019-01-30 11:59:22.879544] INFO: bigquant: random_forest_classifier.v1 开始运行..
        [2019-01-30 11:59:22.885003] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.886167] INFO: bigquant: random_forest_classifier.v1 运行完成[0.006618s].
        [2019-01-30 11:59:22.888608] INFO: bigquant: stock_ranker_predict.v5 开始运行..
        [2019-01-30 11:59:22.896779] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.898080] INFO: bigquant: stock_ranker_predict.v5 运行完成[0.009493s].
        [2019-01-30 11:59:22.901313] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:22.904763] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.905610] INFO: bigquant: cached.v3 运行完成[0.004295s].
        ------ rolling_train: {'m19.__enabled__': False, 'm1.end_date': '2017-01-18', 'm5.start_date': '2016-01-12', 'm9.end_date': '2018-01-25', 'm5.end_date': '2017-01-18', 'm9.start_date': '2017-01-19', 'm1.start_date': '2016-01-12'}
        [2019-01-30 11:59:22.909768] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:22.913296] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.914054] INFO: bigquant: instruments.v2 运行完成[0.004266s].
        [2019-01-30 11:59:22.916092] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.919484] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.920253] INFO: bigquant: input_features.v1 运行完成[0.004168s].
        [2019-01-30 11:59:22.921893] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:22.926385] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.927122] INFO: bigquant: instruments.v2 运行完成[0.005232s].
        [2019-01-30 11:59:22.928827] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.933005] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.933908] INFO: bigquant: input_features.v1 运行完成[0.005073s].
        [2019-01-30 11:59:22.935882] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.939318] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.940172] INFO: bigquant: input_features.v1 运行完成[0.004269s].
        [2019-01-30 11:59:22.943334] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.950507] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.952130] INFO: bigquant: input_features.v1 运行完成[0.008816s].
        [2019-01-30 11:59:22.954445] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:22.958640] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.959520] INFO: bigquant: instruments.v2 运行完成[0.005077s].
        [2019-01-30 11:59:22.961261] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.964672] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.965480] INFO: bigquant: input_features.v1 运行完成[0.004222s].
        [2019-01-30 11:59:22.967306] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.970553] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.971297] INFO: bigquant: input_features.v1 运行完成[0.004001s].
        [2019-01-30 11:59:22.973026] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
        [2019-01-30 11:59:22.976508] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.977499] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.004484s].
        [2019-01-30 11:59:22.979744] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
        [2019-01-30 11:59:22.983455] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.984418] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.004694s].
        [2019-01-30 11:59:22.987490] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:22.991209] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.992054] INFO: bigquant: cached.v3 运行完成[0.004533s].
        [2019-01-30 11:59:22.994121] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:22.997769] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:22.998562] INFO: bigquant: input_features.v1 运行完成[0.004436s].
        [2019-01-30 11:59:23.000672] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.004096] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.004839] INFO: bigquant: input_features.v1 运行完成[0.004178s].
        [2019-01-30 11:59:23.006258] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.009594] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.010499] INFO: bigquant: input_features.v1 运行完成[0.004242s].
        [2019-01-30 11:59:23.012051] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.015246] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.015859] INFO: bigquant: input_features.v1 运行完成[0.003848s].
        [2019-01-30 11:59:23.018243] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.021650] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.022320] INFO: bigquant: cached.v3 运行完成[0.00408s].
        [2019-01-30 11:59:23.026567] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:23.030001] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.030703] INFO: bigquant: general_feature_extractor.v7 运行完成[0.004137s].
        [2019-01-30 11:59:23.034959] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:23.040257] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.041788] INFO: bigquant: general_feature_extractor.v7 运行完成[0.006791s].
        [2019-01-30 11:59:23.046188] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.054984] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.056124] INFO: bigquant: cached.v3 运行完成[0.009966s].
        [2019-01-30 11:59:23.058355] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.062384] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.063160] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004801s].
        [2019-01-30 11:59:23.065267] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.068804] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.069741] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004465s].
        [2019-01-30 11:59:23.077148] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:23.080870] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.081663] INFO: bigquant: general_feature_extractor.v7 运行完成[0.004511s].
        [2019-01-30 11:59:23.083892] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.088046] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.089096] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.005194s].
        [2019-01-30 11:59:23.091205] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.095105] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.095835] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004628s].
        [2019-01-30 11:59:23.097963] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.101604] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.102953] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004977s].
        [2019-01-30 11:59:23.105144] INFO: bigquant: join.v3 开始运行..
        [2019-01-30 11:59:23.108670] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.109540] INFO: bigquant: join.v3 运行完成[0.004392s].
        [2019-01-30 11:59:23.111352] INFO: bigquant: join.v3 开始运行..
        [2019-01-30 11:59:23.114967] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.115792] INFO: bigquant: join.v3 运行完成[0.004435s].
        [2019-01-30 11:59:23.117672] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.121321] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.122083] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004412s].
        [2019-01-30 11:59:23.124079] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:23.127596] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.128352] INFO: bigquant: filter.v3 运行完成[0.004277s].
        [2019-01-30 11:59:23.130381] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:23.133694] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.134574] INFO: bigquant: filter.v3 运行完成[0.00418s].
        [2019-01-30 11:59:23.136603] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:23.143559] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.145579] INFO: bigquant: filter.v3 运行完成[0.008919s].
        [2019-01-30 11:59:23.148793] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:23.154365] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.155250] INFO: bigquant: dropnan.v1 运行完成[0.006504s].
        [2019-01-30 11:59:23.157306] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:23.161116] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.161976] INFO: bigquant: dropnan.v1 运行完成[0.004664s].
        [2019-01-30 11:59:23.164145] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:23.167645] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.168448] INFO: bigquant: dropnan.v1 运行完成[0.004304s].
        [2019-01-30 11:59:23.170694] INFO: bigquant: stock_ranker_train.v5 开始运行..
        [2019-01-30 11:59:23.175790] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.176890] INFO: bigquant: stock_ranker_train.v5 运行完成[0.006191s].
        [2019-01-30 11:59:23.178979] INFO: bigquant: random_forest_classifier.v1 开始运行..
        [2019-01-30 11:59:23.184277] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.185359] INFO: bigquant: random_forest_classifier.v1 运行完成[0.006378s].
        [2019-01-30 11:59:23.187347] INFO: bigquant: stock_ranker_predict.v5 开始运行..
        [2019-01-30 11:59:23.193959] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.195050] INFO: bigquant: stock_ranker_predict.v5 运行完成[0.007679s].
        [2019-01-30 11:59:23.198519] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.202222] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.202922] INFO: bigquant: cached.v3 运行完成[0.004403s].
        ------ rolling_train: {'m19.__enabled__': False, 'm1.end_date': '2018-01-25', 'm5.start_date': '2017-01-19', 'm9.end_date': '2018-12-28', 'm5.end_date': '2018-01-25', 'm9.start_date': '2018-01-26', 'm1.start_date': '2017-01-19'}
        [2019-01-30 11:59:23.207402] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:23.211572] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.212433] INFO: bigquant: instruments.v2 运行完成[0.005027s].
        [2019-01-30 11:59:23.214502] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.217927] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.218841] INFO: bigquant: input_features.v1 运行完成[0.004337s].
        [2019-01-30 11:59:23.220757] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:23.224325] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.225039] INFO: bigquant: instruments.v2 运行完成[0.004274s].
        [2019-01-30 11:59:23.227004] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.230475] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.231398] INFO: bigquant: input_features.v1 运行完成[0.004371s].
        [2019-01-30 11:59:23.233328] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.246470] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.249233] INFO: bigquant: input_features.v1 运行完成[0.015872s].
        [2019-01-30 11:59:23.252317] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.257072] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.258036] INFO: bigquant: input_features.v1 运行完成[0.005713s].
        [2019-01-30 11:59:23.259996] INFO: bigquant: instruments.v2 开始运行..
        [2019-01-30 11:59:23.263585] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.264376] INFO: bigquant: instruments.v2 运行完成[0.004375s].
        [2019-01-30 11:59:23.266466] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.269862] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.270737] INFO: bigquant: input_features.v1 运行完成[0.00426s].
        [2019-01-30 11:59:23.272986] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.276400] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.277100] INFO: bigquant: input_features.v1 运行完成[0.004118s].
        [2019-01-30 11:59:23.279469] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
        [2019-01-30 11:59:23.282781] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.283627] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.004152s].
        [2019-01-30 11:59:23.285974] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
        [2019-01-30 11:59:23.289340] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.290258] INFO: bigquant: advanced_auto_labeler.v2 运行完成[0.004279s].
        [2019-01-30 11:59:23.293069] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.297610] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.298369] INFO: bigquant: cached.v3 运行完成[0.005325s].
        [2019-01-30 11:59:23.300454] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.303828] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.304641] INFO: bigquant: input_features.v1 运行完成[0.004183s].
        [2019-01-30 11:59:23.306749] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.310272] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.310948] INFO: bigquant: input_features.v1 运行完成[0.004205s].
        [2019-01-30 11:59:23.312626] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.316272] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.317005] INFO: bigquant: input_features.v1 运行完成[0.004374s].
        [2019-01-30 11:59:23.319034] INFO: bigquant: input_features.v1 开始运行..
        [2019-01-30 11:59:23.322576] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.323296] INFO: bigquant: input_features.v1 运行完成[0.004281s].
        [2019-01-30 11:59:23.326288] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.329624] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.330342] INFO: bigquant: cached.v3 运行完成[0.004053s].
        [2019-01-30 11:59:23.335084] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:23.339024] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.339870] INFO: bigquant: general_feature_extractor.v7 运行完成[0.004783s].
        [2019-01-30 11:59:23.346007] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:23.351830] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.352807] INFO: bigquant: general_feature_extractor.v7 运行完成[0.006823s].
        [2019-01-30 11:59:23.355886] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.359956] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.360769] INFO: bigquant: cached.v3 运行完成[0.004869s].
        [2019-01-30 11:59:23.362574] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.366201] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.366969] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004394s].
        [2019-01-30 11:59:23.368900] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.372101] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.372828] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.003928s].
        [2019-01-30 11:59:23.377196] INFO: bigquant: general_feature_extractor.v7 开始运行..
        [2019-01-30 11:59:23.380558] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.381217] INFO: bigquant: general_feature_extractor.v7 运行完成[0.004026s].
        [2019-01-30 11:59:23.382805] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.386195] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.386862] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.00406s].
        [2019-01-30 11:59:23.388755] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.391897] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.392609] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.003864s].
        [2019-01-30 11:59:23.394573] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.397948] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.398623] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004049s].
        [2019-01-30 11:59:23.400301] INFO: bigquant: join.v3 开始运行..
        [2019-01-30 11:59:23.403976] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.404666] INFO: bigquant: join.v3 运行完成[0.004366s].
        [2019-01-30 11:59:23.406279] INFO: bigquant: join.v3 开始运行..
        [2019-01-30 11:59:23.409931] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.411187] INFO: bigquant: join.v3 运行完成[0.004903s].
        [2019-01-30 11:59:23.413159] INFO: bigquant: derived_feature_extractor.v3 开始运行..
        [2019-01-30 11:59:23.416631] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.417404] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.00424s].
        [2019-01-30 11:59:23.419262] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:23.423504] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.424170] INFO: bigquant: filter.v3 运行完成[0.004902s].
        [2019-01-30 11:59:23.426120] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:23.429401] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.430068] INFO: bigquant: filter.v3 运行完成[0.003926s].
        [2019-01-30 11:59:23.431628] INFO: bigquant: filter.v3 开始运行..
        [2019-01-30 11:59:23.435895] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.436856] INFO: bigquant: filter.v3 运行完成[0.00522s].
        [2019-01-30 11:59:23.441121] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:23.452366] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.453347] INFO: bigquant: dropnan.v1 运行完成[0.012241s].
        [2019-01-30 11:59:23.455452] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:23.459437] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.460168] INFO: bigquant: dropnan.v1 运行完成[0.004723s].
        [2019-01-30 11:59:23.462186] INFO: bigquant: dropnan.v1 开始运行..
        [2019-01-30 11:59:23.465732] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.466698] INFO: bigquant: dropnan.v1 运行完成[0.004513s].
        [2019-01-30 11:59:23.468791] INFO: bigquant: stock_ranker_train.v5 开始运行..
        [2019-01-30 11:59:23.474267] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.475309] INFO: bigquant: stock_ranker_train.v5 运行完成[0.006516s].
        [2019-01-30 11:59:23.477406] INFO: bigquant: random_forest_classifier.v1 开始运行..
        [2019-01-30 11:59:23.482715] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.483713] INFO: bigquant: random_forest_classifier.v1 运行完成[0.0063s].
        [2019-01-30 11:59:23.486145] INFO: bigquant: stock_ranker_predict.v5 开始运行..
        [2019-01-30 11:59:23.492989] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.494048] INFO: bigquant: stock_ranker_predict.v5 运行完成[0.007884s].
        [2019-01-30 11:59:23.497428] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.500831] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.501658] INFO: bigquant: cached.v3 运行完成[0.004227s].
        [2019-01-30 11:59:23.504424] INFO: bigquant: cached.v3 开始运行..
        [2019-01-30 11:59:23.510717] INFO: bigquant: 命中缓存
        [2019-01-30 11:59:23.511522] INFO: bigquant: cached.v3 运行完成[0.007092s].
        [2019-01-30 11:59:23.527414] INFO: bigquant: backtest.v8 开始运行..
        [2019-01-30 11:59:23.532171] INFO: bigquant: 命中缓存
        
        • 收益率51.45%
        • 年化收益率14.65%
        • 基准收益率-19.64%
        • 阿尔法0.13
        • 贝塔0.15
        • 夏普比率1.05
        • 胜率0.57
        • 盈亏比1.47
        • 收益波动率10.76%
        • 信息比率0.06
        • 最大回撤11.61%
        [2019-01-30 11:59:24.524626] INFO: bigquant: backtest.v8 运行完成[0.997207s].
        

        (tkyz) #9

        好的,感谢