复制链接
克隆策略

策略名称

R-Breaker日内策略

策略思路

R-Breaker是一种短线日内交易策略。根据前一个交易日的收盘价(C)、最高价(H)和最低价(L)数据通过一定方式计算出六个价位,从大到小依次为: 突破买入价、观察卖出价、反转卖出价、反转买入、观察买入价、突破卖出价。 中心价位P = (H + C + L)/3 突破买入价 = H + 2P -2L 观察卖出价 = P + H - L 反转卖出价 = 2P - L 反转买入价 = 2P - H 观察买入价 = P - (H - L) 突破卖出价 = L - 2(H - P)

空仓时:突破策略 空仓时,当盘中价格>突破买入价,则认为上涨的趋势还会继续,开仓做多; 空仓时,当盘中价格<突破卖出价,则认为下跌的趋势还会继续,开仓做空。

持仓时:反转策略 持多单时:当日内最高价>观察卖出价后,盘中价格回落,跌破反转卖出价构成的支撑线时,采取反转策略,即做空; 持空单时:当日内最低价<观察买入价后,盘中价格反弹,超过反转买入价构成的阻力线时,采取反转策略,即做多。

In [6]:
from datetime import datetime,timedelta
from bigtrader.constant import *
from biglearning.api import M
import numpy as np

def initialize(context):
    """初始化"""
    print("initialize")  
    context.ins = context.instruments[0] #从传入参数中获取需要交易的合约
    context.order_num = 2 #下单手数
    context.set_universe(context.ins)#设置需要处理的合约
    context.stopLossPrice = 50    # 设置止损点数
    
    context.closetime_day = "14:58" #日内策略白盘平仓时间,一般14:58
    context.closetime_night = "22:58" #日内策略夜盘平仓时间,一般22:58,注意有些商品夜盘收盘时间不一样
    
def before_trading(context, data):
    """盘前处理"""
    #print("before_trading")
    context.subscribe(context.ins) #注册合约
    context.max_high = 0 #当日最高价
    context.max_low = 0 #当日最低价
    hist = data.history(context.ins, ["high","low","open","close"], 1, "1d")

    high = hist['high'][0]  # 前一日的最高价
    low = hist['low'][0]  # 前一日的最低价
    close = hist['close'][0]  # 前一日的收盘价
    pivot = (high + low + close) / 3  # 枢轴点
    context.bBreak = high + 2 * (pivot - low)  # 突破买入价 
    context.sSetup = pivot + (high - low)  # 观察卖出价
    context.sEnter = 2 * pivot - low  # 反转卖出价
    context.bEnter = 2 * pivot - high  # 反转买入价
    context.bSetup = pivot - (high - low)  # 观察买入价
    context.sBreak = low - 2 * (high - pivot)  # 突破卖出价

    
def handle_data(context, data):
    """Bar行情推送"""
    cur_date =  data.current_dt
    cur_hm = cur_date.strftime('%H:%M') 
    
    #获取当日最高价和最低价
    today_high = data.current(context.ins,'high')
    today_low = data.current(context.ins,'low')
    
    context.max_high = max(context.max_high,today_high)
    context.max_low = max(context.max_high,today_low) 
    
    # 分别获取多头持仓,和空头持仓
    position_long = context.get_position(context.ins, Direction.LONG)
    position_short = context.get_position(context.ins, Direction.SHORT)
    
    # 获取当前价格
    price = data.current(context.ins, "close")
    
    #部分品种夜盘收盘时间不一样,此时间表示指定的尾盘平仓时间往后偏移30分钟,这段时间内不能开新仓,只能平仓。给30分钟是为了足够的冗余
    closetime_nightshift = (datetime.strptime(context.closetime_night,'%H:%M') + timedelta(minutes = 30)).strftime('%H:%M')
    #尾盘平仓
    if((cur_hm>=context.closetime_day and cur_hm<="15:00") or (cur_hm>=context.closetime_night and cur_hm<=closetime_nightshift)):
        if(position_long.current_qty != 0):
            rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
            msg = "{} 尾盘平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
            context.write_log(msg, stdout=1) #输出关键日志
        if(position_short.current_qty != 0):
            rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
            msg = "{} 尾盘平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
            context.write_log(msg, stdout=1) #输出关键日志
        #尾盘不开新仓,直接返回
        return
        
    # 突破策略:
    if position_long.current_qty == 0 and position_short.current_qty == 0:  # 空仓条件下
        if price > context.bBreak:
            # 在空仓的情况下,如果盘中价格超过突破买入价,则采取趋势策略,即在该点位开仓做多
            rv = context.buy_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
            msg = "{} 开多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
            context.write_log(msg, stdout=1) #输出关键日志
            context.open_position_price = price
        elif price < context.sBreak:
            # 在空仓的情况下,如果盘中价格跌破突破卖出价,则采取趋势策略,即在该点位开仓做空
            rv = context.sell_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
            msg = "{} 开空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
            context.write_log(msg, stdout=1) #输出关键日志
            context.open_position_price = price
    # 设置止损条件
    else:  # 有持仓时
        # 开仓价与当前行情价之差大于止损点则止损
        if (position_long.current_qty != 0 and context.open_position_price - price >= context.stopLossPrice) or \
                (position_short.current_qty != 0 and price - context.open_position_price >= context.stopLossPrice):
            context.write_log('达到止损点,全部平仓', stdout=1) #输出关键日志
            if(position_long.current_qty != 0):
                rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 止损平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
            if(position_short.current_qty != 0):
                rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 止损平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
        # 反转策略:
        if position_long.current_qty != 0:  # 多仓条件下
            if context.max_high > context.sSetup and price < context.sEnter:
                # 多头持仓,当日内最高价超过观察卖出价后
                # 盘中价格出现回落,且进一步跌破反转卖出价构成的支撑线时
                # 采取反转策略,即在该点位反手做空
                context.write_log('多头持仓,当日内最高价超过观察卖出价后跌破反转卖出价: 反手做空', stdout=1) #输出关键日志
                rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
                
                rv = context.sell_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                context.open_position_price = price
                msg = "{} 开空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志  
                
        elif position_short.current_qty != 0:  # 空头持仓
            if context.max_low < context.bSetup and price > context.bEnter:
                # 空头持仓,当日内最低价低于观察买入价后,
                # 盘中价格出现反弹,且进一步超过反转买入价构成的阻力线时,
                # 采取反转策略,即在该点位反手做多
                context.write_log('空头持仓,当日最低价低于观察买入价后超过反转买入价: 反手做多', stdout=1) #输出关键日志
                rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
                
                rv = context.buy_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                context.open_position_price = price
                msg = "{} 开多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志   
                

def handle_order(context, order):
    """委托回报推送"""
    msg = "handle_order data:{}".format(order.log_str())
    context.write_log(msg, stdout=1)
         
def handle_trade(context, trade):
    """成交回报推送"""
    msg = "handle_trade data:{}".format(trade.log_str())
    context.write_log(msg, stdout=1) 
    # 分别获取最新的多头持仓和空头持仓
    position_long = context.get_position(trade.symbol, Direction.LONG)
    position_short = context.get_position(trade.symbol, Direction.SHORT)
    msg = "当前多头持仓:{} 当前空头持仓:{}".format(str(position_long),str(position_short))
    context.write_log(msg, stdout=1) 
    
instruments = "RB2005.SHF"

#需要交易者传入的参数
strategy_setting = [
    {
        "instruments": instruments,
        "order_num": 2,
        "closetime_day": "14:58",
        "closetime_night": "22:58"
    }    
]
start_date = "2020-01-21"
end_date = "2020-04-01"
md = M.hftrade.v2(start_date=start_date,
                     end_date=end_date,
                     instruments=[instruments], #只传入一个合约便于策略逻辑展示
                     capital_base=100000,
                     product_type=Product.FUTURE,
                     frequency=Frequency.MINUTE,
                     initialize=initialize,
                     before_trading_start=before_trading,
                     handle_data=handle_data,
                     handle_order=handle_order,
                     handle_trade=handle_trade,
                     plot_charts=True,
                     volume_limit=1.0,
                     show_debug_info=1,
                     before_start_days=10,
                     m_deps=np.random.rand())
[2023-05-22 15:24:07.396769] INFO moduleinvoker: hfbacktest.v2 开始运行..
[2023-05-22 15:24:07.404442] INFO hfbacktest: passed-in daily_data_ds:None
[2023-05-22 15:24:07.406223] INFO hfbacktest: passed-in minute_data_ds:None
[2023-05-22 15:24:07.408079] INFO hfbacktest: passed-in tick_data_ds:None
[2023-05-22 15:24:07.409679] INFO hfbacktest: passed-in each_data_ds:None
[2023-05-22 15:24:07.411032] INFO hfbacktest: passed-in dominant_data_ds:None
[2023-05-22 15:24:07.412326] INFO hfbacktest: passed-in basic_data_ds:None
[2023-05-22 15:24:07.413734] INFO hfbacktest: passed-in benchmark_data_ds:None
[2023-05-22 15:24:07.415214] INFO hfbacktest: hfbacktest2 V2.0.0
[2023-05-22 15:24:07.416449] INFO hfbacktest: pytradersdk v1.0.0 2023-05-19
[2023-05-22 15:24:07.442308] INFO hfbacktest: strategy callbacks:{'initialize': <function initialize at 0x7f09001f71f0>, 'before_trading': <function before_trading at 0x7f0900044e50>, 'handle_data': <function handle_data at 0x7f0900044d30>, 'handle_trade': <function handle_trade at 0x7f0900044f70>, 'handle_order': <function handle_order at 0x7f0900044ee0>}
[2023-05-22 15:24:07.444894] INFO hfbacktest: begin reading history data, 2020-01-21 00:00:00~2020-04-01, disable_cache:False, replay_bdb:False
[2023-05-22 15:24:07.446415] INFO hfbacktest: reading benchmark data 000300.HIX 2020-01-21 00:00:00~2020-04-01...
[2023-05-22 15:24:07.467035] INFO moduleinvoker: cached.v2 开始运行..
[2023-05-22 15:24:07.492300] INFO moduleinvoker: 命中缓存
[2023-05-22 15:24:07.496322] INFO moduleinvoker: cached.v2 运行完成[0.029245s].
[2023-05-22 15:24:07.609612] INFO hfbacktest: reading daily data 2019-01-21 00:00:00~2020-04-01...
[2023-05-22 15:24:07.624802] INFO moduleinvoker: cached.v2 开始运行..
[2023-05-22 15:24:07.636795] INFO moduleinvoker: 命中缓存
[2023-05-22 15:24:07.638991] INFO moduleinvoker: cached.v2 运行完成[0.014256s].
[2023-05-22 15:24:07.785312] INFO hfbacktest: reading minute data 2020-01-09 20:55:00~2020-04-01...
[2023-05-22 15:24:07.831102] INFO moduleinvoker: cached.v2 开始运行..
[2023-05-22 15:24:07.860069] INFO moduleinvoker: 命中缓存
[2023-05-22 15:24:07.862759] INFO moduleinvoker: cached.v2 运行完成[0.031698s].
[2023-05-22 15:24:08.089779] INFO hfbacktest: cached_benchmark_ds:DataSource(811c07e12631498a82fd2221807eee6cT)
[2023-05-22 15:24:08.092688] INFO hfbacktest: cached_daily_ds:DataSource(db785b011ecd4f88960d5357c945667aT)
[2023-05-22 15:24:08.095361] INFO hfbacktest: cached_minute_ds:DataSource(d348283102dc4d80b0d5642ab0b4c5bdT)
[2023-05-22 15:24:08.100228] INFO hfbacktest: cached_tick_ds:None
[2023-05-22 15:24:08.102526] INFO hfbacktest: cached_each_ds:None
[2023-05-22 15:24:08.105475] INFO hfbacktest: dominant_data_ds:None
[2023-05-22 15:24:08.109301] INFO hfbacktest: read history data done, call run backtest(future,1m,100000,2020-01-21~2020-04-01) ...
[2023-05-22 15:24:08.112195] INFO hfbacktest: run_algo: PyTradeEngine ver=1.0.0
[2023-05-22 15:24:08.122427] INFO hfbacktest: run algo: init rv=0
[2023-05-22 15:24:08.135694] INFO hfbacktest: run_algo: set_history_data frequency='1m', len=13125, rv=0
[2023-05-22 15:24:08.138512] INFO hfbacktest: run_algo: add strategy funcs done rv=4, running...
initialize
2023-05-22 15:24:08.208019 2020-02-03 09:01:00 开空 for RB2005.SHF  最新价=3233.0 下单函数返回=1
2023-05-22 15:24:08.215502 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3233.0000,6(Unknown),20200203 90100000,1_0_0,pystrategy]
2023-05-22 15:24:08.238977 handle_order data:PyOrderData[bktfut,2,RB2005.SHF,'2','0',0,2,3233.0000,0(NotTraded),20200203 90100000,1_0_0,pystrategy]
2023-05-22 15:24:08.256083 handle_order data:PyOrderData[bktfut,2,RB2005.SHF,'2','0',2,2,3233.0000,2(AllTraded),20200203 90100000,1_0_0,pystrategy]
2023-05-22 15:24:08.262062 handle_trade data:PyTradeData(bktfut,2,RB2005.SHF,'2','0',2,3233.0000,     1,20200203 90200000,pystrategy,1_0_0)
2023-05-22 15:24:08.267613 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3233.0000,3233.0000,8405.80,20200203) at 0x0x7f0995062d20
2023-05-22 15:24:08.275024 达到止损点,全部平仓
2023-05-22 15:24:08.281359 2020-02-03 09:59:00 止损平空 for RB2005.SHF  最新价=3288.0 下单函数返回=2
2023-05-22 15:24:08.286543 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3288.0000,6(Unknown),20200203 95900000,2_0_0,pystrategy]
2023-05-22 15:24:08.290655 handle_order data:PyOrderData[bktfut,3,RB2005.SHF,'1','2',0,2,3288.0000,0(NotTraded),20200203 95900000,2_0_0,pystrategy]
2023-05-22 15:24:08.294632 handle_order data:PyOrderData[bktfut,3,RB2005.SHF,'1','2',2,2,3288.0000,2(AllTraded),20200203 95900000,2_0_0,pystrategy]
2023-05-22 15:24:08.301132 handle_trade data:PyTradeData(bktfut,3,RB2005.SHF,'1','2',2,3288.0000,     2,20200203 100000000,pystrategy,2_0_0)
2023-05-22 15:24:08.306531 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3233.0000,3289.0000,0.00,20200203) at 0x0x7f0995062d20
2023-05-22 15:24:08.311469 2020-02-03 10:00:00 开空 for RB2005.SHF  最新价=3289.0 下单函数返回=3
2023-05-22 15:24:08.315487 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3289.0000,6(Unknown),20200203 100000000,3_0_0,pystrategy]
2023-05-22 15:24:08.319646 handle_order data:PyOrderData[bktfut,4,RB2005.SHF,'2','0',0,2,3289.0000,0(NotTraded),20200203 100000000,3_0_0,pystrategy]
2023-05-22 15:24:08.323531 handle_order data:PyOrderData[bktfut,4,RB2005.SHF,'2','0',2,2,3289.0000,2(AllTraded),20200203 100000000,3_0_0,pystrategy]
2023-05-22 15:24:08.327365 handle_trade data:PyTradeData(bktfut,4,RB2005.SHF,'2','0',2,3289.0000,     3,20200203 100100000,pystrategy,3_0_0)
2023-05-22 15:24:08.331264 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3289.0000,3289.0000,8551.40,20200203) at 0x0x7f0995062d20
2023-05-22 15:24:08.340571 2020-02-03 14:58:00 尾盘平空 for RB2005.SHF  最新价=3233.0 下单函数返回=4
2023-05-22 15:24:08.344591 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3233.0000,6(Unknown),20200203 145800000,4_0_0,pystrategy]
2023-05-22 15:24:08.348524 handle_order data:PyOrderData[bktfut,5,RB2005.SHF,'1','2',0,2,3233.0000,0(NotTraded),20200203 145800000,4_0_0,pystrategy]
2023-05-22 15:24:08.354452 handle_order data:PyOrderData[bktfut,5,RB2005.SHF,'1','2',2,2,3233.0000,2(AllTraded),20200203 145800000,4_0_0,pystrategy]
2023-05-22 15:24:08.361694 handle_trade data:PyTradeData(bktfut,5,RB2005.SHF,'1','2',2,3233.0000,     4,20200203 145900000,pystrategy,4_0_0)
2023-05-22 15:24:08.368052 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3289.0000,3233.0000,0.00,20200203) at 0x0x7f0995062d20
2023-05-22 15:24:08.428243 2020-02-11 09:20:00 开多 for RB2005.SHF  最新价=3368.0 下单函数返回=5
2023-05-22 15:24:08.432855 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3368.0000,6(Unknown),20200211 92000000,5_0_0,pystrategy]
2023-05-22 15:24:08.436880 handle_order data:PyOrderData[bktfut,6,RB2005.SHF,'1','0',0,2,3368.0000,0(NotTraded),20200211 92000000,5_0_0,pystrategy]
2023-05-22 15:24:08.440875 handle_order data:PyOrderData[bktfut,6,RB2005.SHF,'1','0',2,2,3368.0000,2(AllTraded),20200211 92000000,5_0_0,pystrategy]
2023-05-22 15:24:08.444880 handle_trade data:PyTradeData(bktfut,6,RB2005.SHF,'1','0',2,3367.0000,     5,20200211 92100000,pystrategy,5_0_0)
2023-05-22 15:24:08.448621 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3367.0000,3367.0000,8754.20,20200211) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3371.0000,0.00,20200211) at 0x0x7f0995062d20
2023-05-22 15:24:08.459251 2020-02-11 14:58:00 尾盘平多 for RB2005.SHF  最新价=3395.0 下单函数返回=6
2023-05-22 15:24:08.463301 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3395.0000,6(Unknown),20200211 145800000,6_0_0,pystrategy]
2023-05-22 15:24:08.468559 handle_order data:PyOrderData[bktfut,7,RB2005.SHF,'2','2',0,2,3395.0000,0(NotTraded),20200211 145800000,6_0_0,pystrategy]
2023-05-22 15:24:08.484870 handle_order data:PyOrderData[bktfut,7,RB2005.SHF,'2','2',2,2,3395.0000,2(AllTraded),20200211 145800000,6_0_0,pystrategy]
2023-05-22 15:24:08.499072 handle_trade data:PyTradeData(bktfut,7,RB2005.SHF,'2','2',2,3395.0000,     6,20200211 145900000,pystrategy,6_0_0)
2023-05-22 15:24:08.506344 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3367.0000,3394.0000,0.00,20200211) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3394.0000,0.00,20200211) at 0x0x7f0995062d20
2023-05-22 15:24:08.580442 2020-02-20 09:28:00 开多 for RB2005.SHF  最新价=3441.0 下单函数返回=7
2023-05-22 15:24:08.588187 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3441.0000,6(Unknown),20200220 92800000,7_0_0,pystrategy]
2023-05-22 15:24:08.597766 handle_order data:PyOrderData[bktfut,8,RB2005.SHF,'1','0',0,2,3441.0000,0(NotTraded),20200220 92800000,7_0_0,pystrategy]
2023-05-22 15:24:08.606194 handle_order data:PyOrderData[bktfut,8,RB2005.SHF,'1','0',2,2,3441.0000,2(AllTraded),20200220 92800000,7_0_0,pystrategy]
2023-05-22 15:24:08.617240 handle_trade data:PyTradeData(bktfut,8,RB2005.SHF,'1','0',2,3441.0000,     7,20200220 92900000,pystrategy,7_0_0)
2023-05-22 15:24:08.631545 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3441.0000,3441.0000,8946.60,20200220) at 0x0x7f0995062d20 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3444.0000,0.00,20200220) at 0x0x7f0995062a40
2023-05-22 15:24:08.653772 2020-02-20 14:58:00 尾盘平多 for RB2005.SHF  最新价=3457.0 下单函数返回=8
2023-05-22 15:24:08.668402 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3457.0000,6(Unknown),20200220 145800000,8_0_0,pystrategy]
2023-05-22 15:24:08.675927 handle_order data:PyOrderData[bktfut,9,RB2005.SHF,'2','2',0,2,3457.0000,0(NotTraded),20200220 145800000,8_0_0,pystrategy]
2023-05-22 15:24:08.682525 handle_order data:PyOrderData[bktfut,9,RB2005.SHF,'2','2',2,2,3457.0000,2(AllTraded),20200220 145800000,8_0_0,pystrategy]
2023-05-22 15:24:08.691302 handle_trade data:PyTradeData(bktfut,9,RB2005.SHF,'2','2',2,3458.0000,     8,20200220 145900000,pystrategy,8_0_0)
2023-05-22 15:24:08.698690 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3441.0000,3457.0000,0.00,20200220) at 0x0x7f0995062d20 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3457.0000,0.00,20200220) at 0x0x7f0995062a40
2023-05-22 15:24:08.745823 2020-02-28 09:05:00 开空 for RB2005.SHF  最新价=3347.0 下单函数返回=9
2023-05-22 15:24:08.750480 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3347.0000,6(Unknown),20200228 90500000,9_0_0,pystrategy]
2023-05-22 15:24:08.754287 handle_order data:PyOrderData[bktfut,10,RB2005.SHF,'2','0',0,2,3347.0000,0(NotTraded),20200228 90500000,9_0_0,pystrategy]
2023-05-22 15:24:08.758222 handle_order data:PyOrderData[bktfut,10,RB2005.SHF,'2','0',2,2,3347.0000,2(AllTraded),20200228 90500000,9_0_0,pystrategy]
2023-05-22 15:24:08.762290 handle_trade data:PyTradeData(bktfut,10,RB2005.SHF,'2','0',2,3347.0000,     9,20200228 90600000,pystrategy,9_0_0)
2023-05-22 15:24:08.766062 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3340.0000,0.00,20200228) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3347.0000,3347.0000,8702.20,20200228) at 0x0x7f0995062d20
2023-05-22 15:24:08.778502 2020-02-28 14:58:00 尾盘平空 for RB2005.SHF  最新价=3333.0 下单函数返回=10
2023-05-22 15:24:08.783012 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3333.0000,6(Unknown),20200228 145800000,10_0_0,pystrategy]
2023-05-22 15:24:08.786740 handle_order data:PyOrderData[bktfut,11,RB2005.SHF,'1','2',0,2,3333.0000,0(NotTraded),20200228 145800000,10_0_0,pystrategy]
2023-05-22 15:24:08.790379 handle_order data:PyOrderData[bktfut,11,RB2005.SHF,'1','2',2,2,3333.0000,2(AllTraded),20200228 145800000,10_0_0,pystrategy]
2023-05-22 15:24:08.794099 handle_trade data:PyTradeData(bktfut,11,RB2005.SHF,'1','2',2,3334.0000,    10,20200228 145900000,pystrategy,10_0_0)
2023-05-22 15:24:08.797951 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3336.0000,0.00,20200228) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3347.0000,3336.0000,0.00,20200228) at 0x0x7f0995062d20
2023-05-22 15:24:08.840482 2020-03-09 09:02:00 开空 for RB2005.SHF  最新价=3390.0 下单函数返回=11
2023-05-22 15:24:08.845079 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3390.0000,6(Unknown),20200309 90200000,11_0_0,pystrategy]
2023-05-22 15:24:08.849301 handle_order data:PyOrderData[bktfut,12,RB2005.SHF,'2','0',0,2,3390.0000,0(NotTraded),20200309 90200000,11_0_0,pystrategy]
2023-05-22 15:24:08.853131 handle_order data:PyOrderData[bktfut,12,RB2005.SHF,'2','0',2,2,3390.0000,2(AllTraded),20200309 90200000,11_0_0,pystrategy]
2023-05-22 15:24:08.857099 handle_trade data:PyTradeData(bktfut,12,RB2005.SHF,'2','0',2,3390.0000,    11,20200309 90300000,pystrategy,11_0_0)
2023-05-22 15:24:08.860835 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3393.0000,0.00,20200309) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3390.0000,3390.0000,8814.00,20200309) at 0x0x7f0995062d20
2023-05-22 15:24:08.872215 2020-03-09 14:58:00 尾盘平空 for RB2005.SHF  最新价=3439.0 下单函数返回=12
2023-05-22 15:24:08.876441 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3439.0000,6(Unknown),20200309 145800000,12_0_0,pystrategy]
2023-05-22 15:24:08.880779 handle_order data:PyOrderData[bktfut,13,RB2005.SHF,'1','2',0,2,3439.0000,0(NotTraded),20200309 145800000,12_0_0,pystrategy]
2023-05-22 15:24:08.894261 handle_order data:PyOrderData[bktfut,13,RB2005.SHF,'1','2',2,2,3439.0000,2(AllTraded),20200309 145800000,12_0_0,pystrategy]
2023-05-22 15:24:08.900804 handle_trade data:PyTradeData(bktfut,13,RB2005.SHF,'1','2',2,3439.0000,    12,20200309 145900000,pystrategy,12_0_0)
2023-05-22 15:24:08.906758 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3438.0000,0.00,20200309) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3390.0000,3438.0000,0.00,20200309) at 0x0x7f0995062d20
2023-05-22 15:24:08.996301 2020-03-19 10:14:00 开空 for RB2005.SHF  最新价=3456.0 下单函数返回=13
2023-05-22 15:24:09.007368 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3456.0000,6(Unknown),20200319 101400000,13_0_0,pystrategy]
2023-05-22 15:24:09.014790 handle_order data:PyOrderData[bktfut,14,RB2005.SHF,'2','0',0,2,3456.0000,0(NotTraded),20200319 101400000,13_0_0,pystrategy]
2023-05-22 15:24:09.021356 handle_order data:PyOrderData[bktfut,14,RB2005.SHF,'2','0',2,2,3456.0000,2(AllTraded),20200319 101400000,13_0_0,pystrategy]
2023-05-22 15:24:09.026382 handle_trade data:PyTradeData(bktfut,14,RB2005.SHF,'2','0',2,3457.0000,    13,20200319 101500000,pystrategy,13_0_0)
2023-05-22 15:24:09.034208 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3460.0000,0.00,20200319) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3457.0000,3457.0000,8988.20,20200319) at 0x0x7f0995062d20
2023-05-22 15:24:09.049877 达到止损点,全部平仓
2023-05-22 15:24:09.059065 2020-03-19 14:20:00 止损平空 for RB2005.SHF  最新价=3507.0 下单函数返回=14
2023-05-22 15:24:09.067613 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3507.0000,6(Unknown),20200319 142000000,14_0_0,pystrategy]
2023-05-22 15:24:09.076212 handle_order data:PyOrderData[bktfut,15,RB2005.SHF,'1','2',0,2,3507.0000,0(NotTraded),20200319 142000000,14_0_0,pystrategy]
2023-05-22 15:24:09.082652 handle_order data:PyOrderData[bktfut,15,RB2005.SHF,'1','2',2,2,3507.0000,2(AllTraded),20200319 142000000,14_0_0,pystrategy]
2023-05-22 15:24:09.087750 handle_trade data:PyTradeData(bktfut,15,RB2005.SHF,'1','2',2,3507.0000,    14,20200319 142100000,pystrategy,14_0_0)
2023-05-22 15:24:09.095981 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3510.0000,0.00,20200319) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3457.0000,3510.0000,0.00,20200319) at 0x0x7f0995062d20
2023-05-22 15:24:09.147052 2020-03-30 09:11:00 开空 for RB2005.SHF  最新价=3408.0 下单函数返回=15
2023-05-22 15:24:09.151852 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3408.0000,6(Unknown),20200330 91100000,15_0_0,pystrategy]
2023-05-22 15:24:09.156129 handle_order data:PyOrderData[bktfut,16,RB2005.SHF,'2','0',0,2,3408.0000,0(NotTraded),20200330 91100000,15_0_0,pystrategy]
2023-05-22 15:24:09.160076 handle_order data:PyOrderData[bktfut,16,RB2005.SHF,'2','0',2,2,3408.0000,2(AllTraded),20200330 91100000,15_0_0,pystrategy]
2023-05-22 15:24:09.163865 handle_trade data:PyTradeData(bktfut,16,RB2005.SHF,'2','0',2,3406.0000,    15,20200330 91200000,pystrategy,15_0_0)
2023-05-22 15:24:09.167922 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3409.0000,0.00,20200330) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3406.0000,3406.0000,8855.60,20200330) at 0x0x7f0995062d20
2023-05-22 15:24:09.182402 2020-03-30 14:58:00 尾盘平空 for RB2005.SHF  最新价=3403.0 下单函数返回=16
2023-05-22 15:24:09.189699 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3403.0000,6(Unknown),20200330 145800000,16_0_0,pystrategy]
2023-05-22 15:24:09.195520 handle_order data:PyOrderData[bktfut,17,RB2005.SHF,'1','2',0,2,3403.0000,0(NotTraded),20200330 145800000,16_0_0,pystrategy]
2023-05-22 15:24:09.200344 handle_order data:PyOrderData[bktfut,17,RB2005.SHF,'1','2',2,2,3403.0000,2(AllTraded),20200330 145800000,16_0_0,pystrategy]
2023-05-22 15:24:09.207014 handle_trade data:PyTradeData(bktfut,17,RB2005.SHF,'1','2',2,3404.0000,    16,20200330 145900000,pystrategy,16_0_0)
2023-05-22 15:24:09.213209 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3403.0000,0.00,20200330) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3406.0000,3403.0000,0.00,20200330) at 0x0x7f0995062d20
[2023-05-22 15:24:09.240346] INFO hfbacktest: run_algo: done
[2023-05-22 15:24:09.617932] INFO hfbacktest: backtest done, raw_perf_ds:DataSource(a5229e5a69294d37829d73f2ede164f3T)
/usr/local/python3/lib/python3.8/site-packages/pandas/compat/_optional.py:116: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  if distutils.version.LooseVersion(version) < minimum_version:
/usr/local/python3/lib/python3.8/site-packages/setuptools/_distutils/version.py:346: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  other = LooseVersion(other)
/usr/local/python3/lib/python3.8/site-packages/tables/array.py:241: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  (oid, self.atom, self.shape, self._v_chunkshape) = self._open_array()
/usr/local/python3/lib/python3.8/site-packages/tables/atom.py:1224: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
  return pickle.loads(array.tostring())
/var/app/enabled/fai/settings.py:22: ResourceWarning: unclosed <socket.socket fd=79, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.160.156.187', 59300), raddr=('10.102.176.195', 8000)>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/var/app/enabled/fai/lib/logsclient.py:37: DeprecationWarning: Importing DisplayHandle from IPython.core.display is deprecated since IPython 7.14, please import from IPython display
[2023-05-22 15:24:12.053643] INFO: bigcharts.impl.render:render.py:407:render_chart Data is None, skip loading it to chart.
2023-05-22 15:24:12.478709 perf_render_future process plot...
  • 收益率-0.87%
  • 年化收益率-4.48%
  • 基准收益率-10.68%
  • 阿尔法-0.06
  • 贝塔0.02
  • 夏普比率-2.07
  • 胜率0.62
  • 盈亏比0.45
  • 收益波动率3.7%
  • 最大回撤1.99%
成交时间 合约代码 合约名称 买/卖 开/平 数量 成交价 交易金额 交易佣金 平仓盈亏
Loading... (need help?)
日期 合约代码 合约名称 持仓均价 收盘价 数量 持仓保证金 浮动盈亏 平仓盈亏
Loading... (need help?)
时间 级别 内容
Loading... (need help?)
[2023-05-22 15:24:12.530798] INFO moduleinvoker: hfbacktest.v2 运行完成[5.134s].
INFO:moduleinvoker:hfbacktest.v2 运行完成[5.134s].
[2023-05-22 15:24:12.653759] INFO moduleinvoker: hftrade.v2 运行完成[5.281694s].
INFO:moduleinvoker:hftrade.v2 运行完成[5.281694s].
In [ ]:
 

    In [6]:
    from datetime import datetime,timedelta
    from bigtrader.constant import *
    from biglearning.api import M
    import numpy as np
    
    def initialize(context):
        """初始化"""
        print("initialize")  
        context.ins = context.instruments[0] #从传入参数中获取需要交易的合约
        context.order_num = 2 #下单手数
        context.set_universe(context.ins)#设置需要处理的合约
        context.stopLossPrice = 50    # 设置止损点数
        
        context.closetime_day = "14:58" #日内策略白盘平仓时间,一般14:58
        context.closetime_night = "22:58" #日内策略夜盘平仓时间,一般22:58,注意有些商品夜盘收盘时间不一样
        
    def before_trading(context, data):
        """盘前处理"""
        #print("before_trading")
        context.subscribe(context.ins) #注册合约
        context.max_high = 0 #当日最高价
        context.max_low = 0 #当日最低价
        hist = data.history(context.ins, ["high","low","open","close"], 1, "1d")
    
        high = hist['high'][0]  # 前一日的最高价
        low = hist['low'][0]  # 前一日的最低价
        close = hist['close'][0]  # 前一日的收盘价
        pivot = (high + low + close) / 3  # 枢轴点
        context.bBreak = high + 2 * (pivot - low)  # 突破买入价 
        context.sSetup = pivot + (high - low)  # 观察卖出价
        context.sEnter = 2 * pivot - low  # 反转卖出价
        context.bEnter = 2 * pivot - high  # 反转买入价
        context.bSetup = pivot - (high - low)  # 观察买入价
        context.sBreak = low - 2 * (high - pivot)  # 突破卖出价
    
        
    def handle_data(context, data):
        """Bar行情推送"""
        cur_date =  data.current_dt
        cur_hm = cur_date.strftime('%H:%M') 
        
        #获取当日最高价和最低价
        today_high = data.current(context.ins,'high')
        today_low = data.current(context.ins,'low')
        
        context.max_high = max(context.max_high,today_high)
        context.max_low = max(context.max_high,today_low) 
        
        # 分别获取多头持仓,和空头持仓
        position_long = context.get_position(context.ins, Direction.LONG)
        position_short = context.get_position(context.ins, Direction.SHORT)
        
        # 获取当前价格
        price = data.current(context.ins, "close")
        
        #部分品种夜盘收盘时间不一样,此时间表示指定的尾盘平仓时间往后偏移30分钟,这段时间内不能开新仓,只能平仓。给30分钟是为了足够的冗余
        closetime_nightshift = (datetime.strptime(context.closetime_night,'%H:%M') + timedelta(minutes = 30)).strftime('%H:%M')
        #尾盘平仓
        if((cur_hm>=context.closetime_day and cur_hm<="15:00") or (cur_hm>=context.closetime_night and cur_hm<=closetime_nightshift)):
            if(position_long.current_qty != 0):
                rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 尾盘平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
            if(position_short.current_qty != 0):
                rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 尾盘平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
            #尾盘不开新仓,直接返回
            return
            
        # 突破策略:
        if position_long.current_qty == 0 and position_short.current_qty == 0:  # 空仓条件下
            if price > context.bBreak:
                # 在空仓的情况下,如果盘中价格超过突破买入价,则采取趋势策略,即在该点位开仓做多
                rv = context.buy_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                msg = "{} 开多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
                context.open_position_price = price
            elif price < context.sBreak:
                # 在空仓的情况下,如果盘中价格跌破突破卖出价,则采取趋势策略,即在该点位开仓做空
                rv = context.sell_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                msg = "{} 开空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
                context.open_position_price = price
        # 设置止损条件
        else:  # 有持仓时
            # 开仓价与当前行情价之差大于止损点则止损
            if (position_long.current_qty != 0 and context.open_position_price - price >= context.stopLossPrice) or \
                    (position_short.current_qty != 0 and price - context.open_position_price >= context.stopLossPrice):
                context.write_log('达到止损点,全部平仓', stdout=1) #输出关键日志
                if(position_long.current_qty != 0):
                    rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 止损平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
                if(position_short.current_qty != 0):
                    rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 止损平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
            # 反转策略:
            if position_long.current_qty != 0:  # 多仓条件下
                if context.max_high > context.sSetup and price < context.sEnter:
                    # 多头持仓,当日内最高价超过观察卖出价后
                    # 盘中价格出现回落,且进一步跌破反转卖出价构成的支撑线时
                    # 采取反转策略,即在该点位反手做空
                    context.write_log('多头持仓,当日内最高价超过观察卖出价后跌破反转卖出价: 反手做空', stdout=1) #输出关键日志
                    rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
                    
                    rv = context.sell_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                    context.open_position_price = price
                    msg = "{} 开空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志  
                    
            elif position_short.current_qty != 0:  # 空头持仓
                if context.max_low < context.bSetup and price > context.bEnter:
                    # 空头持仓,当日内最低价低于观察买入价后,
                    # 盘中价格出现反弹,且进一步超过反转买入价构成的阻力线时,
                    # 采取反转策略,即在该点位反手做多
                    context.write_log('空头持仓,当日最低价低于观察买入价后超过反转买入价: 反手做多', stdout=1) #输出关键日志
                    rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
                    
                    rv = context.buy_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                    context.open_position_price = price
                    msg = "{} 开多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志   
                    
    
    def handle_order(context, order):
        """委托回报推送"""
        msg = "handle_order data:{}".format(order.log_str())
        context.write_log(msg, stdout=1)
             
    def handle_trade(context, trade):
        """成交回报推送"""
        msg = "handle_trade data:{}".format(trade.log_str())
        context.write_log(msg, stdout=1) 
        # 分别获取最新的多头持仓和空头持仓
        position_long = context.get_position(trade.symbol, Direction.LONG)
        position_short = context.get_position(trade.symbol, Direction.SHORT)
        msg = "当前多头持仓:{} 当前空头持仓:{}".format(str(position_long),str(position_short))
        context.write_log(msg, stdout=1) 
        
    instruments = "RB2005.SHF"
    
    #需要交易者传入的参数
    strategy_setting = [
        {
            "instruments": instruments,
            "order_num": 2,
            "closetime_day": "14:58",
            "closetime_night": "22:58"
        }    
    ]
    start_date = "2020-01-21"
    end_date = "2020-04-01"
    md = M.hftrade.v2(start_date=start_date,
                         end_date=end_date,
                         instruments=[instruments], #只传入一个合约便于策略逻辑展示
                         capital_base=100000,
                         product_type=Product.FUTURE,
                         frequency=Frequency.MINUTE,
                         initialize=initialize,
                         before_trading_start=before_trading,
                         handle_data=handle_data,
                         handle_order=handle_order,
                         handle_trade=handle_trade,
                         plot_charts=True,
                         volume_limit=1.0,
                         show_debug_info=1,
                         before_start_days=10,
                         m_deps=np.random.rand())
    
    [2023-05-22 15:24:07.396769] INFO moduleinvoker: hfbacktest.v2 开始运行..
    [2023-05-22 15:24:07.404442] INFO hfbacktest: passed-in daily_data_ds:None
    [2023-05-22 15:24:07.406223] INFO hfbacktest: passed-in minute_data_ds:None
    [2023-05-22 15:24:07.408079] INFO hfbacktest: passed-in tick_data_ds:None
    [2023-05-22 15:24:07.409679] INFO hfbacktest: passed-in each_data_ds:None
    [2023-05-22 15:24:07.411032] INFO hfbacktest: passed-in dominant_data_ds:None
    [2023-05-22 15:24:07.412326] INFO hfbacktest: passed-in basic_data_ds:None
    [2023-05-22 15:24:07.413734] INFO hfbacktest: passed-in benchmark_data_ds:None
    [2023-05-22 15:24:07.415214] INFO hfbacktest: hfbacktest2 V2.0.0
    [2023-05-22 15:24:07.416449] INFO hfbacktest: pytradersdk v1.0.0 2023-05-19
    [2023-05-22 15:24:07.442308] INFO hfbacktest: strategy callbacks:{'initialize': <function initialize at 0x7f09001f71f0>, 'before_trading': <function before_trading at 0x7f0900044e50>, 'handle_data': <function handle_data at 0x7f0900044d30>, 'handle_trade': <function handle_trade at 0x7f0900044f70>, 'handle_order': <function handle_order at 0x7f0900044ee0>}
    [2023-05-22 15:24:07.444894] INFO hfbacktest: begin reading history data, 2020-01-21 00:00:00~2020-04-01, disable_cache:False, replay_bdb:False
    [2023-05-22 15:24:07.446415] INFO hfbacktest: reading benchmark data 000300.HIX 2020-01-21 00:00:00~2020-04-01...
    [2023-05-22 15:24:07.467035] INFO moduleinvoker: cached.v2 开始运行..
    [2023-05-22 15:24:07.492300] INFO moduleinvoker: 命中缓存
    [2023-05-22 15:24:07.496322] INFO moduleinvoker: cached.v2 运行完成[0.029245s].
    [2023-05-22 15:24:07.609612] INFO hfbacktest: reading daily data 2019-01-21 00:00:00~2020-04-01...
    [2023-05-22 15:24:07.624802] INFO moduleinvoker: cached.v2 开始运行..
    [2023-05-22 15:24:07.636795] INFO moduleinvoker: 命中缓存
    [2023-05-22 15:24:07.638991] INFO moduleinvoker: cached.v2 运行完成[0.014256s].
    [2023-05-22 15:24:07.785312] INFO hfbacktest: reading minute data 2020-01-09 20:55:00~2020-04-01...
    [2023-05-22 15:24:07.831102] INFO moduleinvoker: cached.v2 开始运行..
    [2023-05-22 15:24:07.860069] INFO moduleinvoker: 命中缓存
    [2023-05-22 15:24:07.862759] INFO moduleinvoker: cached.v2 运行完成[0.031698s].
    [2023-05-22 15:24:08.089779] INFO hfbacktest: cached_benchmark_ds:DataSource(811c07e12631498a82fd2221807eee6cT)
    [2023-05-22 15:24:08.092688] INFO hfbacktest: cached_daily_ds:DataSource(db785b011ecd4f88960d5357c945667aT)
    [2023-05-22 15:24:08.095361] INFO hfbacktest: cached_minute_ds:DataSource(d348283102dc4d80b0d5642ab0b4c5bdT)
    [2023-05-22 15:24:08.100228] INFO hfbacktest: cached_tick_ds:None
    [2023-05-22 15:24:08.102526] INFO hfbacktest: cached_each_ds:None
    [2023-05-22 15:24:08.105475] INFO hfbacktest: dominant_data_ds:None
    [2023-05-22 15:24:08.109301] INFO hfbacktest: read history data done, call run backtest(future,1m,100000,2020-01-21~2020-04-01) ...
    [2023-05-22 15:24:08.112195] INFO hfbacktest: run_algo: PyTradeEngine ver=1.0.0
    [2023-05-22 15:24:08.122427] INFO hfbacktest: run algo: init rv=0
    [2023-05-22 15:24:08.135694] INFO hfbacktest: run_algo: set_history_data frequency='1m', len=13125, rv=0
    [2023-05-22 15:24:08.138512] INFO hfbacktest: run_algo: add strategy funcs done rv=4, running...
    initialize
    2023-05-22 15:24:08.208019 2020-02-03 09:01:00 开空 for RB2005.SHF  最新价=3233.0 下单函数返回=1
    2023-05-22 15:24:08.215502 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3233.0000,6(Unknown),20200203 90100000,1_0_0,pystrategy]
    2023-05-22 15:24:08.238977 handle_order data:PyOrderData[bktfut,2,RB2005.SHF,'2','0',0,2,3233.0000,0(NotTraded),20200203 90100000,1_0_0,pystrategy]
    2023-05-22 15:24:08.256083 handle_order data:PyOrderData[bktfut,2,RB2005.SHF,'2','0',2,2,3233.0000,2(AllTraded),20200203 90100000,1_0_0,pystrategy]
    2023-05-22 15:24:08.262062 handle_trade data:PyTradeData(bktfut,2,RB2005.SHF,'2','0',2,3233.0000,     1,20200203 90200000,pystrategy,1_0_0)
    2023-05-22 15:24:08.267613 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3233.0000,3233.0000,8405.80,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.275024 达到止损点,全部平仓
    2023-05-22 15:24:08.281359 2020-02-03 09:59:00 止损平空 for RB2005.SHF  最新价=3288.0 下单函数返回=2
    2023-05-22 15:24:08.286543 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3288.0000,6(Unknown),20200203 95900000,2_0_0,pystrategy]
    2023-05-22 15:24:08.290655 handle_order data:PyOrderData[bktfut,3,RB2005.SHF,'1','2',0,2,3288.0000,0(NotTraded),20200203 95900000,2_0_0,pystrategy]
    2023-05-22 15:24:08.294632 handle_order data:PyOrderData[bktfut,3,RB2005.SHF,'1','2',2,2,3288.0000,2(AllTraded),20200203 95900000,2_0_0,pystrategy]
    2023-05-22 15:24:08.301132 handle_trade data:PyTradeData(bktfut,3,RB2005.SHF,'1','2',2,3288.0000,     2,20200203 100000000,pystrategy,2_0_0)
    2023-05-22 15:24:08.306531 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3233.0000,3289.0000,0.00,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.311469 2020-02-03 10:00:00 开空 for RB2005.SHF  最新价=3289.0 下单函数返回=3
    2023-05-22 15:24:08.315487 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3289.0000,6(Unknown),20200203 100000000,3_0_0,pystrategy]
    2023-05-22 15:24:08.319646 handle_order data:PyOrderData[bktfut,4,RB2005.SHF,'2','0',0,2,3289.0000,0(NotTraded),20200203 100000000,3_0_0,pystrategy]
    2023-05-22 15:24:08.323531 handle_order data:PyOrderData[bktfut,4,RB2005.SHF,'2','0',2,2,3289.0000,2(AllTraded),20200203 100000000,3_0_0,pystrategy]
    2023-05-22 15:24:08.327365 handle_trade data:PyTradeData(bktfut,4,RB2005.SHF,'2','0',2,3289.0000,     3,20200203 100100000,pystrategy,3_0_0)
    2023-05-22 15:24:08.331264 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3289.0000,3289.0000,8551.40,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.340571 2020-02-03 14:58:00 尾盘平空 for RB2005.SHF  最新价=3233.0 下单函数返回=4
    2023-05-22 15:24:08.344591 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3233.0000,6(Unknown),20200203 145800000,4_0_0,pystrategy]
    2023-05-22 15:24:08.348524 handle_order data:PyOrderData[bktfut,5,RB2005.SHF,'1','2',0,2,3233.0000,0(NotTraded),20200203 145800000,4_0_0,pystrategy]
    2023-05-22 15:24:08.354452 handle_order data:PyOrderData[bktfut,5,RB2005.SHF,'1','2',2,2,3233.0000,2(AllTraded),20200203 145800000,4_0_0,pystrategy]
    2023-05-22 15:24:08.361694 handle_trade data:PyTradeData(bktfut,5,RB2005.SHF,'1','2',2,3233.0000,     4,20200203 145900000,pystrategy,4_0_0)
    2023-05-22 15:24:08.368052 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3289.0000,3233.0000,0.00,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.428243 2020-02-11 09:20:00 开多 for RB2005.SHF  最新价=3368.0 下单函数返回=5
    2023-05-22 15:24:08.432855 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3368.0000,6(Unknown),20200211 92000000,5_0_0,pystrategy]
    2023-05-22 15:24:08.436880 handle_order data:PyOrderData[bktfut,6,RB2005.SHF,'1','0',0,2,3368.0000,0(NotTraded),20200211 92000000,5_0_0,pystrategy]
    2023-05-22 15:24:08.440875 handle_order data:PyOrderData[bktfut,6,RB2005.SHF,'1','0',2,2,3368.0000,2(AllTraded),20200211 92000000,5_0_0,pystrategy]
    2023-05-22 15:24:08.444880 handle_trade data:PyTradeData(bktfut,6,RB2005.SHF,'1','0',2,3367.0000,     5,20200211 92100000,pystrategy,5_0_0)
    2023-05-22 15:24:08.448621 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3367.0000,3367.0000,8754.20,20200211) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3371.0000,0.00,20200211) at 0x0x7f0995062d20
    2023-05-22 15:24:08.459251 2020-02-11 14:58:00 尾盘平多 for RB2005.SHF  最新价=3395.0 下单函数返回=6
    2023-05-22 15:24:08.463301 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3395.0000,6(Unknown),20200211 145800000,6_0_0,pystrategy]
    2023-05-22 15:24:08.468559 handle_order data:PyOrderData[bktfut,7,RB2005.SHF,'2','2',0,2,3395.0000,0(NotTraded),20200211 145800000,6_0_0,pystrategy]
    2023-05-22 15:24:08.484870 handle_order data:PyOrderData[bktfut,7,RB2005.SHF,'2','2',2,2,3395.0000,2(AllTraded),20200211 145800000,6_0_0,pystrategy]
    2023-05-22 15:24:08.499072 handle_trade data:PyTradeData(bktfut,7,RB2005.SHF,'2','2',2,3395.0000,     6,20200211 145900000,pystrategy,6_0_0)
    2023-05-22 15:24:08.506344 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3367.0000,3394.0000,0.00,20200211) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3394.0000,0.00,20200211) at 0x0x7f0995062d20
    2023-05-22 15:24:08.580442 2020-02-20 09:28:00 开多 for RB2005.SHF  最新价=3441.0 下单函数返回=7
    2023-05-22 15:24:08.588187 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3441.0000,6(Unknown),20200220 92800000,7_0_0,pystrategy]
    2023-05-22 15:24:08.597766 handle_order data:PyOrderData[bktfut,8,RB2005.SHF,'1','0',0,2,3441.0000,0(NotTraded),20200220 92800000,7_0_0,pystrategy]
    2023-05-22 15:24:08.606194 handle_order data:PyOrderData[bktfut,8,RB2005.SHF,'1','0',2,2,3441.0000,2(AllTraded),20200220 92800000,7_0_0,pystrategy]
    2023-05-22 15:24:08.617240 handle_trade data:PyTradeData(bktfut,8,RB2005.SHF,'1','0',2,3441.0000,     7,20200220 92900000,pystrategy,7_0_0)
    2023-05-22 15:24:08.631545 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3441.0000,3441.0000,8946.60,20200220) at 0x0x7f0995062d20 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3444.0000,0.00,20200220) at 0x0x7f0995062a40
    2023-05-22 15:24:08.653772 2020-02-20 14:58:00 尾盘平多 for RB2005.SHF  最新价=3457.0 下单函数返回=8
    2023-05-22 15:24:08.668402 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3457.0000,6(Unknown),20200220 145800000,8_0_0,pystrategy]
    2023-05-22 15:24:08.675927 handle_order data:PyOrderData[bktfut,9,RB2005.SHF,'2','2',0,2,3457.0000,0(NotTraded),20200220 145800000,8_0_0,pystrategy]
    2023-05-22 15:24:08.682525 handle_order data:PyOrderData[bktfut,9,RB2005.SHF,'2','2',2,2,3457.0000,2(AllTraded),20200220 145800000,8_0_0,pystrategy]
    2023-05-22 15:24:08.691302 handle_trade data:PyTradeData(bktfut,9,RB2005.SHF,'2','2',2,3458.0000,     8,20200220 145900000,pystrategy,8_0_0)
    2023-05-22 15:24:08.698690 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3441.0000,3457.0000,0.00,20200220) at 0x0x7f0995062d20 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3457.0000,0.00,20200220) at 0x0x7f0995062a40
    2023-05-22 15:24:08.745823 2020-02-28 09:05:00 开空 for RB2005.SHF  最新价=3347.0 下单函数返回=9
    2023-05-22 15:24:08.750480 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3347.0000,6(Unknown),20200228 90500000,9_0_0,pystrategy]
    2023-05-22 15:24:08.754287 handle_order data:PyOrderData[bktfut,10,RB2005.SHF,'2','0',0,2,3347.0000,0(NotTraded),20200228 90500000,9_0_0,pystrategy]
    2023-05-22 15:24:08.758222 handle_order data:PyOrderData[bktfut,10,RB2005.SHF,'2','0',2,2,3347.0000,2(AllTraded),20200228 90500000,9_0_0,pystrategy]
    2023-05-22 15:24:08.762290 handle_trade data:PyTradeData(bktfut,10,RB2005.SHF,'2','0',2,3347.0000,     9,20200228 90600000,pystrategy,9_0_0)
    2023-05-22 15:24:08.766062 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3340.0000,0.00,20200228) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3347.0000,3347.0000,8702.20,20200228) at 0x0x7f0995062d20
    2023-05-22 15:24:08.778502 2020-02-28 14:58:00 尾盘平空 for RB2005.SHF  最新价=3333.0 下单函数返回=10
    2023-05-22 15:24:08.783012 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3333.0000,6(Unknown),20200228 145800000,10_0_0,pystrategy]
    2023-05-22 15:24:08.786740 handle_order data:PyOrderData[bktfut,11,RB2005.SHF,'1','2',0,2,3333.0000,0(NotTraded),20200228 145800000,10_0_0,pystrategy]
    2023-05-22 15:24:08.790379 handle_order data:PyOrderData[bktfut,11,RB2005.SHF,'1','2',2,2,3333.0000,2(AllTraded),20200228 145800000,10_0_0,pystrategy]
    2023-05-22 15:24:08.794099 handle_trade data:PyTradeData(bktfut,11,RB2005.SHF,'1','2',2,3334.0000,    10,20200228 145900000,pystrategy,10_0_0)
    2023-05-22 15:24:08.797951 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3336.0000,0.00,20200228) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3347.0000,3336.0000,0.00,20200228) at 0x0x7f0995062d20
    2023-05-22 15:24:08.840482 2020-03-09 09:02:00 开空 for RB2005.SHF  最新价=3390.0 下单函数返回=11
    2023-05-22 15:24:08.845079 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3390.0000,6(Unknown),20200309 90200000,11_0_0,pystrategy]
    2023-05-22 15:24:08.849301 handle_order data:PyOrderData[bktfut,12,RB2005.SHF,'2','0',0,2,3390.0000,0(NotTraded),20200309 90200000,11_0_0,pystrategy]
    2023-05-22 15:24:08.853131 handle_order data:PyOrderData[bktfut,12,RB2005.SHF,'2','0',2,2,3390.0000,2(AllTraded),20200309 90200000,11_0_0,pystrategy]
    2023-05-22 15:24:08.857099 handle_trade data:PyTradeData(bktfut,12,RB2005.SHF,'2','0',2,3390.0000,    11,20200309 90300000,pystrategy,11_0_0)
    2023-05-22 15:24:08.860835 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3393.0000,0.00,20200309) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3390.0000,3390.0000,8814.00,20200309) at 0x0x7f0995062d20
    2023-05-22 15:24:08.872215 2020-03-09 14:58:00 尾盘平空 for RB2005.SHF  最新价=3439.0 下单函数返回=12
    2023-05-22 15:24:08.876441 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3439.0000,6(Unknown),20200309 145800000,12_0_0,pystrategy]
    2023-05-22 15:24:08.880779 handle_order data:PyOrderData[bktfut,13,RB2005.SHF,'1','2',0,2,3439.0000,0(NotTraded),20200309 145800000,12_0_0,pystrategy]
    2023-05-22 15:24:08.894261 handle_order data:PyOrderData[bktfut,13,RB2005.SHF,'1','2',2,2,3439.0000,2(AllTraded),20200309 145800000,12_0_0,pystrategy]
    2023-05-22 15:24:08.900804 handle_trade data:PyTradeData(bktfut,13,RB2005.SHF,'1','2',2,3439.0000,    12,20200309 145900000,pystrategy,12_0_0)
    2023-05-22 15:24:08.906758 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3438.0000,0.00,20200309) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3390.0000,3438.0000,0.00,20200309) at 0x0x7f0995062d20
    2023-05-22 15:24:08.996301 2020-03-19 10:14:00 开空 for RB2005.SHF  最新价=3456.0 下单函数返回=13
    2023-05-22 15:24:09.007368 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3456.0000,6(Unknown),20200319 101400000,13_0_0,pystrategy]
    2023-05-22 15:24:09.014790 handle_order data:PyOrderData[bktfut,14,RB2005.SHF,'2','0',0,2,3456.0000,0(NotTraded),20200319 101400000,13_0_0,pystrategy]
    2023-05-22 15:24:09.021356 handle_order data:PyOrderData[bktfut,14,RB2005.SHF,'2','0',2,2,3456.0000,2(AllTraded),20200319 101400000,13_0_0,pystrategy]
    2023-05-22 15:24:09.026382 handle_trade data:PyTradeData(bktfut,14,RB2005.SHF,'2','0',2,3457.0000,    13,20200319 101500000,pystrategy,13_0_0)
    2023-05-22 15:24:09.034208 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3460.0000,0.00,20200319) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3457.0000,3457.0000,8988.20,20200319) at 0x0x7f0995062d20
    2023-05-22 15:24:09.049877 达到止损点,全部平仓
    2023-05-22 15:24:09.059065 2020-03-19 14:20:00 止损平空 for RB2005.SHF  最新价=3507.0 下单函数返回=14
    2023-05-22 15:24:09.067613 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3507.0000,6(Unknown),20200319 142000000,14_0_0,pystrategy]
    2023-05-22 15:24:09.076212 handle_order data:PyOrderData[bktfut,15,RB2005.SHF,'1','2',0,2,3507.0000,0(NotTraded),20200319 142000000,14_0_0,pystrategy]
    2023-05-22 15:24:09.082652 handle_order data:PyOrderData[bktfut,15,RB2005.SHF,'1','2',2,2,3507.0000,2(AllTraded),20200319 142000000,14_0_0,pystrategy]
    2023-05-22 15:24:09.087750 handle_trade data:PyTradeData(bktfut,15,RB2005.SHF,'1','2',2,3507.0000,    14,20200319 142100000,pystrategy,14_0_0)
    2023-05-22 15:24:09.095981 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3510.0000,0.00,20200319) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3457.0000,3510.0000,0.00,20200319) at 0x0x7f0995062d20
    2023-05-22 15:24:09.147052 2020-03-30 09:11:00 开空 for RB2005.SHF  最新价=3408.0 下单函数返回=15
    2023-05-22 15:24:09.151852 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3408.0000,6(Unknown),20200330 91100000,15_0_0,pystrategy]
    2023-05-22 15:24:09.156129 handle_order data:PyOrderData[bktfut,16,RB2005.SHF,'2','0',0,2,3408.0000,0(NotTraded),20200330 91100000,15_0_0,pystrategy]
    2023-05-22 15:24:09.160076 handle_order data:PyOrderData[bktfut,16,RB2005.SHF,'2','0',2,2,3408.0000,2(AllTraded),20200330 91100000,15_0_0,pystrategy]
    2023-05-22 15:24:09.163865 handle_trade data:PyTradeData(bktfut,16,RB2005.SHF,'2','0',2,3406.0000,    15,20200330 91200000,pystrategy,15_0_0)
    2023-05-22 15:24:09.167922 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3409.0000,0.00,20200330) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3406.0000,3406.0000,8855.60,20200330) at 0x0x7f0995062d20
    2023-05-22 15:24:09.182402 2020-03-30 14:58:00 尾盘平空 for RB2005.SHF  最新价=3403.0 下单函数返回=16
    2023-05-22 15:24:09.189699 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3403.0000,6(Unknown),20200330 145800000,16_0_0,pystrategy]
    2023-05-22 15:24:09.195520 handle_order data:PyOrderData[bktfut,17,RB2005.SHF,'1','2',0,2,3403.0000,0(NotTraded),20200330 145800000,16_0_0,pystrategy]
    2023-05-22 15:24:09.200344 handle_order data:PyOrderData[bktfut,17,RB2005.SHF,'1','2',2,2,3403.0000,2(AllTraded),20200330 145800000,16_0_0,pystrategy]
    2023-05-22 15:24:09.207014 handle_trade data:PyTradeData(bktfut,17,RB2005.SHF,'1','2',2,3404.0000,    16,20200330 145900000,pystrategy,16_0_0)
    2023-05-22 15:24:09.213209 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3403.0000,0.00,20200330) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3406.0000,3403.0000,0.00,20200330) at 0x0x7f0995062d20
    [2023-05-22 15:24:09.240346] INFO hfbacktest: run_algo: done
    [2023-05-22 15:24:09.617932] INFO hfbacktest: backtest done, raw_perf_ds:DataSource(a5229e5a69294d37829d73f2ede164f3T)
    
    /usr/local/python3/lib/python3.8/site-packages/pandas/compat/_optional.py:116: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
      if distutils.version.LooseVersion(version) < minimum_version:
    /usr/local/python3/lib/python3.8/site-packages/setuptools/_distutils/version.py:346: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
      other = LooseVersion(other)
    /usr/local/python3/lib/python3.8/site-packages/tables/array.py:241: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
    Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
      (oid, self.atom, self.shape, self._v_chunkshape) = self._open_array()
    /usr/local/python3/lib/python3.8/site-packages/tables/atom.py:1224: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
      return pickle.loads(array.tostring())
    /var/app/enabled/fai/settings.py:22: ResourceWarning: unclosed <socket.socket fd=79, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.160.156.187', 59300), raddr=('10.102.176.195', 8000)>
    ResourceWarning: Enable tracemalloc to get the object allocation traceback
    /var/app/enabled/fai/lib/logsclient.py:37: DeprecationWarning: Importing DisplayHandle from IPython.core.display is deprecated since IPython 7.14, please import from IPython display
    [2023-05-22 15:24:12.053643] INFO: bigcharts.impl.render:render.py:407:render_chart Data is None, skip loading it to chart.
    
    2023-05-22 15:24:12.478709 perf_render_future process plot...
    
    • 收益率-0.87%
    • 年化收益率-4.48%
    • 基准收益率-10.68%
    • 阿尔法-0.06
    • 贝塔0.02
    • 夏普比率-2.07
    • 胜率0.62
    • 盈亏比0.45
    • 收益波动率3.7%
    • 最大回撤1.99%
    成交时间 合约代码 合约名称 买/卖 开/平 数量 成交价 交易金额 交易佣金 平仓盈亏
    Loading... (need help?)
    日期 合约代码 合约名称 持仓均价 收盘价 数量 持仓保证金 浮动盈亏 平仓盈亏
    Loading... (need help?)
    时间 级别 内容
    Loading... (need help?)
    [2023-05-22 15:24:12.530798] INFO moduleinvoker: hfbacktest.v2 运行完成[5.134s].
    
    INFO:moduleinvoker:hfbacktest.v2 运行完成[5.134s].
    
    [2023-05-22 15:24:12.653759] INFO moduleinvoker: hftrade.v2 运行完成[5.281694s].
    
    INFO:moduleinvoker:hftrade.v2 运行完成[5.281694s].
    

    策略名称

    R-Breaker日内策略

    策略思路

    R-Breaker是一种短线日内交易策略。根据前一个交易日的收盘价(C)、最高价(H)和最低价(L)数据通过一定方式计算出六个价位,从大到小依次为: 突破买入价、观察卖出价、反转卖出价、反转买入、观察买入价、突破卖出价。 中心价位P = (H + C + L)/3 突破买入价 = H + 2P -2L 观察卖出价 = P + H - L 反转卖出价 = 2P - L 反转买入价 = 2P - H 观察买入价 = P - (H - L) 突破卖出价 = L - 2(H - P)

    空仓时:突破策略 空仓时,当盘中价格>突破买入价,则认为上涨的趋势还会继续,开仓做多; 空仓时,当盘中价格<突破卖出价,则认为下跌的趋势还会继续,开仓做空。

    持仓时:反转策略 持多单时:当日内最高价>观察卖出价后,盘中价格回落,跌破反转卖出价构成的支撑线时,采取反转策略,即做空; 持空单时:当日内最低价<观察买入价后,盘中价格反弹,超过反转买入价构成的阻力线时,采取反转策略,即做多。

    In [6]:
    from datetime import datetime,timedelta
    from bigtrader.constant import *
    from biglearning.api import M
    import numpy as np
    
    def initialize(context):
        """初始化"""
        print("initialize")  
        context.ins = context.instruments[0] #从传入参数中获取需要交易的合约
        context.order_num = 2 #下单手数
        context.set_universe(context.ins)#设置需要处理的合约
        context.stopLossPrice = 50    # 设置止损点数
        
        context.closetime_day = "14:58" #日内策略白盘平仓时间,一般14:58
        context.closetime_night = "22:58" #日内策略夜盘平仓时间,一般22:58,注意有些商品夜盘收盘时间不一样
        
    def before_trading(context, data):
        """盘前处理"""
        #print("before_trading")
        context.subscribe(context.ins) #注册合约
        context.max_high = 0 #当日最高价
        context.max_low = 0 #当日最低价
        hist = data.history(context.ins, ["high","low","open","close"], 1, "1d")
    
        high = hist['high'][0]  # 前一日的最高价
        low = hist['low'][0]  # 前一日的最低价
        close = hist['close'][0]  # 前一日的收盘价
        pivot = (high + low + close) / 3  # 枢轴点
        context.bBreak = high + 2 * (pivot - low)  # 突破买入价 
        context.sSetup = pivot + (high - low)  # 观察卖出价
        context.sEnter = 2 * pivot - low  # 反转卖出价
        context.bEnter = 2 * pivot - high  # 反转买入价
        context.bSetup = pivot - (high - low)  # 观察买入价
        context.sBreak = low - 2 * (high - pivot)  # 突破卖出价
    
        
    def handle_data(context, data):
        """Bar行情推送"""
        cur_date =  data.current_dt
        cur_hm = cur_date.strftime('%H:%M') 
        
        #获取当日最高价和最低价
        today_high = data.current(context.ins,'high')
        today_low = data.current(context.ins,'low')
        
        context.max_high = max(context.max_high,today_high)
        context.max_low = max(context.max_high,today_low) 
        
        # 分别获取多头持仓,和空头持仓
        position_long = context.get_position(context.ins, Direction.LONG)
        position_short = context.get_position(context.ins, Direction.SHORT)
        
        # 获取当前价格
        price = data.current(context.ins, "close")
        
        #部分品种夜盘收盘时间不一样,此时间表示指定的尾盘平仓时间往后偏移30分钟,这段时间内不能开新仓,只能平仓。给30分钟是为了足够的冗余
        closetime_nightshift = (datetime.strptime(context.closetime_night,'%H:%M') + timedelta(minutes = 30)).strftime('%H:%M')
        #尾盘平仓
        if((cur_hm>=context.closetime_day and cur_hm<="15:00") or (cur_hm>=context.closetime_night and cur_hm<=closetime_nightshift)):
            if(position_long.current_qty != 0):
                rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 尾盘平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
            if(position_short.current_qty != 0):
                rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 尾盘平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
            #尾盘不开新仓,直接返回
            return
            
        # 突破策略:
        if position_long.current_qty == 0 and position_short.current_qty == 0:  # 空仓条件下
            if price > context.bBreak:
                # 在空仓的情况下,如果盘中价格超过突破买入价,则采取趋势策略,即在该点位开仓做多
                rv = context.buy_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                msg = "{} 开多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
                context.open_position_price = price
            elif price < context.sBreak:
                # 在空仓的情况下,如果盘中价格跌破突破卖出价,则采取趋势策略,即在该点位开仓做空
                rv = context.sell_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                msg = "{} 开空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                context.write_log(msg, stdout=1) #输出关键日志
                context.open_position_price = price
        # 设置止损条件
        else:  # 有持仓时
            # 开仓价与当前行情价之差大于止损点则止损
            if (position_long.current_qty != 0 and context.open_position_price - price >= context.stopLossPrice) or \
                    (position_short.current_qty != 0 and price - context.open_position_price >= context.stopLossPrice):
                context.write_log('达到止损点,全部平仓', stdout=1) #输出关键日志
                if(position_long.current_qty != 0):
                    rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 止损平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
                if(position_short.current_qty != 0):
                    rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 止损平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
            # 反转策略:
            if position_long.current_qty != 0:  # 多仓条件下
                if context.max_high > context.sSetup and price < context.sEnter:
                    # 多头持仓,当日内最高价超过观察卖出价后
                    # 盘中价格出现回落,且进一步跌破反转卖出价构成的支撑线时
                    # 采取反转策略,即在该点位反手做空
                    context.write_log('多头持仓,当日内最高价超过观察卖出价后跌破反转卖出价: 反手做空', stdout=1) #输出关键日志
                    rv = context.sell_close(context.ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 平多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
                    
                    rv = context.sell_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                    context.open_position_price = price
                    msg = "{} 开空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志  
                    
            elif position_short.current_qty != 0:  # 空头持仓
                if context.max_low < context.bSetup and price > context.bEnter:
                    # 空头持仓,当日内最低价低于观察买入价后,
                    # 盘中价格出现反弹,且进一步超过反转买入价构成的阻力线时,
                    # 采取反转策略,即在该点位反手做多
                    context.write_log('空头持仓,当日最低价低于观察买入价后超过反转买入价: 反手做多', stdout=1) #输出关键日志
                    rv = context.buy_close(context.ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                    msg = "{} 平空 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志
                    
                    rv = context.buy_open(context.ins, context.order_num, price, order_type=OrderType.MARKET)
                    context.open_position_price = price
                    msg = "{} 开多 for {}  最新价={} 下单函数返回={}".format(str(data.current_dt),context.ins,str(price),str(rv))
                    context.write_log(msg, stdout=1) #输出关键日志   
                    
    
    def handle_order(context, order):
        """委托回报推送"""
        msg = "handle_order data:{}".format(order.log_str())
        context.write_log(msg, stdout=1)
             
    def handle_trade(context, trade):
        """成交回报推送"""
        msg = "handle_trade data:{}".format(trade.log_str())
        context.write_log(msg, stdout=1) 
        # 分别获取最新的多头持仓和空头持仓
        position_long = context.get_position(trade.symbol, Direction.LONG)
        position_short = context.get_position(trade.symbol, Direction.SHORT)
        msg = "当前多头持仓:{} 当前空头持仓:{}".format(str(position_long),str(position_short))
        context.write_log(msg, stdout=1) 
        
    instruments = "RB2005.SHF"
    
    #需要交易者传入的参数
    strategy_setting = [
        {
            "instruments": instruments,
            "order_num": 2,
            "closetime_day": "14:58",
            "closetime_night": "22:58"
        }    
    ]
    start_date = "2020-01-21"
    end_date = "2020-04-01"
    md = M.hftrade.v2(start_date=start_date,
                         end_date=end_date,
                         instruments=[instruments], #只传入一个合约便于策略逻辑展示
                         capital_base=100000,
                         product_type=Product.FUTURE,
                         frequency=Frequency.MINUTE,
                         initialize=initialize,
                         before_trading_start=before_trading,
                         handle_data=handle_data,
                         handle_order=handle_order,
                         handle_trade=handle_trade,
                         plot_charts=True,
                         volume_limit=1.0,
                         show_debug_info=1,
                         before_start_days=10,
                         m_deps=np.random.rand())
    
    [2023-05-22 15:24:07.396769] INFO moduleinvoker: hfbacktest.v2 开始运行..
    [2023-05-22 15:24:07.404442] INFO hfbacktest: passed-in daily_data_ds:None
    [2023-05-22 15:24:07.406223] INFO hfbacktest: passed-in minute_data_ds:None
    [2023-05-22 15:24:07.408079] INFO hfbacktest: passed-in tick_data_ds:None
    [2023-05-22 15:24:07.409679] INFO hfbacktest: passed-in each_data_ds:None
    [2023-05-22 15:24:07.411032] INFO hfbacktest: passed-in dominant_data_ds:None
    [2023-05-22 15:24:07.412326] INFO hfbacktest: passed-in basic_data_ds:None
    [2023-05-22 15:24:07.413734] INFO hfbacktest: passed-in benchmark_data_ds:None
    [2023-05-22 15:24:07.415214] INFO hfbacktest: hfbacktest2 V2.0.0
    [2023-05-22 15:24:07.416449] INFO hfbacktest: pytradersdk v1.0.0 2023-05-19
    [2023-05-22 15:24:07.442308] INFO hfbacktest: strategy callbacks:{'initialize': <function initialize at 0x7f09001f71f0>, 'before_trading': <function before_trading at 0x7f0900044e50>, 'handle_data': <function handle_data at 0x7f0900044d30>, 'handle_trade': <function handle_trade at 0x7f0900044f70>, 'handle_order': <function handle_order at 0x7f0900044ee0>}
    [2023-05-22 15:24:07.444894] INFO hfbacktest: begin reading history data, 2020-01-21 00:00:00~2020-04-01, disable_cache:False, replay_bdb:False
    [2023-05-22 15:24:07.446415] INFO hfbacktest: reading benchmark data 000300.HIX 2020-01-21 00:00:00~2020-04-01...
    [2023-05-22 15:24:07.467035] INFO moduleinvoker: cached.v2 开始运行..
    [2023-05-22 15:24:07.492300] INFO moduleinvoker: 命中缓存
    [2023-05-22 15:24:07.496322] INFO moduleinvoker: cached.v2 运行完成[0.029245s].
    [2023-05-22 15:24:07.609612] INFO hfbacktest: reading daily data 2019-01-21 00:00:00~2020-04-01...
    [2023-05-22 15:24:07.624802] INFO moduleinvoker: cached.v2 开始运行..
    [2023-05-22 15:24:07.636795] INFO moduleinvoker: 命中缓存
    [2023-05-22 15:24:07.638991] INFO moduleinvoker: cached.v2 运行完成[0.014256s].
    [2023-05-22 15:24:07.785312] INFO hfbacktest: reading minute data 2020-01-09 20:55:00~2020-04-01...
    [2023-05-22 15:24:07.831102] INFO moduleinvoker: cached.v2 开始运行..
    [2023-05-22 15:24:07.860069] INFO moduleinvoker: 命中缓存
    [2023-05-22 15:24:07.862759] INFO moduleinvoker: cached.v2 运行完成[0.031698s].
    [2023-05-22 15:24:08.089779] INFO hfbacktest: cached_benchmark_ds:DataSource(811c07e12631498a82fd2221807eee6cT)
    [2023-05-22 15:24:08.092688] INFO hfbacktest: cached_daily_ds:DataSource(db785b011ecd4f88960d5357c945667aT)
    [2023-05-22 15:24:08.095361] INFO hfbacktest: cached_minute_ds:DataSource(d348283102dc4d80b0d5642ab0b4c5bdT)
    [2023-05-22 15:24:08.100228] INFO hfbacktest: cached_tick_ds:None
    [2023-05-22 15:24:08.102526] INFO hfbacktest: cached_each_ds:None
    [2023-05-22 15:24:08.105475] INFO hfbacktest: dominant_data_ds:None
    [2023-05-22 15:24:08.109301] INFO hfbacktest: read history data done, call run backtest(future,1m,100000,2020-01-21~2020-04-01) ...
    [2023-05-22 15:24:08.112195] INFO hfbacktest: run_algo: PyTradeEngine ver=1.0.0
    [2023-05-22 15:24:08.122427] INFO hfbacktest: run algo: init rv=0
    [2023-05-22 15:24:08.135694] INFO hfbacktest: run_algo: set_history_data frequency='1m', len=13125, rv=0
    [2023-05-22 15:24:08.138512] INFO hfbacktest: run_algo: add strategy funcs done rv=4, running...
    initialize
    2023-05-22 15:24:08.208019 2020-02-03 09:01:00 开空 for RB2005.SHF  最新价=3233.0 下单函数返回=1
    2023-05-22 15:24:08.215502 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3233.0000,6(Unknown),20200203 90100000,1_0_0,pystrategy]
    2023-05-22 15:24:08.238977 handle_order data:PyOrderData[bktfut,2,RB2005.SHF,'2','0',0,2,3233.0000,0(NotTraded),20200203 90100000,1_0_0,pystrategy]
    2023-05-22 15:24:08.256083 handle_order data:PyOrderData[bktfut,2,RB2005.SHF,'2','0',2,2,3233.0000,2(AllTraded),20200203 90100000,1_0_0,pystrategy]
    2023-05-22 15:24:08.262062 handle_trade data:PyTradeData(bktfut,2,RB2005.SHF,'2','0',2,3233.0000,     1,20200203 90200000,pystrategy,1_0_0)
    2023-05-22 15:24:08.267613 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3233.0000,3233.0000,8405.80,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.275024 达到止损点,全部平仓
    2023-05-22 15:24:08.281359 2020-02-03 09:59:00 止损平空 for RB2005.SHF  最新价=3288.0 下单函数返回=2
    2023-05-22 15:24:08.286543 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3288.0000,6(Unknown),20200203 95900000,2_0_0,pystrategy]
    2023-05-22 15:24:08.290655 handle_order data:PyOrderData[bktfut,3,RB2005.SHF,'1','2',0,2,3288.0000,0(NotTraded),20200203 95900000,2_0_0,pystrategy]
    2023-05-22 15:24:08.294632 handle_order data:PyOrderData[bktfut,3,RB2005.SHF,'1','2',2,2,3288.0000,2(AllTraded),20200203 95900000,2_0_0,pystrategy]
    2023-05-22 15:24:08.301132 handle_trade data:PyTradeData(bktfut,3,RB2005.SHF,'1','2',2,3288.0000,     2,20200203 100000000,pystrategy,2_0_0)
    2023-05-22 15:24:08.306531 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3233.0000,3289.0000,0.00,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.311469 2020-02-03 10:00:00 开空 for RB2005.SHF  最新价=3289.0 下单函数返回=3
    2023-05-22 15:24:08.315487 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3289.0000,6(Unknown),20200203 100000000,3_0_0,pystrategy]
    2023-05-22 15:24:08.319646 handle_order data:PyOrderData[bktfut,4,RB2005.SHF,'2','0',0,2,3289.0000,0(NotTraded),20200203 100000000,3_0_0,pystrategy]
    2023-05-22 15:24:08.323531 handle_order data:PyOrderData[bktfut,4,RB2005.SHF,'2','0',2,2,3289.0000,2(AllTraded),20200203 100000000,3_0_0,pystrategy]
    2023-05-22 15:24:08.327365 handle_trade data:PyTradeData(bktfut,4,RB2005.SHF,'2','0',2,3289.0000,     3,20200203 100100000,pystrategy,3_0_0)
    2023-05-22 15:24:08.331264 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3289.0000,3289.0000,8551.40,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.340571 2020-02-03 14:58:00 尾盘平空 for RB2005.SHF  最新价=3233.0 下单函数返回=4
    2023-05-22 15:24:08.344591 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3233.0000,6(Unknown),20200203 145800000,4_0_0,pystrategy]
    2023-05-22 15:24:08.348524 handle_order data:PyOrderData[bktfut,5,RB2005.SHF,'1','2',0,2,3233.0000,0(NotTraded),20200203 145800000,4_0_0,pystrategy]
    2023-05-22 15:24:08.354452 handle_order data:PyOrderData[bktfut,5,RB2005.SHF,'1','2',2,2,3233.0000,2(AllTraded),20200203 145800000,4_0_0,pystrategy]
    2023-05-22 15:24:08.361694 handle_trade data:PyTradeData(bktfut,5,RB2005.SHF,'1','2',2,3233.0000,     4,20200203 145900000,pystrategy,4_0_0)
    2023-05-22 15:24:08.368052 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3289.0000,3233.0000,0.00,20200203) at 0x0x7f0995062d20
    2023-05-22 15:24:08.428243 2020-02-11 09:20:00 开多 for RB2005.SHF  最新价=3368.0 下单函数返回=5
    2023-05-22 15:24:08.432855 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3368.0000,6(Unknown),20200211 92000000,5_0_0,pystrategy]
    2023-05-22 15:24:08.436880 handle_order data:PyOrderData[bktfut,6,RB2005.SHF,'1','0',0,2,3368.0000,0(NotTraded),20200211 92000000,5_0_0,pystrategy]
    2023-05-22 15:24:08.440875 handle_order data:PyOrderData[bktfut,6,RB2005.SHF,'1','0',2,2,3368.0000,2(AllTraded),20200211 92000000,5_0_0,pystrategy]
    2023-05-22 15:24:08.444880 handle_trade data:PyTradeData(bktfut,6,RB2005.SHF,'1','0',2,3367.0000,     5,20200211 92100000,pystrategy,5_0_0)
    2023-05-22 15:24:08.448621 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3367.0000,3367.0000,8754.20,20200211) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3371.0000,0.00,20200211) at 0x0x7f0995062d20
    2023-05-22 15:24:08.459251 2020-02-11 14:58:00 尾盘平多 for RB2005.SHF  最新价=3395.0 下单函数返回=6
    2023-05-22 15:24:08.463301 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3395.0000,6(Unknown),20200211 145800000,6_0_0,pystrategy]
    2023-05-22 15:24:08.468559 handle_order data:PyOrderData[bktfut,7,RB2005.SHF,'2','2',0,2,3395.0000,0(NotTraded),20200211 145800000,6_0_0,pystrategy]
    2023-05-22 15:24:08.484870 handle_order data:PyOrderData[bktfut,7,RB2005.SHF,'2','2',2,2,3395.0000,2(AllTraded),20200211 145800000,6_0_0,pystrategy]
    2023-05-22 15:24:08.499072 handle_trade data:PyTradeData(bktfut,7,RB2005.SHF,'2','2',2,3395.0000,     6,20200211 145900000,pystrategy,6_0_0)
    2023-05-22 15:24:08.506344 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3367.0000,3394.0000,0.00,20200211) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3394.0000,0.00,20200211) at 0x0x7f0995062d20
    2023-05-22 15:24:08.580442 2020-02-20 09:28:00 开多 for RB2005.SHF  最新价=3441.0 下单函数返回=7
    2023-05-22 15:24:08.588187 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3441.0000,6(Unknown),20200220 92800000,7_0_0,pystrategy]
    2023-05-22 15:24:08.597766 handle_order data:PyOrderData[bktfut,8,RB2005.SHF,'1','0',0,2,3441.0000,0(NotTraded),20200220 92800000,7_0_0,pystrategy]
    2023-05-22 15:24:08.606194 handle_order data:PyOrderData[bktfut,8,RB2005.SHF,'1','0',2,2,3441.0000,2(AllTraded),20200220 92800000,7_0_0,pystrategy]
    2023-05-22 15:24:08.617240 handle_trade data:PyTradeData(bktfut,8,RB2005.SHF,'1','0',2,3441.0000,     7,20200220 92900000,pystrategy,7_0_0)
    2023-05-22 15:24:08.631545 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3441.0000,3441.0000,8946.60,20200220) at 0x0x7f0995062d20 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3444.0000,0.00,20200220) at 0x0x7f0995062a40
    2023-05-22 15:24:08.653772 2020-02-20 14:58:00 尾盘平多 for RB2005.SHF  最新价=3457.0 下单函数返回=8
    2023-05-22 15:24:08.668402 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3457.0000,6(Unknown),20200220 145800000,8_0_0,pystrategy]
    2023-05-22 15:24:08.675927 handle_order data:PyOrderData[bktfut,9,RB2005.SHF,'2','2',0,2,3457.0000,0(NotTraded),20200220 145800000,8_0_0,pystrategy]
    2023-05-22 15:24:08.682525 handle_order data:PyOrderData[bktfut,9,RB2005.SHF,'2','2',2,2,3457.0000,2(AllTraded),20200220 145800000,8_0_0,pystrategy]
    2023-05-22 15:24:08.691302 handle_trade data:PyTradeData(bktfut,9,RB2005.SHF,'2','2',2,3458.0000,     8,20200220 145900000,pystrategy,8_0_0)
    2023-05-22 15:24:08.698690 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3441.0000,3457.0000,0.00,20200220) at 0x0x7f0995062d20 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3457.0000,0.00,20200220) at 0x0x7f0995062a40
    2023-05-22 15:24:08.745823 2020-02-28 09:05:00 开空 for RB2005.SHF  最新价=3347.0 下单函数返回=9
    2023-05-22 15:24:08.750480 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3347.0000,6(Unknown),20200228 90500000,9_0_0,pystrategy]
    2023-05-22 15:24:08.754287 handle_order data:PyOrderData[bktfut,10,RB2005.SHF,'2','0',0,2,3347.0000,0(NotTraded),20200228 90500000,9_0_0,pystrategy]
    2023-05-22 15:24:08.758222 handle_order data:PyOrderData[bktfut,10,RB2005.SHF,'2','0',2,2,3347.0000,2(AllTraded),20200228 90500000,9_0_0,pystrategy]
    2023-05-22 15:24:08.762290 handle_trade data:PyTradeData(bktfut,10,RB2005.SHF,'2','0',2,3347.0000,     9,20200228 90600000,pystrategy,9_0_0)
    2023-05-22 15:24:08.766062 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3340.0000,0.00,20200228) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3347.0000,3347.0000,8702.20,20200228) at 0x0x7f0995062d20
    2023-05-22 15:24:08.778502 2020-02-28 14:58:00 尾盘平空 for RB2005.SHF  最新价=3333.0 下单函数返回=10
    2023-05-22 15:24:08.783012 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3333.0000,6(Unknown),20200228 145800000,10_0_0,pystrategy]
    2023-05-22 15:24:08.786740 handle_order data:PyOrderData[bktfut,11,RB2005.SHF,'1','2',0,2,3333.0000,0(NotTraded),20200228 145800000,10_0_0,pystrategy]
    2023-05-22 15:24:08.790379 handle_order data:PyOrderData[bktfut,11,RB2005.SHF,'1','2',2,2,3333.0000,2(AllTraded),20200228 145800000,10_0_0,pystrategy]
    2023-05-22 15:24:08.794099 handle_trade data:PyTradeData(bktfut,11,RB2005.SHF,'1','2',2,3334.0000,    10,20200228 145900000,pystrategy,10_0_0)
    2023-05-22 15:24:08.797951 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3336.0000,0.00,20200228) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3347.0000,3336.0000,0.00,20200228) at 0x0x7f0995062d20
    2023-05-22 15:24:08.840482 2020-03-09 09:02:00 开空 for RB2005.SHF  最新价=3390.0 下单函数返回=11
    2023-05-22 15:24:08.845079 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3390.0000,6(Unknown),20200309 90200000,11_0_0,pystrategy]
    2023-05-22 15:24:08.849301 handle_order data:PyOrderData[bktfut,12,RB2005.SHF,'2','0',0,2,3390.0000,0(NotTraded),20200309 90200000,11_0_0,pystrategy]
    2023-05-22 15:24:08.853131 handle_order data:PyOrderData[bktfut,12,RB2005.SHF,'2','0',2,2,3390.0000,2(AllTraded),20200309 90200000,11_0_0,pystrategy]
    2023-05-22 15:24:08.857099 handle_trade data:PyTradeData(bktfut,12,RB2005.SHF,'2','0',2,3390.0000,    11,20200309 90300000,pystrategy,11_0_0)
    2023-05-22 15:24:08.860835 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3393.0000,0.00,20200309) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3390.0000,3390.0000,8814.00,20200309) at 0x0x7f0995062d20
    2023-05-22 15:24:08.872215 2020-03-09 14:58:00 尾盘平空 for RB2005.SHF  最新价=3439.0 下单函数返回=12
    2023-05-22 15:24:08.876441 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3439.0000,6(Unknown),20200309 145800000,12_0_0,pystrategy]
    2023-05-22 15:24:08.880779 handle_order data:PyOrderData[bktfut,13,RB2005.SHF,'1','2',0,2,3439.0000,0(NotTraded),20200309 145800000,12_0_0,pystrategy]
    2023-05-22 15:24:08.894261 handle_order data:PyOrderData[bktfut,13,RB2005.SHF,'1','2',2,2,3439.0000,2(AllTraded),20200309 145800000,12_0_0,pystrategy]
    2023-05-22 15:24:08.900804 handle_trade data:PyTradeData(bktfut,13,RB2005.SHF,'1','2',2,3439.0000,    12,20200309 145900000,pystrategy,12_0_0)
    2023-05-22 15:24:08.906758 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3438.0000,0.00,20200309) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3390.0000,3438.0000,0.00,20200309) at 0x0x7f0995062d20
    2023-05-22 15:24:08.996301 2020-03-19 10:14:00 开空 for RB2005.SHF  最新价=3456.0 下单函数返回=13
    2023-05-22 15:24:09.007368 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3456.0000,6(Unknown),20200319 101400000,13_0_0,pystrategy]
    2023-05-22 15:24:09.014790 handle_order data:PyOrderData[bktfut,14,RB2005.SHF,'2','0',0,2,3456.0000,0(NotTraded),20200319 101400000,13_0_0,pystrategy]
    2023-05-22 15:24:09.021356 handle_order data:PyOrderData[bktfut,14,RB2005.SHF,'2','0',2,2,3456.0000,2(AllTraded),20200319 101400000,13_0_0,pystrategy]
    2023-05-22 15:24:09.026382 handle_trade data:PyTradeData(bktfut,14,RB2005.SHF,'2','0',2,3457.0000,    13,20200319 101500000,pystrategy,13_0_0)
    2023-05-22 15:24:09.034208 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3460.0000,0.00,20200319) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3457.0000,3457.0000,8988.20,20200319) at 0x0x7f0995062d20
    2023-05-22 15:24:09.049877 达到止损点,全部平仓
    2023-05-22 15:24:09.059065 2020-03-19 14:20:00 止损平空 for RB2005.SHF  最新价=3507.0 下单函数返回=14
    2023-05-22 15:24:09.067613 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3507.0000,6(Unknown),20200319 142000000,14_0_0,pystrategy]
    2023-05-22 15:24:09.076212 handle_order data:PyOrderData[bktfut,15,RB2005.SHF,'1','2',0,2,3507.0000,0(NotTraded),20200319 142000000,14_0_0,pystrategy]
    2023-05-22 15:24:09.082652 handle_order data:PyOrderData[bktfut,15,RB2005.SHF,'1','2',2,2,3507.0000,2(AllTraded),20200319 142000000,14_0_0,pystrategy]
    2023-05-22 15:24:09.087750 handle_trade data:PyTradeData(bktfut,15,RB2005.SHF,'1','2',2,3507.0000,    14,20200319 142100000,pystrategy,14_0_0)
    2023-05-22 15:24:09.095981 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3510.0000,0.00,20200319) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3457.0000,3510.0000,0.00,20200319) at 0x0x7f0995062d20
    2023-05-22 15:24:09.147052 2020-03-30 09:11:00 开空 for RB2005.SHF  最新价=3408.0 下单函数返回=15
    2023-05-22 15:24:09.151852 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3408.0000,6(Unknown),20200330 91100000,15_0_0,pystrategy]
    2023-05-22 15:24:09.156129 handle_order data:PyOrderData[bktfut,16,RB2005.SHF,'2','0',0,2,3408.0000,0(NotTraded),20200330 91100000,15_0_0,pystrategy]
    2023-05-22 15:24:09.160076 handle_order data:PyOrderData[bktfut,16,RB2005.SHF,'2','0',2,2,3408.0000,2(AllTraded),20200330 91100000,15_0_0,pystrategy]
    2023-05-22 15:24:09.163865 handle_trade data:PyTradeData(bktfut,16,RB2005.SHF,'2','0',2,3406.0000,    15,20200330 91200000,pystrategy,15_0_0)
    2023-05-22 15:24:09.167922 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3409.0000,0.00,20200330) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3406.0000,3406.0000,8855.60,20200330) at 0x0x7f0995062d20
    2023-05-22 15:24:09.182402 2020-03-30 14:58:00 尾盘平空 for RB2005.SHF  最新价=3403.0 下单函数返回=16
    2023-05-22 15:24:09.189699 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3403.0000,6(Unknown),20200330 145800000,16_0_0,pystrategy]
    2023-05-22 15:24:09.195520 handle_order data:PyOrderData[bktfut,17,RB2005.SHF,'1','2',0,2,3403.0000,0(NotTraded),20200330 145800000,16_0_0,pystrategy]
    2023-05-22 15:24:09.200344 handle_order data:PyOrderData[bktfut,17,RB2005.SHF,'1','2',2,2,3403.0000,2(AllTraded),20200330 145800000,16_0_0,pystrategy]
    2023-05-22 15:24:09.207014 handle_trade data:PyTradeData(bktfut,17,RB2005.SHF,'1','2',2,3404.0000,    16,20200330 145900000,pystrategy,16_0_0)
    2023-05-22 15:24:09.213209 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3403.0000,0.00,20200330) at 0x0x7f0995062a40 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3406.0000,3403.0000,0.00,20200330) at 0x0x7f0995062d20
    [2023-05-22 15:24:09.240346] INFO hfbacktest: run_algo: done
    [2023-05-22 15:24:09.617932] INFO hfbacktest: backtest done, raw_perf_ds:DataSource(a5229e5a69294d37829d73f2ede164f3T)
    
    /usr/local/python3/lib/python3.8/site-packages/pandas/compat/_optional.py:116: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
      if distutils.version.LooseVersion(version) < minimum_version:
    /usr/local/python3/lib/python3.8/site-packages/setuptools/_distutils/version.py:346: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
      other = LooseVersion(other)
    /usr/local/python3/lib/python3.8/site-packages/tables/array.py:241: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
    Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
      (oid, self.atom, self.shape, self._v_chunkshape) = self._open_array()
    /usr/local/python3/lib/python3.8/site-packages/tables/atom.py:1224: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
      return pickle.loads(array.tostring())
    /var/app/enabled/fai/settings.py:22: ResourceWarning: unclosed <socket.socket fd=79, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.160.156.187', 59300), raddr=('10.102.176.195', 8000)>
    ResourceWarning: Enable tracemalloc to get the object allocation traceback
    /var/app/enabled/fai/lib/logsclient.py:37: DeprecationWarning: Importing DisplayHandle from IPython.core.display is deprecated since IPython 7.14, please import from IPython display
    [2023-05-22 15:24:12.053643] INFO: bigcharts.impl.render:render.py:407:render_chart Data is None, skip loading it to chart.
    
    2023-05-22 15:24:12.478709 perf_render_future process plot...
    
    • 收益率-0.87%
    • 年化收益率-4.48%
    • 基准收益率-10.68%
    • 阿尔法-0.06
    • 贝塔0.02
    • 夏普比率-2.07
    • 胜率0.62
    • 盈亏比0.45
    • 收益波动率3.7%
    • 最大回撤1.99%
    成交时间 合约代码 合约名称 买/卖 开/平 数量 成交价 交易金额 交易佣金 平仓盈亏
    Loading... (need help?)
    日期 合约代码 合约名称 持仓均价 收盘价 数量 持仓保证金 浮动盈亏 平仓盈亏
    Loading... (need help?)
    时间 级别 内容
    Loading... (need help?)
    [2023-05-22 15:24:12.530798] INFO moduleinvoker: hfbacktest.v2 运行完成[5.134s].
    
    INFO:moduleinvoker:hfbacktest.v2 运行完成[5.134s].
    
    [2023-05-22 15:24:12.653759] INFO moduleinvoker: hftrade.v2 运行完成[5.281694s].
    
    INFO:moduleinvoker:hftrade.v2 运行完成[5.281694s].
    
    In [ ]: