{"description":"实验创建于2022/4/8","graph":{"edges":[{"to_node_id":"-161:input_data","from_node_id":"-505:data"},{"to_node_id":"-760:input","from_node_id":"-505:data"},{"to_node_id":"-645:input_1","from_node_id":"-512:data"},{"to_node_id":"-161:features","from_node_id":"-666:data"},{"to_node_id":"-549:input_1","from_node_id":"-161:data"},{"to_node_id":"-7412:instruments","from_node_id":"-760:instrument_list"},{"to_node_id":"-567:data2","from_node_id":"-645:data_1"},{"to_node_id":"-567:data1","from_node_id":"-549:data_1"},{"to_node_id":"-577:input_1","from_node_id":"-567:data"},{"to_node_id":"-665:input_data","from_node_id":"-577:data_1"},{"to_node_id":"-7412:options_data","from_node_id":"-665:data"}],"nodes":[{"node_id":"-505","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"market_performance_CN_CONBOND","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2022-01-17","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-07-20","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-505"},{"name":"features","node_id":"-505"}],"output_ports":[{"name":"data","node_id":"-505"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-512","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"basic_info_CN_CONBOND","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2022-01-17","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-07-20","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-512"},{"name":"features","node_id":"-512"}],"output_ports":[{"name":"data","node_id":"-512"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-666","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ndouble_low = close + bond_prem_ratio # 双低价\nremain_size > 1.5 # 剩余规模\ntotal_size\nremain_size\nbond_prem_ratio\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-666"}],"output_ports":[{"name":"data","node_id":"-666"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-161","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":"-161"},{"name":"features","node_id":"-161"}],"output_ports":[{"name":"data","node_id":"-161"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-760","module_id":"BigQuantSpace.trade_data_generation.trade_data_generation-v1","parameters":[{"name":"category","value":"CN_STOCK","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input","node_id":"-760"}],"output_ports":[{"name":"history_data","node_id":"-760"},{"name":"instrument_list","node_id":"-760"},{"name":"calendar","node_id":"-760"}],"cacheable":false,"seq_num":9,"comment":"","comment_collapsed":true},{"node_id":"-645","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()\n df['list_date'] = df['list_date'].astype(str)\n df['delist_date'] = df['delist_date'].astype(str)\n df = df.loc[:,['instrument','list_date','delist_date']]\n \n data_1 = DataSource.write_df(df)\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":"-645"},{"name":"input_2","node_id":"-645"},{"name":"input_3","node_id":"-645"}],"output_ports":[{"name":"data_1","node_id":"-645"},{"name":"data_2","node_id":"-645"},{"name":"data_3","node_id":"-645"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-549","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()\n \n df = df.loc[:,['date','instrument','close','bond_prem_ratio','double_low','remain_size','total_size']]\n \n data_1 = DataSource.write_df(df)\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":"-549"},{"name":"input_2","node_id":"-549"},{"name":"input_3","node_id":"-549"}],"output_ports":[{"name":"data_1","node_id":"-549"},{"name":"data_2","node_id":"-549"},{"name":"data_3","node_id":"-549"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-567","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"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":"-567"},{"name":"data2","node_id":"-567"}],"output_ports":[{"name":"data","node_id":"-567"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-577","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()\n \n df['date'] = pd.to_datetime(df['date'])\n df['list_date'] = pd.to_datetime(df['list_date'])\n df['delist_date'] = pd.to_datetime(df['delist_date'])\n \n #买入规则:上市满30天,并且价格小于120\n #df['can_buy'] = df['date'] > (df['list_date'] + datetime.timedelta(days=30)) and df['close']<120\n df['can_buy'] = df['close']<120\n #卖出规则:价格大于140时卖\n df['to_clean'] = df['close']>140\n \n data_1 = DataSource.write_df(df)\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":"-577"},{"name":"input_2","node_id":"-577"},{"name":"input_3","node_id":"-577"}],"output_ports":[{"name":"data_1","node_id":"-577"},{"name":"data_2","node_id":"-577"},{"name":"data_3","node_id":"-577"}],"cacheable":true,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"-7412","module_id":"BigQuantSpace.hftrade.hftrade-v2","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 # 加载股票指标数据,数据继承自m6模块\n context.indicator_data = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n \n # 设置股票数量\n context.stock_num = 20\n \n # 调仓天数,22个交易日大概就是一个月。可以理解为一个月换仓一次\n context.rebalance_days = 22\n \n # 如果策略运行中,需要将数据进行保存,可以借用extension这个对象,类型为dict\n # 比如当前运行的k线的索引,比如个股持仓天数、买入均价\n if 'index' not in context.extension:\n context.extension['index'] = 0\n ","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n context.subscribe(context.instruments)\n pass","type":"Literal","bound_global_parameter":null},{"name":"handle_tick","value":"# 交易引擎:tick数据处理函数,每个tick执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # context.extension['index'] += 1\n # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月\n #if context.extension['index'] % context.rebalance_days != 0:\n # return\n # 当前的日期\n date = data.current_dt.strftime('%Y-%m-%d')\n print('----------',date)\n #获取当天的股票列表\n cur_data = context.indicator_data[context.indicator_data['date'] == date]\n\n #建仓条件判断:市场双低均值达到170可进行建仓\n #if cur_data['double_low'].mean() > 170:\n # print(date,':该调仓日市场双低均值为',cur_data['double_low'].mean(),\",无需建仓\")\n # return\n # 如果价格>120,则不建仓\n #if cur_data['close'].mean() > 120:\n # #print(date,'该转债价格大于120,',cur_data['instrument'],',无需建仓')\n # return\n \n # 设定股票池\n # 条件1:满足条件的可以买\n stock_can_buy = cur_data[cur_data['can_buy'] == True]\n # 条件2:满足卖出条件的可以卖\n stock_to_clean = cur_data[cur_data['to_clean'] == True]\n \n symbols = list(set(stock_can_buy['instrument'].values).difference(set(stock_to_clean['instrument'].values)))\n cur_data = cur_data.set_index('instrument').loc[symbols,:].reset_index().sort_values('close')\n stock_to_buy = list(cur_data.instrument[:context.stock_num])\n \n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity for equity in context.portfolio.positions]\n # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有\n no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]\n # 需要卖出的股票\n stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell] \n \n # 卖出\n for stock in stock_to_sell:\n context.order_target_percent(stock, 0)\n \n # 如果当天没有买入的股票,就返回\n if len(stock_to_buy) == 0:\n print(date,'当天没有买入的股票')\n return\n\n # 等权重买入 \n weight = 1 / len(stock_to_buy)\n \n # 买入\n for stock in stock_to_buy:\n context.order_target_percent(stock, weight)\n ","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"after_trading","value":"# 交易引擎:盘后处理函数,每日盘后执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":"1000001","type":"Literal","bound_global_parameter":null},{"name":"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":"before_start_days","value":"0","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_buy","value":"close","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_sell","value":"close","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.HIX","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"disable_cache","value":"False","type":"Literal","bound_global_parameter":null},{"name":"replay_bdb","value":"False","type":"Literal","bound_global_parameter":null},{"name":"show_debug_info","value":"False","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-7412"},{"name":"options_data","node_id":"-7412"},{"name":"history_ds","node_id":"-7412"},{"name":"benchmark_ds","node_id":"-7412"}],"output_ports":[{"name":"raw_perf","node_id":"-7412"}],"cacheable":false,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-665","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"date<delist_date and close<120","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":"-665"}],"output_ports":[{"name":"data","node_id":"-665"},{"name":"left_data","node_id":"-665"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-505' Position='139,-159,200,200'/><node_position Node='-512' Position='623,-44,200,200'/><node_position Node='-666' Position='445,-164,200,200'/><node_position Node='-161' Position='322,-49,200,200'/><node_position Node='-760' Position='5,48,200,200'/><node_position Node='-645' Position='601,48,200,200'/><node_position Node='-549' Position='302,50,200,200'/><node_position Node='-567' Position='406.4010009765625,168.5484619140625,200,200'/><node_position Node='-577' Position='404.2525634765625,280.2680358886719,200,200'/><node_position Node='-7412' Position='228.9443359375,597.65771484375,200,200'/><node_position Node='-665' Position='413.92059326171875,408.1010437011719,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2022-07-21 17:21:05.801969] INFO: moduleinvoker: use_datasource.v1 开始运行..
[2022-07-21 17:21:06.709997] INFO: moduleinvoker: use_datasource.v1 运行完成[0.908028s].
[2022-07-21 17:21:06.730039] INFO: moduleinvoker: trade_data_generation.v1 开始运行..
[2022-07-21 17:21:07.196914] INFO: moduleinvoker: trade_data_generation.v1 运行完成[0.466859s].
[2022-07-21 17:21:07.290978] INFO: moduleinvoker: use_datasource.v1 开始运行..
[2022-07-21 17:21:07.568563] INFO: moduleinvoker: use_datasource.v1 运行完成[0.277586s].
[2022-07-21 17:21:07.849726] INFO: moduleinvoker: cached.v3 开始运行..
[2022-07-21 17:21:08.323770] INFO: moduleinvoker: cached.v3 运行完成[0.474048s].
[2022-07-21 17:21:08.330063] INFO: moduleinvoker: input_features.v1 开始运行..
[2022-07-21 17:21:08.357848] INFO: moduleinvoker: 命中缓存
[2022-07-21 17:21:08.360126] INFO: moduleinvoker: input_features.v1 运行完成[0.030088s].
[2022-07-21 17:21:08.414069] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2022-07-21 17:21:09.577045] INFO: derived_feature_extractor: 提取完成 double_low = close + bond_prem_ratio # 双低价, 0.003s
[2022-07-21 17:21:09.586557] INFO: derived_feature_extractor: 提取完成 remain_size > 1.5 # 剩余规模, 0.007s
[2022-07-21 17:21:10.704568] INFO: derived_feature_extractor: /data, 48721
[2022-07-21 17:21:10.933624] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[2.51954s].
[2022-07-21 17:21:10.989241] INFO: moduleinvoker: cached.v3 开始运行..
[2022-07-21 17:21:11.626055] INFO: moduleinvoker: cached.v3 运行完成[0.636831s].
[2022-07-21 17:21:11.651690] INFO: moduleinvoker: join.v3 开始运行..
[2022-07-21 17:21:12.168884] INFO: join: /data, 行数=48721/2569, 耗时=0.143173s
[2022-07-21 17:21:12.261535] INFO: join: 最终行数: 48721
[2022-07-21 17:21:12.290988] INFO: moduleinvoker: join.v3 运行完成[0.639286s].
[2022-07-21 17:21:12.337417] INFO: moduleinvoker: cached.v3 开始运行..
[2022-07-21 17:21:12.767617] INFO: moduleinvoker: cached.v3 运行完成[0.430219s].
[2022-07-21 17:21:12.816377] INFO: moduleinvoker: filter.v3 开始运行..
[2022-07-21 17:21:12.930042] INFO: filter: 使用表达式 date[2022-07-21 17:21:13.302832] INFO: filter: 过滤 /data, 22204/26517/48721
[2022-07-21 17:21:13.388361] INFO: moduleinvoker: filter.v3 运行完成[0.571976s].
[2022-07-21 17:21:13.449657] INFO: moduleinvoker: hfbacktest.v1 开始运行..
[2022-07-21 17:21:13.458495] INFO: hfbacktest: biglearning V1.4.14
[2022-07-21 17:21:13.463283] INFO: hfbacktest: bigtrader v1.9.7 2022-07-11
[2022-07-21 17:21:13.509585] INFO: moduleinvoker: cached.v2 开始运行..
[2022-07-21 17:21:13.836785] INFO: moduleinvoker: cached.v2 运行完成[0.327205s].
[2022-07-21 17:21:14.067474] INFO: moduleinvoker: cached.v2 开始运行..
[2022-07-21 17:21:15.378715] INFO: moduleinvoker: cached.v2 运行完成[1.311242s].
[2022-07-21 17:21:16.849263] ERROR: moduleinvoker: module name: hfbacktest, module version: v1, trackeback: TypeError: 'NoneType' object is not iterable
[2022-07-21 17:21:16.861232] ERROR: moduleinvoker: module name: hftrade, module version: v2, trackeback: TypeError: 'NoneType' object is not iterable
---------- 2022-01-17
---------- 2022-01-18
---------- 2022-01-19
---------- 2022-01-20
---------- 2022-01-21
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-114-0f056b8e46c2> in <module>
229 )
230
--> 231 m8 = M.hftrade.v2(
232 instruments=m9.instrument_list,
233 options_data=m11.data,
TypeError: 'NoneType' object is not iterable