复制链接
克隆策略

HFTrade 主函数

  1. 初始化函数 >>> initialize_bigquant_run(context) 策略初始化函数,只触发一次。可以在该函数中初始化一些变量,如读取配置等
  2. 盘前处理函数 >>> before_trading_start_bigquant_run(context, data) 策略盘前交易函数,每日盘前触发一次。可以在该函数中一些启动前的准备,如订阅行情等
  3. tick数据处理函数 >>> handle_tick_bigquant_run(context, tick) Tick快照行情通知函数,每个标的的行情有变化时则会触发
  4. bar数据处理函数 >>> handle_data_bigquant_run(context, data) Bar行情通知函数,每个bar时间周期会触发,包括日线和分钟。
  5. 成交回报处理函数 >>> handle_trade_bigquant_run(context, trade) 成交回报通知函数,有成交时会触发。
  6. 委托回报处理函数 >>> handle_order_bigquant_run(context, order) 委托回报通知函数,每个订单状态有变化时会触发。
  7. 盘后处理函数 >>> after_trading_bigquant_run(context, data)

常见对象说明

  1. 账户信息 >>> TradingAccount(StockTradingAccount/FutureTradingAccount)
  2. 持仓信息 >>> Position(StockPosition/FuturePosition)
  3. 委托信息 >>> OrderData
  4. 成交数据 >>> TradeData
  5. Tick对象 >>> TickData
  6. Bar对象 >>> BarDataBar
  7. Dataduix >>> BarDatasBar行情访问(注意不是单个bar数据)

交易函数

  1. order(symbol, volume, price, order_type=OrderType.LIMIT, offset=Offset.NONE) 必须指定标的、下单数量、下单价格
  2. order_percent(symbol, percent, price, order_type=OrderType.LIMIT) 按比例下单[股票],必须指定标的、资金仓位比例、下单价格, 只针对买单
  3. order_value(symbol, value, price, order_type=OrderType.LIMIT) 按价值下单[股票],必须指定标的、资金、下单价格, 只针对买单
  4. order_target(symbol, target, price, order_type=OrderType.LIMIT) 下单[股票],必须指定标的、目标数量、下单价格, 多用于清空持仓
  5. order_target_percent(symbol,target_percent, price, order_type=OrderType.LIMIT) 按目标比例下单[股票],必须指定标的、资金仓位比例、下单价格, 只针对买单

数据接口

  1. 获取持仓 >>> get_account_position(symbol, direction=Direction.NONE, create_if_none=True)
  2. 获取挂单 >>> get_open_orders(symbol='')
  3. 获取订单 >>> get_orders(symbol='')
  4. 获取成交 >>> get_trades(symbol='')

其他接口

  1. 获取策略设置 >>> get_conf_param(name, d=None)
  2. 获取错误信息 >>> get_error_msg(error_id)
  3. 打印日志 >>> write_log(content, level="info", stdout=0)
  4. 计算可买量 >>> calc_buy_volume(symbol, price, value)
In [104]:
DataSource('bar1m_CN_STOCK_A').read(instruments='000002.SZA', start_date='2023-03-01 09:38:00')
Out[104]:
date open close low high amount volume instrument
0 2023-03-01 09:38:00 17.139999 17.139999 17.129999 17.150000 6743141.0 393500 000002.SZA
1 2023-03-01 09:39:00 17.139999 17.120001 17.110001 17.139999 5989120.0 349700 000002.SZA
2 2023-03-01 09:40:00 17.110001 17.150000 17.110001 17.160000 22327804.0 1302529 000002.SZA
3 2023-03-01 09:41:00 17.160000 17.139999 17.139999 17.190001 9975187.0 581000 000002.SZA
4 2023-03-01 09:42:00 17.139999 17.129999 17.129999 17.160000 5217671.0 304400 000002.SZA
... ... ... ... ... ... ... ... ...
1668 2023-03-09 14:56:00 16.120001 16.120001 16.110001 16.120001 4339571.0 269200 000002.SZA
1669 2023-03-09 14:57:00 16.120001 16.120001 16.120001 16.129999 4543944.0 281831 000002.SZA
1670 2023-03-09 14:58:00 16.129999 16.129999 16.129999 16.129999 137099.0 8500 000002.SZA
1671 2023-03-09 14:59:00 16.129999 16.129999 16.129999 16.129999 0.0 0 000002.SZA
1672 2023-03-09 15:00:00 16.120001 16.120001 16.120001 16.120001 7523188.0 466699 000002.SZA

1673 rows × 8 columns

    {"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"}
    In [102]:
    # 本代码由可视化策略环境自动生成 2023年3月10日 11:49
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 交易引擎:初始化函数,只执行一次
    def m1_initialize_bigquant_run(context):
        # 加载预测数据
        context.symbol = '000002.SZA'
    
    # 交易引擎:每个单位时间开盘前调用一次。
    def m1_before_trading_start_bigquant_run(context, data):
        # 盘前处理,订阅行情等
    #     context.subscribe(context.symbol)
        context.subscribe_bar(context.symbol, '1m')
    
    # 交易引擎:tick数据处理函数,每个tick执行一次
    def m1_handle_tick_bigquant_run(context, tick):
        pass
    #     curdate = tick.trading_day.strftime('%Y-%m-%d')
    #     curtime = tick.time.strftime('%H:%M:%S')
    #     context.write_log("当前时间:{}, 当前时间:{}, 股票代码:{}, 卖一价:{}, 买一价:{}".format(curdate, curtime, tick.instrument, tick.ask_price1, tick.bid_price1), stdout=1)
    
    # 交易引擎:bar数据处理函数,每个时间单位执行一次
    def m1_handle_data_bigquant_run(context, data):
    #     pass
        curdate = data.current_dt.strftime('%Y-%m-%d')
        curtime = data.current_dt.strftime('%H:%M:%S')
    #     context.write_log("当前时间:{}, 当前时间:{}, 合约,当前bar的收盘价:{}".format(curdate, curtime, data.get_daily_value(context.symbol, 'close')), stdout=1)
        
        
        ######################## 下单函数说明 ############################
    #     if curdate == '2023-03-01':
    #         if (curtime >= '09:40:00') and (curtime < '09:40:55'):          # 下单卖出股
    #             _flag = context.order(context.symbol, 500, price=None, order_type=OrderType.MARKET)
    #             context.write_log("买入500股, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
    #         if (curtime >= '10:00:00') and (curtime < '10:00:55'):        # 下单5%
    #             _flag = context.order_percent(context.symbol, 0.05, price=None, order_type=OrderType.MARKET)
    #             context.write_log("买入仓位5%, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
    #         if (curtime >= '10:30:00') and (curtime < '10:30:55'):        # 下单10万元
    #             _flag = context.order_value(context.symbol, 100000, price=None, order_type=OrderType.MARKET)
    #             context.write_log("买入10万元, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
    #         if (curtime >= '11:00:00') and (curtime < '11:00:55'):        # 将数量下到1万股
    #             _flag = context.order_target(context.symbol, 10000, price=None, order_type=OrderType.MARKET)
    #             context.write_log("将数量下到1万股, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
    #     if curdate == '2023-03-02':
    #         if (curtime >= '11:15:00') and (curtime < '11:15:55'):        # 卖出500股
    #             _flag = context.order(context.symbol, -500, price=None, order_type=OrderType.MARKET)
    #             context.write_log("卖500股, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
    #         if (curtime >= '13:01:00') and (curtime < '13:01:55'):        # 卖到持仓1%
    #             _flag = context.order_target_percent(context.symbol, 0.01, price=None, order_type=OrderType.MARKET)
    #             context.write_log("卖到持仓1%, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
    #         if (curtime >= '14:01:00') and (curtime < '14:01:55'):        # 清仓
    #             _flag = context.order_target(context.symbol, 0, price=None, order_type=OrderType.MARKET)
    #             context.write_log("清仓, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
                
                
        ######################## 数据获取函数说明 ############################    
        if (curdate == '2023-03-01') and (curtime >= '09:40:00') and (curtime < '09:40:55'):
            # 交易前
            msg = ''
            account = context.get_trading_account()
            msg += "\n【交易前】账户信息!日期:{}, 时间:{}, 总资产:{}, 总持仓市值:{}, 可用资金:{}".format(curdate, curtime, account.portfolio_value, account.positions_value, account.available)
            pos = context.get_account_position(context.symbol)
            msg += "\n【交易前】持仓信息!日期:{}, 时间:{}, 最新价:{}, 持仓均价:{}, 总持仓:{}, 可用数量:{}".format(curdate, curtime, pos.last_price, pos.cost_price, pos.today_qty, pos.avail_qty)
            context.write_log(msg, stdout=1)
            
            # 交易中
            _flag = context.order(context.symbol, 500, price=None, order_type=OrderType.MARKET)
            context.write_log("买入500股, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
    
            _flag = context.order(context.symbol, 500, price=16.5, order_type=OrderType.LIMIT)
            context.write_log("买入500股挂单, 时间:{}, 返回标识:{}".format(curtime, _flag), stdout=1)
            
        if (curdate == '2023-03-01') and (curtime >= '10:40:00') and (curtime < '10:40:55'):
            # 当日交易后
            msg = ''
            all_pos = context.get_account_positions()
            msg += "\n【当日交易后】日期:{}, 时间:{}, 所有持仓:{}".format(curdate, curtime, all_pos)
            open_orders = context.get_open_orders(context.symbol)
            msg += "\n【当日交易后】日期:{}, 时间:{}, 所有挂单:{}".format(curdate, curtime, open_orders)
            orders = context.get_orders(context.symbol)
            msg += "\n【当日交易后】日期:{}, 时间:{}, 所有订单:{}".format(curdate, curtime, orders)   
            trades = context.get_trades(context.symbol)
            msg += "\n【当日交易后】日期:{}, 时间:{}, 所有成交单:{}".format(curdate, curtime, trades) 
            context.write_log(msg, stdout=1)        
            
            
        if (curdate == '2023-03-02') and (curtime >= '09:40:00') and (curtime < '09:40:55'):
            # 次日交易后
            msg = ''
            account = context.get_trading_account()
            msg += "\n【交易后】账户信息!日期:{}, 时间:{}, 总资产:{}, 总持仓市值:{}, 可用资金:{}".format(curdate, curtime, account.portfolio_value, account.positions_value, account.available)
            pos = context.get_account_position(context.symbol)
            msg += "\n【交易后】持仓信息!日期:{}, 时间:{}, 最新价:{}, 持仓均价:{}, 可用数量:{}".format(curdate, curtime, pos.last_price, pos.cost_price, pos.avail_qty)
            context.write_log(msg, stdout=1)
            
    # 交易引擎:成交回报处理函数,每个成交发生时执行一次
    def m1_handle_trade_bigquant_run(context, trade):
        curtime = pd.to_datetime(trade.trade_time).strftime('%H:%M:%S')
        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)
    
    # 交易引擎:委托回报处理函数,每个委托变化时执行一次
    def m1_handle_order_bigquant_run(context, order):
        curtime = pd.to_datetime(order.order_time).strftime('%H:%M:%S')
        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)
    
    # 交易引擎:盘后处理函数,每日盘后执行一次
    def m1_after_trading_bigquant_run(context, data):
        pass
    
    
    m2 = M.instruments.v2(
        start_date='2023-03-01',
        end_date='2023-03-02',
        market='CN_STOCK_A',
        instrument_list='000002.SZA',
        max_count=0,
        m_cached=False
    )
    
    m1 = M.hftrade.v2(
        instruments=m2.data,
        start_date='',
        end_date='',
        initialize=m1_initialize_bigquant_run,
        before_trading_start=m1_before_trading_start_bigquant_run,
        handle_tick=m1_handle_tick_bigquant_run,
        handle_data=m1_handle_data_bigquant_run,
        handle_trade=m1_handle_trade_bigquant_run,
        handle_order=m1_handle_order_bigquant_run,
        after_trading=m1_after_trading_bigquant_run,
        capital_base=100000,
        frequency='minute',
        price_type='真实价格',
        product_type='股票',
        before_start_days='0',
        volume_limit=1,
        order_price_field_buy='open',
        order_price_field_sell='close',
        benchmark='000300.HIX',
        plot_charts=True,
        disable_cache=False,
        replay_bdb=False,
        show_debug_info=False,
        backtest_only=False
    )
    
    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

    常见定量说明

    1. Direction:买卖方向/持仓方向
    2. Offset:开平标志
    3. OrderType:委托类型
    4. OrderStatus:委托状态
    5. Frequency:频率
    6. AdjustType:复权类型
    7. Product:产品类别
    In [103]:
    Direction.SHORT
    
    Out[103]:
    '2'