{"description":"实验创建于2023/3/9","graph":{"edges":[{"to_node_id":"-40:instruments","from_node_id":"-66:data"}],"nodes":[{"node_id":"-40","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 # 加载预测数据\n context.symbol = '000002.SZA'\n","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n # 盘前处理,订阅行情等\n# context.subscribe(context.symbol)\n context.subscribe_bar(context.symbol, '1m')\n","type":"Literal","bound_global_parameter":null},{"name":"handle_tick","value":"# 交易引擎:tick数据处理函数,每个tick执行一次\ndef bigquant_run(context, tick):\n pass\n# curdate = tick.trading_day.strftime('%Y-%m-%d')\n# curtime = tick.time.strftime('%H:%M:%S')\n# context.write_log(\"当前时间:{}, 当前时间:{}, 股票代码:{}, 卖一价:{}, 买一价:{}\".format(curdate, curtime, tick.instrument, tick.ask_price1, tick.bid_price1), stdout=1)\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 交易引擎:bar数据处理函数,每个时间单位执行一次\ndef bigquant_run(context, data):\n# pass\n curdate = data.current_dt.strftime('%Y-%m-%d')\n curtime = data.current_dt.strftime('%H:%M:%S')\n# context.write_log(\"当前时间:{}, 当前时间:{}, 合约,当前bar的收盘价:{}\".format(curdate, curtime, data.get_daily_value(context.symbol, 'close')), stdout=1)\n \n \n ######################## 下单函数说明 ############################\n# if curdate == '2023-03-01':\n# if (curtime >= '09:40:00') and (curtime < '09:40:55'): # 下单卖出股\n# _flag = context.order(context.symbol, 500, price=None, order_type=OrderType.MARKET)\n# context.write_log(\"买入500股, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n# if (curtime >= '10:00:00') and (curtime < '10:00:55'): # 下单5%\n# _flag = context.order_percent(context.symbol, 0.05, price=None, order_type=OrderType.MARKET)\n# context.write_log(\"买入仓位5%, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n# if (curtime >= '10:30:00') and (curtime < '10:30:55'): # 下单10万元\n# _flag = context.order_value(context.symbol, 100000, price=None, order_type=OrderType.MARKET)\n# context.write_log(\"买入10万元, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n# if (curtime >= '11:00:00') and (curtime < '11:00:55'): # 将数量下到1万股\n# _flag = context.order_target(context.symbol, 10000, price=None, order_type=OrderType.MARKET)\n# context.write_log(\"将数量下到1万股, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n# if curdate == '2023-03-02':\n# if (curtime >= '11:15:00') and (curtime < '11:15:55'): # 卖出500股\n# _flag = context.order(context.symbol, -500, price=None, order_type=OrderType.MARKET)\n# context.write_log(\"卖500股, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n# if (curtime >= '13:01:00') and (curtime < '13:01:55'): # 卖到持仓1%\n# _flag = context.order_target_percent(context.symbol, 0.01, price=None, order_type=OrderType.MARKET)\n# context.write_log(\"卖到持仓1%, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n# if (curtime >= '14:01:00') and (curtime < '14:01:55'): # 清仓\n# _flag = context.order_target(context.symbol, 0, price=None, order_type=OrderType.MARKET)\n# context.write_log(\"清仓, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n \n \n ######################## 数据获取函数说明 ############################ \n if (curdate == '2023-03-01') and (curtime >= '09:40:00') and (curtime < '09:40:55'):\n # 交易前\n msg = ''\n account = context.get_trading_account()\n msg += \"\\n【交易前】账户信息!日期:{}, 时间:{}, 总资产:{}, 总持仓市值:{}, 可用资金:{}\".format(curdate, curtime, account.portfolio_value, account.positions_value, account.available)\n pos = context.get_account_position(context.symbol)\n msg += \"\\n【交易前】持仓信息!日期:{}, 时间:{}, 最新价:{}, 持仓均价:{}, 总持仓:{}, 可用数量:{}\".format(curdate, curtime, pos.last_price, pos.cost_price, pos.today_qty, pos.avail_qty)\n context.write_log(msg, stdout=1)\n \n # 交易中\n _flag = context.order(context.symbol, 500, price=None, order_type=OrderType.MARKET)\n context.write_log(\"买入500股, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n\n _flag = context.order(context.symbol, 500, price=16.5, order_type=OrderType.LIMIT)\n context.write_log(\"买入500股挂单, 时间:{}, 返回标识:{}\".format(curtime, _flag), stdout=1)\n \n if (curdate == '2023-03-01') and (curtime >= '10:40:00') and (curtime < '10:40:55'):\n # 当日交易后\n msg = ''\n all_pos = context.get_account_positions()\n msg += \"\\n【当日交易后】日期:{}, 时间:{}, 所有持仓:{}\".format(curdate, curtime, all_pos)\n open_orders = context.get_open_orders(context.symbol)\n msg += \"\\n【当日交易后】日期:{}, 时间:{}, 所有挂单:{}\".format(curdate, curtime, open_orders)\n orders = context.get_orders(context.symbol)\n msg += \"\\n【当日交易后】日期:{}, 时间:{}, 所有订单:{}\".format(curdate, curtime, orders) \n trades = context.get_trades(context.symbol)\n msg += \"\\n【当日交易后】日期:{}, 时间:{}, 所有成交单:{}\".format(curdate, curtime, trades) \n context.write_log(msg, stdout=1) \n \n \n if (curdate == '2023-03-02') and (curtime >= '09:40:00') and (curtime < '09:40:55'):\n # 次日交易后\n msg = ''\n account = context.get_trading_account()\n msg += \"\\n【交易后】账户信息!日期:{}, 时间:{}, 总资产:{}, 总持仓市值:{}, 可用资金:{}\".format(curdate, curtime, account.portfolio_value, account.positions_value, account.available)\n pos = context.get_account_position(context.symbol)\n msg += \"\\n【交易后】持仓信息!日期:{}, 时间:{}, 最新价:{}, 持仓均价:{}, 可用数量:{}\".format(curdate, curtime, pos.last_price, pos.cost_price, pos.avail_qty)\n context.write_log(msg, stdout=1)\n ","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, trade):\n curtime = pd.to_datetime(trade.trade_time).strftime('%H:%M:%S')\n context.write_log(\"[成交回报] direction:{}, offset:{}, orderID:{}, tradeID:{}, price:{}, volume:{}, time:{}\".format(trade.direction, trade.offset, trade.order_id, trade.trade_id, trade.filled_price, trade.filled_qty, curtime), stdout=1)\n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, order):\n curtime = pd.to_datetime(order.order_time).strftime('%H:%M:%S')\n context.write_log('[委托回报] direction:{}, offset:{}, orderID:{}, price:{}, totalVolume:{}, tradedVolume:{}, status: {}, time:{}'.format(order.direction, order.offset, order.order_id, order.order_price, order.order_qty, order.filled_qty, order.order_status, curtime), stdout=1)\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":"100000","type":"Literal","bound_global_parameter":null},{"name":"frequency","value":"minute","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":"volume_limit","value":1,"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":"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":"-40"},{"name":"options_data","node_id":"-40"},{"name":"history_ds","node_id":"-40"},{"name":"benchmark_ds","node_id":"-40"}],"output_ports":[{"name":"raw_perf","node_id":"-40"}],"cacheable":false,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-66","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2023-03-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2023-03-02","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"000002.SZA","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-66"}],"output_ports":[{"name":"data","node_id":"-66"}],"cacheable":false,"seq_num":2,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-40' Position='77,433,200,200'/><node_position Node='-66' Position='58,283,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2023-03-10 11:42:02.222918] INFO: moduleinvoker: instruments.v2 开始运行..
[2023-03-10 11:42:02.248306] INFO: moduleinvoker: instruments.v2 运行完成[0.025379s].
[2023-03-10 11:42:02.275026] INFO: moduleinvoker: hfbacktest.v1 开始运行..
[2023-03-10 11:42:02.281300] INFO: hfbacktest: biglearning V1.4.20
[2023-03-10 11:42:02.282518] INFO: hfbacktest: bigtrader v1.9.13 2023-03-03
[2023-03-10 11:42:02.297197] INFO: moduleinvoker: cached.v2 开始运行..
[2023-03-10 11:42:02.304354] INFO: moduleinvoker: 命中缓存
[2023-03-10 11:42:02.305619] INFO: moduleinvoker: cached.v2 运行完成[0.00843s].
[2023-03-10 11:42:02.509033] INFO: moduleinvoker: cached.v2 开始运行..
[2023-03-10 11:42:02.517195] INFO: moduleinvoker: 命中缓存
[2023-03-10 11:42:02.518472] INFO: moduleinvoker: cached.v2 运行完成[0.009452s].
[2023-03-10 11:42:03.811964] INFO: hfbacktest: backtest done, raw_perf_ds:DataSource(8191b54fdbc04652a5a12ec3c9887eacT)
[2023-03-10 11:42:04.757703] INFO: moduleinvoker: hfbacktest.v1 运行完成[2.482679s].
[2023-03-10 11:42:04.759216] INFO: moduleinvoker: hftrade.v2 运行完成[2.504215s].
2023-03-10 11:42:02.635505 init history datas...
2023-03-10 11:42:02.637532 init history datas done.
2023-03-10 11:42:02.641950 run_backtest() capital_base:100000, frequency:1m, product_type:equity, date:2023-03-01 ~ 2023-03-02
2023-03-10 11:42:02.643333 run_backtest() running...
2023-03-10 11:42:02.651669 initial contracts len=0
2023-03-10 11:42:02.654198 backtest inited.
2023-03-10 11:42:02.656496 backtest transforming 1m, bars=1...
2023-03-10 11:42:02.658055 transform start_trading_day=2023-03-01 00:00:00, simulation period=2023-03-01 ~ 2023-03-02
2023-03-10 11:42:02.659344 transform before_start_days=0
2023-03-10 11:42:02.660554 transform replay_func=<cyfunction BacktestEngine.transform.<locals>.replay_bars_dt at 0x7f3d469b82b0>
2023-03-10 11:42:02.704052 strategy(bkt000,):
【交易前】账户信息!日期:2023-03-01, 时间:09:40:00, 总资产:100000, 总持仓市值:0, 可用资金:100000
【交易前】持仓信息!日期:2023-03-01, 时间:09:40:00, 最新价:0.0, 持仓均价:0.0, 总持仓:0, 可用数量:0
2023-03-10 11:42:02.706240 strategy(bkt000,): [委托回报] direction:1, offset:0, orderID:1, price:17.1499, totalVolume:500, tradedVolume:0, status: 0, time:09:40:00
2023-03-10 11:42:02.707442 strategy(bkt000,): 买入500股, 时间:09:40:00, 返回标识:0
2023-03-10 11:42:02.708856 strategy(bkt000,): [委托回报] direction:1, offset:0, orderID:2, price:17.1499, totalVolume:500, tradedVolume:0, status: 0, time:09:40:00
2023-03-10 11:42:02.709717 strategy(bkt000,): 买入500股挂单, 时间:09:40:00, 返回标识:0
2023-03-10 11:42:02.711560 strategy(bkt000,): [委托回报] direction:1, offset:0, orderID:1, price:17.1499, totalVolume:500, tradedVolume:500, status: 2, time:09:40:00
2023-03-10 11:42:02.712770 strategy(bkt000,): [成交回报] direction:1, offset:0, orderID:1, tradeID:1, price:17.15999984741211, volume:500, time:09:41:00
2023-03-10 11:42:02.714442 strategy(bkt000,): [委托回报] direction:1, offset:0, orderID:2, price:17.1499, totalVolume:500, tradedVolume:500, status: 2, time:09:40:00
2023-03-10 11:42:02.715586 strategy(bkt000,): [成交回报] direction:1, offset:0, orderID:2, tradeID:2, price:17.15, volume:500, time:09:41:00
2023-03-10 11:42:02.717062 strategy(bkt000,):
【当日交易后】日期:2023-03-01, 时间:10:40:00, 所有持仓:{'000002.SZA': StockPosition(bkt000,000002.SZA,LONG,current_qty:1000,avail_qty:0,cost_price:17.155,last_price:17.15,margin:0.0)}
【当日交易后】日期:2023-03-01, 时间:10:40:00, 所有挂单:[]
【当日交易后】日期:2023-03-01, 时间:10:40:00, 所有订单:[OrderData({'gateway_name': '', 'broker_id': 'BACKTEST', 'account_id': 'bkt000', 'acct_type': '0', 'instrument': '000002', 'exchange': 'SZSE', 'symbol': '000002.SZA', 'trading_day': '20230301', 'order_id': '1', 'order_sysid': '1', 'bt_order_sysid': 'SZSE.1', 'basket_id': '', 'direction': '1', 'offset': '0', 'covered_flag': '', 'order_price': 17.1499, 'order_qty': 500, 'filled_qty': 500, 'avg_price': 17.16, 'filled_money': 8579.999923706055, 'order_type': 'U', 'order_status': ALLTRADED(2), 'order_property': '', 'entrust_type': '0', 'insert_date': '20230301', 'order_time': '09:40:00', 'cancel_time': '', 'order_datetime': '20230301 09:40:00', 'underlying': '', 'underlying_name': '', 'name': '', 'optcontract_id': '', 'front_id': 0, 'session_id': 0, 'status_msg': '全部成交', 'user_id': 'strategy', 'contract': Equity(1 [000002.SZA]), 'order_key': '1_0_0', 'corr_id': '', 'is_last': False, 'sim_que_volume': 0, 'sim_last_volume': 0}), OrderData({'gateway_name': '', 'broker_id': 'BACKTEST', 'account_id': 'bkt000', 'acct_type': '0', 'instrument': '000002', 'exchange': 'SZSE', 'symbol': '000002.SZA', 'trading_day': '20230301', 'order_id': '2', 'order_sysid': '2', 'bt_order_sysid': 'SZSE.2', 'basket_id': '', 'direction': '1', 'offset': '0', 'covered_flag': '', 'order_price': 17.1499, 'order_qty': 500, 'filled_qty': 500, 'avg_price': 17.15, 'filled_money': 8575.0, 'order_type': '0', 'order_status': ALLTRADED(2), 'order_property': '', 'entrust_type': '0', 'insert_date': '20230301', 'order_time': '09:40:00', 'cancel_time': '', 'order_datetime': '20230301 09:40:00', 'underlying': '', 'underlying_name': '', 'name': '', 'optcontract_id': '', 'front_id': 0, 'session_id': 0, 'status_msg': '全部成交', 'user_id': 'strategy', 'contract': Equity(1 [000002.SZA]), 'order_key': '2_0_0', 'corr_id': '', 'is_last': False, 'sim_que_volume': 0, 'sim_last_volume': 0})]
【当日交易后】日期:2023-03-01, 时间:10:40:00, 所有成交单:[TradeData({'gateway_name': '', 'broker_id': 'BACKTEST', 'account_id': 'bkt000', 'acct_type': '0', 'instrument': '000002', 'exchange': 'SZSE', 'symbol': '000002.SZA', 'order_id': '1', 'order_sysid': '1', 'bt_order_sysid': 'SZSE.1', 'basket_id': '', 'trade_id': '1', 'bt_trade_id': 'SZSE.1', 'direction': '1', 'offset': '0', 'entrust_type': '0', 'covered_flag': '', 'filled_price': 17.16, 'filled_qty': 500, 'filled_money': 8579.999923706055, 'underlying_price': 0.0, 'trading_day': '20230301', 'trade_date': '20230301', 'trade_time': '09:41:00.000000', 'trade_datetime': '20230301 09:41:00.000000', 'underlying': '', 'name': '万科A', 'optcontract_id': '', 'margin': 0.0, 'commission': 5.0, 'user_id': 'strategy', 'realized_pnl': 0.0, 'contract': Equity(1 [000002.SZA]), 'order_key': '1_0_0', 'is_last': False}), TradeData({'gateway_name': '', 'broker_id': 'BACKTEST', 'account_id': 'bkt000', 'acct_type': '0', 'instrument': '000002', 'exchange': 'SZSE', 'symbol': '000002.SZA', 'order_id': '2', 'order_sysid': '2', 'bt_order_sysid': 'SZSE.2', 'basket_id': '', 'trade_id': '2', 'bt_trade_id': 'SZSE.2', 'direction': '1', 'offset': '0', 'entrust_type': '0', 'covered_flag': '', 'filled_price': 17.15, 'filled_qty': 500, 'filled_money': 8575.0, 'underlying_price': 0.0, 'trading_day': '20230301', 'trade_date': '20230301', 'trade_time': '09:41:00.000000', 'trade_datetime': '20230301 09:41:00.000000', 'underlying': '', 'name': '万科A', 'optcontract_id': '', 'margin': 0.0, 'commission': 5.0, 'user_id': 'strategy', 'realized_pnl': 0.0, 'contract': Equity(1 [000002.SZA]), 'order_key': '2_0_0', 'is_last': False})]
2023-03-10 11:42:02.722082 strategy(bkt000,):
【交易后】账户信息!日期:2023-03-02, 时间:09:40:00, 总资产:100055.00129699707, 总持仓市值:17220.001220703125, 可用资金:82835.00007629395
【交易后】持仓信息!日期:2023-03-02, 时间:09:40:00, 最新价:17.220001220703125, 持仓均价:17.154999923706054, 可用数量:1000
2023-03-10 11:42:02.725807 backtest run end!
2023-03-10 11:42:02.740261 run_backtest() finished! time cost 0.096s!
- 收益率-0.43%
- 年化收益率-40.99%
- 基准收益率-0.22%
- 阿尔法-0.66
- 贝塔0.33
- 夏普比率-9.44
- 胜率0.0
- 盈亏比0.0
- 收益波动率6.11%
- 信息比率-1.05
- 最大回撤0.49%
bigcharts-data-start/{"__type":"tabs","__id":"bigchart-71da895fa00f430b9570a9063e1c9a21"}/bigcharts-data-end