{"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"to_node_id":"-106:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data1","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:data"},{"to_node_id":"-106:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-113:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-122:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-129:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-690:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-967:input_1","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"to_node_id":"-122:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-141:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-113:input_data","from_node_id":"-106:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","from_node_id":"-113:data"},{"to_node_id":"-129:input_data","from_node_id":"-122:data"},{"to_node_id":"-1277:input_1","from_node_id":"-129:data"},{"to_node_id":"-690:training_ds","from_node_id":"-47836:data"},{"to_node_id":"-690:predict_ds","from_node_id":"-47840:data"},{"to_node_id":"-47836:input_data","from_node_id":"-967:data_1"},{"to_node_id":"-47840:input_data","from_node_id":"-1277:data_1"},{"to_node_id":"-141:options_data","from_node_id":"-690:predictions"}],"nodes":[{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2010-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2015-1-01","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","module_id":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","parameters":[{"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","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.SHA","type":"Literal","bound_global_parameter":null},{"name":"drop_na_label","value":"True","type":"Literal","bound_global_parameter":null},{"name":"cast_label_int","value":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"return_5\nreturn_10\nreturn_20\navg_amount_5/avg_amount_10\nreturn_5/return_10\nta_cci_14_0\nturn_5/avg_turn_10\navg_amount_0/avg_amount_5\nswing_volatility_5_0/swing_volatility_60_0\namount_10/amount_30\nrank_volatility_10_0\nreturn_0\nta_ema_5_0/close_0\nclose_0/low_0\nta_ema_20_0/close_0\nopen_0/close_1\nhigh_1/close_0\nta_ema_30_0/close_0\nta_rsi(close_0, 6)\namount_0/amount_1\n# return_1","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"how","value":"inner","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"},{"name":"data2","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2015-01-01","type":"Literal","bound_global_parameter":"交易日期"},{"name":"end_date","value":"2021-08-20","type":"Literal","bound_global_parameter":"交易日期"},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"cacheable":true,"seq_num":9,"comment":"预测数据,用于回测和模拟","comment_collapsed":true},{"node_id":"-106","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-106"},{"name":"features","node_id":"-106"}],"output_ports":[{"name":"data","node_id":"-106"}],"cacheable":true,"seq_num":15,"comment":"","comment_collapsed":true},{"node_id":"-113","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-113"},{"name":"features","node_id":"-113"}],"output_ports":[{"name":"data","node_id":"-113"}],"cacheable":true,"seq_num":16,"comment":"","comment_collapsed":true},{"node_id":"-122","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"90","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-122"},{"name":"features","node_id":"-122"}],"output_ports":[{"name":"data","node_id":"-122"}],"cacheable":true,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"-129","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-129"},{"name":"features","node_id":"-129"}],"output_ports":[{"name":"data","node_id":"-129"}],"cacheable":true,"seq_num":18,"comment":"","comment_collapsed":true},{"node_id":"-141","module_id":"BigQuantSpace.trade.trade-v4","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":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 # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]\n context.stock_weights = [1 / stock_count for i in range(0, stock_count)]\n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 1\n context.options['hold_days'] = 1\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\n\n # 1. 资金分配\n # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金\n # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)\n is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)\n cash_avg = context.portfolio.portfolio_value / context.options['hold_days']\n cash_for_buy = min(context.portfolio.cash, (1 if is_staging else 1.5) * cash_avg)\n cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)\n positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items()}\n\n # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰\n if not is_staging and cash_for_sell > 0:\n equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}\n tmp = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(\n lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))\n instruments = equities\n# # print('rank order for sell %s' % instruments)\n for instrument in instruments:\n# if instrument in tmp:\n# print(\"涨停,不卖出\",instrument)\n# continue\n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n if cash_for_sell <= 0:\n break\n\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])\n max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument\n for i, instrument in enumerate(buy_instruments):\n cash = cash_for_buy * buy_cash_weights[i]\n if cash > max_cash_per_instrument - positions.get(instrument, 0):\n # 确保股票持仓量不会超过每次股票最大的占用资金量\n cash = max_cash_per_instrument - positions.get(instrument, 0)\n if cash > 0:\n \n context.order_value(context.symbol(instrument), cash)\n","type":"Literal","bound_global_parameter":null},{"name":"prepare","value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"","type":"Literal","bound_global_parameter":null},{"name":"volume_limit","value":"0.025","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_buy","value":"open","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_sell","value":"open","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":"12000","type":"Literal","bound_global_parameter":null},{"name":"auto_cancel_non_tradable_orders","value":"True","type":"Literal","bound_global_parameter":null},{"name":"data_frequency","value":"daily","type":"Literal","bound_global_parameter":null},{"name":"price_type","value":"真实价格","type":"Literal","bound_global_parameter":null},{"name":"product_type","value":"股票","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.SHA","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-141"},{"name":"options_data","node_id":"-141"},{"name":"history_ds","node_id":"-141"},{"name":"benchmark_ds","node_id":"-141"},{"name":"trading_calendar","node_id":"-141"}],"output_ports":[{"name":"raw_perf","node_id":"-141"}],"cacheable":false,"seq_num":19,"comment":"","comment_collapsed":true},{"node_id":"-47836","module_id":"BigQuantSpace.dropnan.dropnan-v2","parameters":[],"input_ports":[{"name":"input_data","node_id":"-47836"},{"name":"features","node_id":"-47836"}],"output_ports":[{"name":"data","node_id":"-47836"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-47840","module_id":"BigQuantSpace.dropnan.dropnan-v2","parameters":[],"input_ports":[{"name":"input_data","node_id":"-47840"},{"name":"features","node_id":"-47840"}],"output_ports":[{"name":"data","node_id":"-47840"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-967","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read_df()\n ins = m1.data.read_pickle()['instruments']\n start = m1.data.read_pickle()['start_date']\n end = m1.data.read_pickle()['end_date']\n \n df1 = D.features(ins,start,end,fields=['rank_turn_0','rank_amount_0','st_status_0'])\n df_final = pd.merge(df,df1,on=['date','instrument'])\n df_final = df_final[df_final['instrument'].str.startswith(\"688\") == False]\n df_final = df_final[df_final['instrument'].str.startswith(\"3\") == False]\n\n df_final = df_final[df_final[\"st_status_0\"] == 0]\n df_final = df_final[df_final['rank_turn_0'] >= 0.9]\n df_final = df_final[df_final['rank_amount_0'] >= 0.85]\n print(\"用于训练的样本总个数为\",len(df_final))\n print(df_final.iloc[0])\n data_1 = DataSource.write_df(df_final)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-967"},{"name":"input_2","node_id":"-967"},{"name":"input_3","node_id":"-967"}],"output_ports":[{"name":"data_1","node_id":"-967"},{"name":"data_2","node_id":"-967"},{"name":"data_3","node_id":"-967"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-1277","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read_df()\n ins = m9.data.read_pickle()['instruments']\n start = m9.data.read_pickle()['start_date']\n end = m9.data.read_pickle()['end_date']\n \n df1 = D.features(ins,start,end,fields=['rank_turn_0','rank_amount_0','st_status_0'])\n df_final = pd.merge(df,df1,on=['date','instrument'])\n df_final = df_final[df_final['instrument'].str.startswith(\"688\") == False]\n df_final = df_final[df_final['instrument'].str.startswith(\"3\") == False]\n\n df_final = df_final[df_final[\"st_status_0\"] == 0]\n df_final = df_final[df_final['rank_turn_0'] >= 0.9]\n df_final = df_final[df_final['rank_amount_0'] >= 0.85]\n print(\"用于回测的样本总个数为\",len(df_final))\n data_1 = DataSource.write_df(df_final)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-1277"},{"name":"input_2","node_id":"-1277"},{"name":"input_3","node_id":"-1277"}],"output_ports":[{"name":"data_1","node_id":"-1277"},{"name":"data_2","node_id":"-1277"},{"name":"data_3","node_id":"-1277"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-690","module_id":"BigQuantSpace.lightgbm.lightgbm-v2","parameters":[{"name":"num_boost_round","value":"79","type":"Literal","bound_global_parameter":null},{"name":"objective","value":"排序(ndcg)","type":"Literal","bound_global_parameter":null},{"name":"num_class","value":"1","type":"Literal","bound_global_parameter":null},{"name":"num_leaves","value":"60","type":"Literal","bound_global_parameter":null},{"name":"learning_rate","value":"0.1","type":"Literal","bound_global_parameter":null},{"name":"min_data_in_leaf","value":"900","type":"Literal","bound_global_parameter":null},{"name":"max_bin","value":"1023","type":"Literal","bound_global_parameter":null},{"name":"key_cols","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"group_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"random_seed","value":"101","type":"Literal","bound_global_parameter":null},{"name":"other_train_parameters","value":"{'n_jobs':4,'label_gain':','.join([str(x) for x in range(20)]),\"max_position\":29,\"eval_at\":\"1,3,5,10\"}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"training_ds","node_id":"-690"},{"name":"features","node_id":"-690"},{"name":"model","node_id":"-690"},{"name":"predict_ds","node_id":"-690"}],"output_ports":[{"name":"output_model","node_id":"-690"},{"name":"predictions","node_id":"-690"},{"name":"feature_gains","node_id":"-690"}],"cacheable":true,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"-207","module_id":"BigQuantSpace.hyper_rolling_train.hyper_rolling_train-v1","parameters":[{"name":"run","value":"def bigquant_run(\n bq_graph,\n inputs,\n trading_days_market='CN', # 使用那个市场的交易日历, TODO\n train_instruments_mid='m1', # 训练数据 证券代码列表 模块id\n test_instruments_mid='m9', # 测试数据 证券代码列表 模块id\n predict_mid='m10', # 预测 模块id\n trade_mid='m19', # 回测 模块id\n start_date='2015-01-01', # 数据开始日期\n end_date=T.live_run_param('trading_date', '2021-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[0].read_df().set_index('date').loc[ds[1]:].reset_index() 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 and train_data_max_days > 0:\n train_start_date = max(train_end_date - train_data_max_days, 0)\n else:\n train_start_date = 0\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_mid + '.start_date'] = rolling['train_start_date']\n parameters[train_instruments_mid + '.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].predictions, result[test_instruments_mid].data.read_pickle()['start_date']] 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","type":"Literal","bound_global_parameter":null},{"name":"run_now","value":"True","type":"Literal","bound_global_parameter":null},{"name":"bq_graph","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"bq_graph_port","node_id":"-207"},{"name":"input_1","node_id":"-207"},{"name":"input_2","node_id":"-207"},{"name":"input_3","node_id":"-207"}],"output_ports":[{"name":"result","node_id":"-207"}],"cacheable":false,"seq_num":11,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='215,66,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='70,183,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='706,-22,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='249,375,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1075,123,200,200'/><node_position Node='-106' Position='381,188,200,200'/><node_position Node='-113' Position='385,280,200,200'/><node_position Node='-122' Position='1078,236,200,200'/><node_position Node='-129' Position='1081,327,200,200'/><node_position Node='-141' Position='1069,944,200,200'/><node_position Node='-47836' Position='344,643,200,200'/><node_position Node='-47840' Position='1084,615,200,200'/><node_position Node='-967' Position='224,520,200,200'/><node_position Node='-1277' Position='1189,477,200,200'/><node_position Node='-690' Position='521,818,200,200'/><node_position Node='-207' Position='126.966552734375,979.3076782226562,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2021-10-29 11:21:57.733172] INFO: moduleinvoker: instruments.v2 开始运行..
[2021-10-29 11:21:57.812574] INFO: moduleinvoker: instruments.v2 运行完成[0.079403s].
[2021-10-29 11:21:57.816973] INFO: moduleinvoker: input_features.v1 开始运行..
[2021-10-29 11:21:57.828563] INFO: moduleinvoker: 命中缓存
[2021-10-29 11:21:57.830440] INFO: moduleinvoker: input_features.v1 运行完成[0.013528s].
[2021-10-29 11:21:57.835380] INFO: moduleinvoker: instruments.v2 开始运行..
[2021-10-29 11:21:57.909874] INFO: moduleinvoker: instruments.v2 运行完成[0.074467s].
[2021-10-29 11:21:57.922075] INFO: moduleinvoker: advanced_auto_labeler.v2 开始运行..
[2021-10-29 11:21:58.558345] INFO: 自动标注(股票): 加载历史数据: 584988 行
[2021-10-29 11:21:58.560461] INFO: 自动标注(股票): 开始标注 ..
[2021-10-29 11:21:59.502369] INFO: moduleinvoker: advanced_auto_labeler.v2 运行完成[1.580298s].
[2021-10-29 11:21:59.519134] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2021-10-29 11:22:09.921251] INFO: 基础特征抽取: 年份 2015, 特征行数=569698
[2021-10-29 11:22:15.175592] INFO: 基础特征抽取: 年份 2016, 特征行数=15290
[2021-10-29 11:22:15.341892] INFO: 基础特征抽取: 总行数: 584988
[2021-10-29 11:22:15.346943] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[15.827852s].
[2021-10-29 11:22:15.359968] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2021-10-29 11:22:21.552077] INFO: 基础特征抽取: 年份 2015, 特征行数=139170
[2021-10-29 11:22:33.412009] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
[2021-10-29 11:22:38.323270] INFO: 基础特征抽取: 年份 2017, 特征行数=34165
[2021-10-29 11:22:38.417577] INFO: 基础特征抽取: 总行数: 814881
[2021-10-29 11:22:38.423919] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[23.063958s].
[2021-10-29 11:22:38.431230] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2021-10-29 11:22:39.994972] INFO: derived_feature_extractor: 提取完成 avg_amount_5/avg_amount_10, 0.003s
[2021-10-29 11:22:39.998751] INFO: derived_feature_extractor: 提取完成 return_5/return_10, 0.002s
[2021-10-29 11:22:40.001981] INFO: derived_feature_extractor: 提取完成 turn_5/avg_turn_10, 0.002s
[2021-10-29 11:22:40.005531] INFO: derived_feature_extractor: 提取完成 avg_amount_0/avg_amount_5, 0.002s
[2021-10-29 11:22:40.008642] INFO: derived_feature_extractor: 提取完成 swing_volatility_5_0/swing_volatility_60_0, 0.002s
[2021-10-29 11:22:40.012277] INFO: derived_feature_extractor: 提取完成 amount_10/amount_30, 0.003s
[2021-10-29 11:22:40.015402] INFO: derived_feature_extractor: 提取完成 ta_ema_5_0/close_0, 0.002s
[2021-10-29 11:22:40.018419] INFO: derived_feature_extractor: 提取完成 close_0/low_0, 0.002s
[2021-10-29 11:22:40.021465] INFO: derived_feature_extractor: 提取完成 ta_ema_20_0/close_0, 0.002s
[2021-10-29 11:22:40.024567] INFO: derived_feature_extractor: 提取完成 open_0/close_1, 0.002s
[2021-10-29 11:22:40.027566] INFO: derived_feature_extractor: 提取完成 high_1/close_0, 0.002s
[2021-10-29 11:22:40.030628] INFO: derived_feature_extractor: 提取完成 ta_ema_30_0/close_0, 0.002s
[2021-10-29 11:22:42.598356] INFO: derived_feature_extractor: 提取完成 ta_rsi(close_0, 6), 2.567s
[2021-10-29 11:22:42.603057] INFO: derived_feature_extractor: 提取完成 amount_0/amount_1, 0.003s
[2021-10-29 11:22:43.999377] INFO: derived_feature_extractor: /y_2015, 569698
[2021-10-29 11:22:44.991672] INFO: derived_feature_extractor: /y_2016, 15290
[2021-10-29 11:22:45.120102] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[6.68886s].
[2021-10-29 11:22:45.128529] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2021-10-29 11:22:47.255695] INFO: derived_feature_extractor: 提取完成 avg_amount_5/avg_amount_10, 0.004s
[2021-10-29 11:22:47.259785] INFO: derived_feature_extractor: 提取完成 return_5/return_10, 0.002s
[2021-10-29 11:22:47.263454] INFO: derived_feature_extractor: 提取完成 turn_5/avg_turn_10, 0.002s
[2021-10-29 11:22:47.267971] INFO: derived_feature_extractor: 提取完成 avg_amount_0/avg_amount_5, 0.003s
[2021-10-29 11:22:47.271673] INFO: derived_feature_extractor: 提取完成 swing_volatility_5_0/swing_volatility_60_0, 0.002s
[2021-10-29 11:22:47.279948] INFO: derived_feature_extractor: 提取完成 amount_10/amount_30, 0.007s
[2021-10-29 11:22:47.283960] INFO: derived_feature_extractor: 提取完成 ta_ema_5_0/close_0, 0.002s
[2021-10-29 11:22:47.287709] INFO: derived_feature_extractor: 提取完成 close_0/low_0, 0.002s
[2021-10-29 11:22:47.291477] INFO: derived_feature_extractor: 提取完成 ta_ema_20_0/close_0, 0.002s
[2021-10-29 11:22:47.296005] INFO: derived_feature_extractor: 提取完成 open_0/close_1, 0.003s
[2021-10-29 11:22:47.300050] INFO: derived_feature_extractor: 提取完成 high_1/close_0, 0.003s
[2021-10-29 11:22:47.304991] INFO: derived_feature_extractor: 提取完成 ta_ema_30_0/close_0, 0.003s
[2021-10-29 11:22:50.867966] INFO: derived_feature_extractor: 提取完成 ta_rsi(close_0, 6), 3.562s
[2021-10-29 11:22:50.875457] INFO: derived_feature_extractor: 提取完成 amount_0/amount_1, 0.006s
[2021-10-29 11:22:51.547944] INFO: derived_feature_extractor: /y_2015, 139170
[2021-10-29 11:22:53.330674] INFO: derived_feature_extractor: /y_2016, 641546
[2021-10-29 11:22:54.610647] INFO: derived_feature_extractor: /y_2017, 34165
[2021-10-29 11:22:54.847846] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[9.719311s].
[2021-10-29 11:22:54.855906] INFO: moduleinvoker: join.v3 开始运行..
[2021-10-29 11:22:59.837486] INFO: join: /y_2015, 行数=560123/569698, 耗时=3.903477s
[2021-10-29 11:23:00.135383] INFO: join: /y_2016, 行数=10037/15290, 耗时=0.292331s
[2021-10-29 11:23:00.260485] INFO: join: 最终行数: 570160
[2021-10-29 11:23:00.313444] INFO: moduleinvoker: join.v3 运行完成[5.457512s].
[2021-10-29 11:23:00.330094] INFO: moduleinvoker: cached.v3 开始运行..
[2021-10-29 11:23:44.295259] INFO: moduleinvoker: cached.v3 运行完成[43.965172s].
[2021-10-29 11:23:44.306667] INFO: moduleinvoker: cached.v3 开始运行..
[2021-10-29 11:24:03.370117] ERROR: moduleinvoker: module name: cached, module version: v3, trackeback: IndexError: single positional indexer is out-of-bounds
[2021-10-29 11:24:03.380486] ERROR: moduleinvoker: module name: hyper_rolling_train, module version: v1, trackeback: IndexError: single positional indexer is out-of-bounds
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-5-620b16fd8dbf> in <module>
370
371
--> 372 m11 = M.hyper_rolling_train.v1(
373 run=m11_run_bigquant_run,
374 run_now=True,
<ipython-input-5-620b16fd8dbf> in m11_run_bigquant_run(bq_graph, inputs, trading_days_market, train_instruments_mid, test_instruments_mid, predict_mid, trade_mid, start_date, end_date, train_update_days, train_update_days_for_live, train_data_min_days, train_data_max_days, rolling_count_for_live)
355 parameters[test_instruments_mid + '.end_date'] = rolling['test_end_date']
356 # print('------ rolling_train:', parameters)
--> 357 results.append(g.run(parameters))
358
359 # 合并预测结果并回测
<ipython-input-5-620b16fd8dbf> in m6_run_bigquant_run(input_1, input_2, input_3)
20 df_final = df_final[df_final['rank_amount_0'] >= 0.85]
21 print("用于训练的样本总个数为",len(df_final))
---> 22 print(df_final.iloc[0])
23 data_1 = DataSource.write_df(df_final)
24 return Outputs(data_1=data_1, data_2=None, data_3=None)
IndexError: single positional indexer is out-of-bounds