{"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":"287d2cb0-f53c-4101-bdf8-104b137c8601-29: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":"287d2cb0-f53c-4101-bdf8-104b137c8601-29:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-503:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-510:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-3812:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:input_data","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-29:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:input_data","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:data"},{"to_node_id":"-86:input_data","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:data"},{"to_node_id":"-361:input_1","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"to_node_id":"-522:input_1","from_node_id":"-86:data"},{"to_node_id":"-1181:input_data","from_node_id":"-361:data_1"},{"to_node_id":"-503:instruments","from_node_id":"-494:data"},{"to_node_id":"-510:input_data","from_node_id":"-503:data"},{"to_node_id":"-516:input_data","from_node_id":"-510:data"},{"to_node_id":"-3828:data","from_node_id":"-522:data_1"},{"to_node_id":"-3812:training_ds","from_node_id":"-1181:data"},{"to_node_id":"-3812:test_ds","from_node_id":"-1181:left_data"},{"to_node_id":"-3828:model","from_node_id":"-3812:model"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81:options_data","from_node_id":"-3828: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":"2020-01-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. 可用数据字段见 {{web_host_url}}docs/data_history_data.html\n# 添加benchmark_前缀,可使用对应的benchmark数据\n# 2. 可用操作符和函数见 `表达式引擎 <{{web_host_url}}docs/big_expr.html>`_\n\n# 计算收益:2日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\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.HIX","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":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_5\nreturn_10\nreturn_20\nrank_return_5\nfs_common_equity_0\nmarket_cap_0\nrank_market_cap_0\nrank_market_cap_float_0\npb_lf_0\nrank_pb_lf_0\nmf_net_amount_5\navg_mf_net_amount_5\nrank_avg_mf_net_amount_5\nfs_net_profit_yoy_0\nrank_fs_net_profit_yoy_0\nfs_operating_revenue_yoy_0\nfs_roe_ttm_0\nfs_bps_0","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-29","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","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":"20","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-29"},{"name":"features","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-29"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-29"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35"},{"name":"features","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35"}],"cacheable":true,"seq_num":5,"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":"2020-06-01","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":false},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","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":"20","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70"},{"name":"features","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70"}],"cacheable":true,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76"},{"name":"features","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81","module_id":"BigQuantSpace.trade.trade-v3","parameters":[{"name":"start_date","value":"2015-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-06-01","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 instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(\n lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))\n # print('rank order for sell %s' % instruments)\n for instrument in instruments:\n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n if cash_for_sell <= 0:\n break\n\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])\n max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument\n for i, instrument in enumerate(buy_instruments):\n cash = cash_for_buy * buy_cash_weights[i]\n if cash > max_cash_per_instrument - positions.get(instrument, 0):\n # 确保股票持仓量不会超过每次股票最大的占用资金量\n cash = max_cash_per_instrument - positions.get(instrument, 0)\n if cash > 0:\n context.order_value(context.symbol(instrument), cash)\n","type":"Literal","bound_global_parameter":null},{"name":"prepare","value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","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 = 8\n # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]\n context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])\n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 0.4\n context.options['hold_days'] = 2\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":"close","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":"100000","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.HIX","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":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81"},{"name":"options_data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81"}],"output_ports":[{"name":"raw_perf","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81"}],"cacheable":false,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"cacheable":true,"seq_num":13,"comment":"","comment_collapsed":true},{"node_id":"-86","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"-86"}],"output_ports":[{"name":"data","node_id":"-86"}],"cacheable":true,"seq_num":14,"comment":"","comment_collapsed":true},{"node_id":"-361","module_id":"BigQuantSpace.filtet_st_stock_tomo.filtet_st_stock_tomo-v3","parameters":[],"input_ports":[{"name":"input_1","node_id":"-361"}],"output_ports":[{"name":"data_1","node_id":"-361"}],"cacheable":true,"seq_num":16,"comment":"","comment_collapsed":true},{"node_id":"-494","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2020-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-06-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":"-494"}],"output_ports":[{"name":"data","node_id":"-494"}],"cacheable":true,"seq_num":15,"comment":"预测数据,用于回测和模拟","comment_collapsed":true},{"node_id":"-503","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","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":"20","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-503"},{"name":"features","node_id":"-503"}],"output_ports":[{"name":"data","node_id":"-503"}],"cacheable":true,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"-510","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-510"},{"name":"features","node_id":"-510"}],"output_ports":[{"name":"data","node_id":"-510"}],"cacheable":true,"seq_num":18,"comment":"","comment_collapsed":true},{"node_id":"-516","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"-516"}],"output_ports":[{"name":"data","node_id":"-516"}],"cacheable":true,"seq_num":19,"comment":"","comment_collapsed":true},{"node_id":"-522","module_id":"BigQuantSpace.filtet_st_stock_tomo.filtet_st_stock_tomo-v3","parameters":[],"input_ports":[{"name":"input_1","node_id":"-522"}],"output_ports":[{"name":"data_1","node_id":"-522"}],"cacheable":true,"seq_num":21,"comment":"","comment_collapsed":true},{"node_id":"-1181","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"date<\"2015-01-01\"","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-1181"}],"output_ports":[{"name":"data","node_id":"-1181"},{"name":"left_data","node_id":"-1181"}],"cacheable":true,"seq_num":22,"comment":"","comment_collapsed":true},{"node_id":"-3812","module_id":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v6","parameters":[{"name":"learning_algorithm","value":"排序","type":"Literal","bound_global_parameter":null},{"name":"number_of_leaves","value":"60","type":"Literal","bound_global_parameter":null},{"name":"minimum_docs_per_leaf","value":"1000","type":"Literal","bound_global_parameter":null},{"name":"number_of_trees","value":"20","type":"Literal","bound_global_parameter":null},{"name":"learning_rate","value":"0.01","type":"Literal","bound_global_parameter":null},{"name":"max_bins","value":"2047","type":"Literal","bound_global_parameter":null},{"name":"feature_fraction","value":"0.8","type":"Literal","bound_global_parameter":null},{"name":"data_row_fraction","value":"0.8","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"ndcg_discount_base","value":1,"type":"Literal","bound_global_parameter":null},{"name":"m_lazy_run","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"training_ds","node_id":"-3812"},{"name":"features","node_id":"-3812"},{"name":"test_ds","node_id":"-3812"},{"name":"base_model","node_id":"-3812"}],"output_ports":[{"name":"model","node_id":"-3812"},{"name":"feature_gains","node_id":"-3812"},{"name":"m_lazy_run","node_id":"-3812"}],"cacheable":true,"seq_num":20,"comment":"","comment_collapsed":true},{"node_id":"-3828","module_id":"BigQuantSpace.stock_ranker_predict.stock_ranker_predict-v5","parameters":[{"name":"m_lazy_run","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"model","node_id":"-3828"},{"name":"data","node_id":"-3828"}],"output_ports":[{"name":"predictions","node_id":"-3828"},{"name":"m_lazy_run","node_id":"-3828"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-141","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='m8', # 预测 模块id\n trade_mid='m12', # 回测 模块id\n start_date='2014-01-01', # 数据开始日期\n end_date=T.live_run_param('trading_date', '2017-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":"-141"},{"name":"input_1","node_id":"-141"},{"name":"input_2","node_id":"-141"},{"name":"input_3","node_id":"-141"}],"output_ports":[{"name":"result","node_id":"-141"}],"cacheable":false,"seq_num":8,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='213,-30,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='664,23,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-29' Position='381,185,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-35' Position='387,280,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='311,337,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1095,124,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-70' Position='1078,236,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-76' Position='1078,327,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-81' Position='1040,837,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='337,414,200,200'/><node_position Node='-86' Position='1078,419,200,200'/><node_position Node='-361' Position='417,494,200,200'/><node_position Node='-494' Position='712,181,200,200'/><node_position Node='-503' Position='771,296,200,200'/><node_position Node='-510' Position='730,406,200,200'/><node_position Node='-516' Position='742,472,200,200'/><node_position Node='-522' Position='1135,513,200,200'/><node_position Node='-1181' Position='581,590,200,200'/><node_position Node='-3812' Position='460,699,200,200'/><node_position Node='-3828' Position='851,665,200,200'/><node_position Node='-141' Position='601,-188,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2022-06-07 13:11:08.747955] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-06-07 13:11:08.768144] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.770250] INFO: moduleinvoker: instruments.v2 运行完成[0.022302s].
[2022-06-07 13:11:08.779827] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-06-07 13:11:08.789824] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.792289] INFO: moduleinvoker: input_features.v1 运行完成[0.01247s].
[2022-06-07 13:11:08.809504] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-06-07 13:11:08.818423] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.820123] INFO: moduleinvoker: instruments.v2 运行完成[0.010649s].
[2022-06-07 13:11:08.828603] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-06-07 13:11:08.837532] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.840682] INFO: moduleinvoker: instruments.v2 运行完成[0.012064s].
[2022-06-07 13:11:08.858889] INFO: moduleinvoker: advanced_auto_labeler.v2 开始运行..
[2022-06-07 13:11:08.869669] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.874817] INFO: moduleinvoker: advanced_auto_labeler.v2 运行完成[0.015929s].
[2022-06-07 13:11:08.898948] INFO: moduleinvoker: general_feature_extractor.v6 开始运行..
[2022-06-07 13:11:08.909778] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.912432] INFO: moduleinvoker: general_feature_extractor.v6 运行完成[0.013502s].
[2022-06-07 13:11:08.936197] INFO: moduleinvoker: general_feature_extractor.v6 开始运行..
[2022-06-07 13:11:08.944056] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.946967] INFO: moduleinvoker: general_feature_extractor.v6 运行完成[0.010803s].
[2022-06-07 13:11:08.965569] INFO: moduleinvoker: general_feature_extractor.v6 开始运行..
[2022-06-07 13:11:08.976564] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:08.979259] INFO: moduleinvoker: general_feature_extractor.v6 运行完成[0.013722s].
[2022-06-07 13:11:08.993237] INFO: moduleinvoker: derived_feature_extractor.v2 开始运行..
[2022-06-07 13:11:09.005812] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:09.008782] INFO: moduleinvoker: derived_feature_extractor.v2 运行完成[0.015504s].
[2022-06-07 13:11:09.018494] INFO: moduleinvoker: derived_feature_extractor.v2 开始运行..
[2022-06-07 13:11:09.029257] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:09.031713] INFO: moduleinvoker: derived_feature_extractor.v2 运行完成[0.01333s].
[2022-06-07 13:11:09.042744] INFO: moduleinvoker: derived_feature_extractor.v2 开始运行..
[2022-06-07 13:11:09.052115] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:09.054547] INFO: moduleinvoker: derived_feature_extractor.v2 运行完成[0.011802s].
[2022-06-07 13:11:09.073506] INFO: moduleinvoker: join.v3 开始运行..
[2022-06-07 13:11:09.081648] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:09.083367] INFO: moduleinvoker: join.v3 运行完成[0.009868s].
[2022-06-07 13:11:09.096760] INFO: moduleinvoker: dropnan.v1 开始运行..
[2022-06-07 13:11:09.514503] INFO: dropnan: /y_2014, 29538/30263
[2022-06-07 13:11:10.657512] INFO: dropnan: /y_2015, 552932/569698
[2022-06-07 13:11:10.825484] INFO: dropnan: /y_2016, 27529/28050
[2022-06-07 13:11:10.961583] INFO: dropnan: 行数: 609999/628011
[2022-06-07 13:11:10.967321] INFO: moduleinvoker: dropnan.v1 运行完成[1.870598s].
[2022-06-07 13:11:10.978030] INFO: moduleinvoker: dropnan.v1 开始运行..
[2022-06-07 13:11:10.986388] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:10.988728] INFO: moduleinvoker: dropnan.v1 运行完成[0.010705s].
[2022-06-07 13:11:11.007814] INFO: moduleinvoker: dropnan.v1 开始运行..
[2022-06-07 13:11:11.018986] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:11.022239] INFO: moduleinvoker: dropnan.v1 运行完成[0.014431s].
[2022-06-07 13:11:13.031399] INFO: moduleinvoker: filtet_st_stock_tomo.v3 开始运行..
[2022-06-07 13:11:16.468855] INFO: moduleinvoker: filtet_st_stock_tomo.v3 运行完成[3.437469s].
[2022-06-07 13:11:16.480860] INFO: moduleinvoker: filtet_st_stock_tomo.v3 开始运行..
[2022-06-07 13:11:16.489261] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:16.490938] INFO: moduleinvoker: filtet_st_stock_tomo.v3 运行完成[0.010105s].
[2022-06-07 13:11:16.515236] INFO: moduleinvoker: filter.v3 开始运行..
[2022-06-07 13:11:16.548907] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:16.553306] INFO: moduleinvoker: filter.v3 运行完成[0.03807s].
[2022-06-07 13:11:16.568414] INFO: moduleinvoker: stock_ranker_train.v6 开始运行..
[2022-06-07 13:11:16.624466] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:16.874782] INFO: moduleinvoker: stock_ranker_train.v6 运行完成[0.30636s].
[2022-06-07 13:11:16.891789] INFO: moduleinvoker: stock_ranker_predict.v5 开始运行..
[2022-06-07 13:11:19.108572] INFO: StockRanker预测: /data ..
[2022-06-07 13:11:22.653645] INFO: moduleinvoker: stock_ranker_predict.v5 运行完成[5.76184s].
[2022-06-07 13:11:22.662703] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-06-07 13:11:22.673288] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:22.675769] INFO: moduleinvoker: instruments.v2 运行完成[0.01307s].
[2022-06-07 13:11:22.681586] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-06-07 13:11:22.690036] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:22.691968] INFO: moduleinvoker: input_features.v1 运行完成[0.010406s].
[2022-06-07 13:11:22.706937] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-06-07 13:11:22.778935] INFO: moduleinvoker: instruments.v2 运行完成[0.072009s].
[2022-06-07 13:11:22.785110] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-06-07 13:11:22.791784] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:22.793490] INFO: moduleinvoker: instruments.v2 运行完成[0.008388s].
[2022-06-07 13:11:22.815474] INFO: moduleinvoker: advanced_auto_labeler.v2 开始运行..
[2022-06-07 13:11:22.824901] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:22.827826] INFO: moduleinvoker: advanced_auto_labeler.v2 运行完成[0.012357s].
[2022-06-07 13:11:22.844163] INFO: moduleinvoker: general_feature_extractor.v6 开始运行..
[2022-06-07 13:11:22.851375] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:22.853555] INFO: moduleinvoker: general_feature_extractor.v6 运行完成[0.009405s].
[2022-06-07 13:11:22.867096] INFO: moduleinvoker: general_feature_extractor.v6 开始运行..
[2022-06-07 13:11:26.356206] INFO: 基础特征抽取: 年份 2015, 特征行数=22733
[2022-06-07 13:11:31.238635] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
[2022-06-07 13:11:31.552727] INFO: 基础特征抽取: 总行数: 664279
[2022-06-07 13:11:31.563173] INFO: moduleinvoker: general_feature_extractor.v6 运行完成[8.696081s].
[2022-06-07 13:11:31.645547] INFO: moduleinvoker: general_feature_extractor.v6 开始运行..
[2022-06-07 13:11:31.654988] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:31.658507] INFO: moduleinvoker: general_feature_extractor.v6 运行完成[0.012956s].
[2022-06-07 13:11:31.670714] INFO: moduleinvoker: derived_feature_extractor.v2 开始运行..
[2022-06-07 13:11:31.678490] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:31.680471] INFO: moduleinvoker: derived_feature_extractor.v2 运行完成[0.009785s].
[2022-06-07 13:11:31.688017] INFO: moduleinvoker: derived_feature_extractor.v2 开始运行..
[2022-06-07 13:11:33.987513] INFO: derived_feature_extractor: /y_2015, 22733
[2022-06-07 13:11:35.920854] INFO: derived_feature_extractor: /y_2016, 641546
[2022-06-07 13:11:36.578447] INFO: moduleinvoker: derived_feature_extractor.v2 运行完成[4.89042s].
[2022-06-07 13:11:36.588223] INFO: moduleinvoker: derived_feature_extractor.v2 开始运行..
[2022-06-07 13:11:36.595315] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:36.597899] INFO: moduleinvoker: derived_feature_extractor.v2 运行完成[0.009697s].
[2022-06-07 13:11:36.613504] INFO: moduleinvoker: join.v3 开始运行..
[2022-06-07 13:11:36.633160] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:36.637652] INFO: moduleinvoker: join.v3 运行完成[0.024147s].
[2022-06-07 13:11:36.651715] INFO: moduleinvoker: dropnan.v1 开始运行..
[2022-06-07 13:11:36.851134] INFO: dropnan: /y_2015, 22397/22733
[2022-06-07 13:11:38.153042] INFO: dropnan: /y_2016, 627057/641546
[2022-06-07 13:11:38.363377] INFO: dropnan: 行数: 649454/664279
[2022-06-07 13:11:38.373009] INFO: moduleinvoker: dropnan.v1 运行完成[1.721297s].
[2022-06-07 13:11:38.383705] INFO: moduleinvoker: dropnan.v1 开始运行..
[2022-06-07 13:11:38.391810] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:38.393954] INFO: moduleinvoker: dropnan.v1 运行完成[0.010257s].
[2022-06-07 13:11:38.415432] INFO: moduleinvoker: dropnan.v1 开始运行..
[2022-06-07 13:11:38.426979] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:38.429094] INFO: moduleinvoker: dropnan.v1 运行完成[0.013668s].
[2022-06-07 13:11:38.439998] INFO: moduleinvoker: filtet_st_stock_tomo.v3 开始运行..
[2022-06-07 13:11:42.578645] INFO: moduleinvoker: filtet_st_stock_tomo.v3 运行完成[4.138658s].
[2022-06-07 13:11:42.589642] INFO: moduleinvoker: filtet_st_stock_tomo.v3 开始运行..
[2022-06-07 13:11:42.597895] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:42.600566] INFO: moduleinvoker: filtet_st_stock_tomo.v3 运行完成[0.010915s].
[2022-06-07 13:11:42.616228] INFO: moduleinvoker: filter.v3 开始运行..
[2022-06-07 13:11:42.631218] INFO: moduleinvoker: 命中缓存
[2022-06-07 13:11:42.633738] INFO: moduleinvoker: filter.v3 运行完成[0.017543s].
[2022-06-07 13:11:42.644000] INFO: moduleinvoker: stock_ranker_train.v6 开始运行..
[2022-06-07 13:11:43.518217] INFO: StockRanker: prepare data: test ..
[2022-06-07 13:11:43.529978] ERROR: moduleinvoker: module name: cached, module version: v2, trackeback: UnboundLocalError: local variable 'feature_cols' referenced before assignment
[2022-06-07 13:11:43.534962] ERROR: moduleinvoker: module name: stock_ranker_train, module version: v6, trackeback: UnboundLocalError: local variable 'feature_cols' referenced before assignment
[2022-06-07 13:11:43.539091] ERROR: moduleinvoker: module name: hyper_rolling_train, module version: v1, trackeback: UnboundLocalError: local variable 'feature_cols' referenced before assignment
bigcharts-data-start/{"__type":"tabs","__id":"bigchart-67c41b9a2f0341ed9c00ff2d4f5b315e"}/bigcharts-data-end
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-1-8a9ae5a9a83a> in <module>
333
334
--> 335 m8 = M.hyper_rolling_train.v1(
336 run=m8_run_bigquant_run,
337 run_now=True,
<ipython-input-1-8a9ae5a9a83a> in m8_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)
318 parameters[test_instruments_mid + '.end_date'] = rolling['test_end_date']
319 # print('------ rolling_train:', parameters)
--> 320 results.append(g.run(parameters))
321
322 # 合并预测结果并回测
UnboundLocalError: local variable 'feature_cols' referenced before assignment