{"description":"实验创建于2021/9/2","graph":{"edges":[{"to_node_id":"-17:instruments","from_node_id":"-4:data"},{"to_node_id":"-33:instruments","from_node_id":"-4:data"},{"to_node_id":"-17:features","from_node_id":"-12:data"},{"to_node_id":"-24:input_data","from_node_id":"-17:data"},{"to_node_id":"-33:options_data","from_node_id":"-24:data"}],"nodes":[{"node_id":"-4","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2013-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2017-11-07","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":"-4"}],"output_ports":[{"name":"data","node_id":"-4"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-12","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nrank_pb_lf_0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-12"}],"output_ports":[{"name":"data","node_id":"-12"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-17","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":"-17"},{"name":"features","node_id":"-17"}],"output_ports":[{"name":"data","node_id":"-17"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-24","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"rank_pb_lf_0 < 0.1","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-24"}],"output_ports":[{"name":"data","node_id":"-24"},{"name":"left_data","node_id":"-24"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-33","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 = 5\n # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]\n context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])\n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 0.2\n context.hold_days = 5\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 按日期过滤得到今日的预测数据\n if context.trading_day_index % 22 != 0:\n return\n\n # 按日期过滤得到当日的数据\n cur_data = context.data[context.data.date == data.current_dt.strftime('%Y-%m-%d')]\n buy_stock = list(cur_data['instrument'])\n\n # 买入股票\n for i in buy_stock:\n if data.can_trade(context.symbol(i)):\n context.order_target_percent(context.symbol(i), 1/len(buy_stock)) # 等权重买入\n \n # 持仓股票列表,为字符串\n is_staging = context.trading_day_index < context.hold_days # 是否在建仓期间(前 hold_days 天)\n equities = {e.symbol: p for e,p in context.portfolio.positions.items() if p.amount>0}\n for instrument in equities:\n if data.can_trade(context.symbol(instrument)):\n context.order_target_percent(context.symbol(instrument), 0)","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":"# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n","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":1000000,"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":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-33"},{"name":"options_data","node_id":"-33"},{"name":"history_ds","node_id":"-33"},{"name":"benchmark_ds","node_id":"-33"},{"name":"trading_calendar","node_id":"-33"}],"output_ports":[{"name":"raw_perf","node_id":"-33"}],"cacheable":false,"seq_num":5,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-4' Position='146,111,200,200'/><node_position Node='-12' Position='468,112,200,200'/><node_position Node='-17' Position='287,236,200,200'/><node_position Node='-24' Position='287,322,200,200'/><node_position Node='-33' Position='224,394,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2021-09-02 08:59:57.745716] INFO: moduleinvoker: instruments.v2 开始运行..
[2021-09-02 08:59:57.756256] INFO: moduleinvoker: 命中缓存
[2021-09-02 08:59:57.757740] INFO: moduleinvoker: instruments.v2 运行完成[0.012032s].
[2021-09-02 08:59:57.761019] INFO: moduleinvoker: input_features.v1 开始运行..
[2021-09-02 08:59:57.769944] INFO: moduleinvoker: 命中缓存
[2021-09-02 08:59:57.771230] INFO: moduleinvoker: input_features.v1 运行完成[0.010212s].
[2021-09-02 08:59:57.784566] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2021-09-02 08:59:57.793993] INFO: moduleinvoker: 命中缓存
[2021-09-02 08:59:57.795281] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[0.010721s].
[2021-09-02 08:59:57.801448] INFO: moduleinvoker: filter.v3 开始运行..
[2021-09-02 08:59:57.819076] INFO: filter: 使用表达式 rank_pb_lf_0 < 0.1 过滤
[2021-09-02 08:59:57.984250] INFO: filter: 过滤 /y_2012, 14647/0/146839
[2021-09-02 08:59:58.165188] INFO: filter: 过滤 /y_2013, 56291/0/564168
[2021-09-02 08:59:58.352889] INFO: filter: 过滤 /y_2014, 56855/0/569948
[2021-09-02 08:59:58.526832] INFO: filter: 过滤 /y_2015, 56837/0/569698
[2021-09-02 08:59:58.726267] INFO: filter: 过滤 /y_2016, 64018/0/641546
[2021-09-02 08:59:58.920768] INFO: filter: 过滤 /y_2017, 61910/0/620177
[2021-09-02 08:59:58.957733] INFO: moduleinvoker: filter.v3 运行完成[1.156271s].
[2021-09-02 09:00:00.486252] INFO: moduleinvoker: backtest.v8 开始运行..
[2021-09-02 09:00:00.490819] INFO: backtest: biglearning backtest:V8.5.0
[2021-09-02 09:00:00.493560] INFO: backtest: product_type:stock by specified
[2021-09-02 09:00:01.653877] INFO: moduleinvoker: cached.v2 开始运行..
[2021-09-02 09:00:42.726071] INFO: backtest: 读取股票行情完成:4256462
[2021-09-02 09:00:54.416085] INFO: moduleinvoker: cached.v2 运行完成[52.762214s].
[2021-09-02 09:01:07.544274] INFO: algo: TradingAlgorithm V1.8.5
[2021-09-02 09:01:13.388334] INFO: algo: trading transform...
[2021-09-02 09:01:14.795155] ERROR: moduleinvoker: module name: backtest, module version: v8, trackeback: AttributeError: 'TradingAlgorithm' object has no attribute 'data'
[2021-09-02 09:01:14.807123] ERROR: moduleinvoker: module name: trade, module version: v4, trackeback: AttributeError: 'TradingAlgorithm' object has no attribute 'data'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-9835637ac2df> in <module>
78 )
79
---> 80 m5 = M.trade.v4(
81 instruments=m1.data,
82 options_data=m4.data,
<ipython-input-9-9835637ac2df> in m5_handle_data_bigquant_run(context, data)
26
27 # 按日期过滤得到当日的数据
---> 28 cur_data = context.data[context.data.date == data.current_dt.strftime('%Y-%m-%d')]
29 buy_stock = list(cur_data['instrument'])
30
AttributeError: 'TradingAlgorithm' object has no attribute 'data'