复制链接
克隆策略

策略名称

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 [3]:
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.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"

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 22:28:10.714707] INFO moduleinvoker: hfbacktest.v2 开始运行..
INFO:moduleinvoker:hfbacktest.v2 开始运行..
[2023-05-22 22:28:10.902402] INFO hfbacktest: passed-in daily_data_ds:None
INFO:hfbacktest:passed-in daily_data_ds:None
[2023-05-22 22:28:10.907344] INFO hfbacktest: passed-in minute_data_ds:None
INFO:hfbacktest:passed-in minute_data_ds:None
[2023-05-22 22:28:10.910653] INFO hfbacktest: passed-in tick_data_ds:None
INFO:hfbacktest:passed-in tick_data_ds:None
[2023-05-22 22:28:10.914001] INFO hfbacktest: passed-in each_data_ds:None
INFO:hfbacktest:passed-in each_data_ds:None
[2023-05-22 22:28:10.917368] INFO hfbacktest: passed-in dominant_data_ds:None
INFO:hfbacktest:passed-in dominant_data_ds:None
[2023-05-22 22:28:10.921308] INFO hfbacktest: passed-in basic_data_ds:None
INFO:hfbacktest:passed-in basic_data_ds:None
[2023-05-22 22:28:10.924485] INFO hfbacktest: passed-in benchmark_data_ds:None
INFO:hfbacktest:passed-in benchmark_data_ds:None
[2023-05-22 22:28:10.927596] INFO hfbacktest: hfbacktest2 V2.0.0
INFO:hfbacktest:hfbacktest2 V2.0.0
[2023-05-22 22:28:10.930576] INFO hfbacktest: pytradersdk v1.0.0 2023-05-19
INFO:hfbacktest:pytradersdk v1.0.0 2023-05-19
[2023-05-22 22:28:11.675939] INFO hfbacktest: strategy callbacks:{'initialize': <function initialize at 0x7f7f4f7f5430>, 'before_trading': <function before_trading at 0x7f7f4f7f54c0>, 'handle_data': <function handle_data at 0x7f7f4f7f5550>, 'handle_trade': <function handle_trade at 0x7f7f4f7f5a60>, 'handle_order': <function handle_order at 0x7f7f4f7f51f0>}
INFO:hfbacktest:strategy callbacks:{'initialize': <function initialize at 0x7f7f4f7f5430>, 'before_trading': <function before_trading at 0x7f7f4f7f54c0>, 'handle_data': <function handle_data at 0x7f7f4f7f5550>, 'handle_trade': <function handle_trade at 0x7f7f4f7f5a60>, 'handle_order': <function handle_order at 0x7f7f4f7f51f0>}
[2023-05-22 22:28:11.679930] INFO hfbacktest: begin reading history data, 2020-01-21 00:00:00~2020-04-01, disable_cache:False, replay_bdb:False
INFO:hfbacktest:begin reading history data, 2020-01-21 00:00:00~2020-04-01, disable_cache:False, replay_bdb:False
[2023-05-22 22:28:11.682797] INFO hfbacktest: reading benchmark data 000300.HIX 2020-01-21 00:00:00~2020-04-01...
INFO:hfbacktest:reading benchmark data 000300.HIX 2020-01-21 00:00:00~2020-04-01...
[2023-05-22 22:28:11.704713] INFO moduleinvoker: cached.v2 开始运行..
INFO:moduleinvoker:cached.v2 开始运行..
[2023-05-22 22:28:11.721103] INFO moduleinvoker: 命中缓存
INFO:moduleinvoker:命中缓存
[2023-05-22 22:28:11.725039] INFO moduleinvoker: cached.v2 运行完成[0.02041s].
INFO:moduleinvoker:cached.v2 运行完成[0.02041s].
/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())
[2023-05-22 22:28:12.025196] INFO hfbacktest: reading daily data 2019-01-21 00:00:00~2020-04-01...
INFO:hfbacktest:reading daily data 2019-01-21 00:00:00~2020-04-01...
[2023-05-22 22:28:12.042450] INFO moduleinvoker: cached.v2 开始运行..
INFO:moduleinvoker:cached.v2 开始运行..
[2023-05-22 22:28:12.052253] INFO moduleinvoker: 命中缓存
INFO:moduleinvoker:命中缓存
[2023-05-22 22:28:12.056440] INFO moduleinvoker: cached.v2 运行完成[0.014005s].
INFO:moduleinvoker:cached.v2 运行完成[0.014005s].
[2023-05-22 22:28:12.157068] INFO hfbacktest: reading minute data 2020-01-09 20:55:00~2020-04-01...
INFO:hfbacktest:reading minute data 2020-01-09 20:55:00~2020-04-01...
[2023-05-22 22:28:12.179014] INFO moduleinvoker: cached.v2 开始运行..
INFO:moduleinvoker:cached.v2 开始运行..
[2023-05-22 22:28:12.191454] INFO moduleinvoker: 命中缓存
INFO:moduleinvoker:命中缓存
[2023-05-22 22:28:12.195577] INFO moduleinvoker: cached.v2 运行完成[0.016598s].
INFO:moduleinvoker:cached.v2 运行完成[0.016598s].
[2023-05-22 22:28:13.147726] INFO hfbacktest: cached_benchmark_ds:DataSource(811c07e12631498a82fd2221807eee6cT)
INFO:hfbacktest:cached_benchmark_ds:DataSource(811c07e12631498a82fd2221807eee6cT)
[2023-05-22 22:28:13.151660] INFO hfbacktest: cached_daily_ds:DataSource(db785b011ecd4f88960d5357c945667aT)
INFO:hfbacktest:cached_daily_ds:DataSource(db785b011ecd4f88960d5357c945667aT)
[2023-05-22 22:28:13.155112] INFO hfbacktest: cached_minute_ds:DataSource(d348283102dc4d80b0d5642ab0b4c5bdT)
INFO:hfbacktest:cached_minute_ds:DataSource(d348283102dc4d80b0d5642ab0b4c5bdT)
[2023-05-22 22:28:13.159286] INFO hfbacktest: cached_tick_ds:None
INFO:hfbacktest:cached_tick_ds:None
[2023-05-22 22:28:13.162030] INFO hfbacktest: cached_each_ds:None
INFO:hfbacktest:cached_each_ds:None
[2023-05-22 22:28:13.164803] INFO hfbacktest: dominant_data_ds:None
INFO:hfbacktest:dominant_data_ds:None
[2023-05-22 22:28:13.167844] INFO hfbacktest: read history data done, call run backtest(future,1m,100000,2020-01-21~2020-04-01) ...
INFO:hfbacktest:read history data done, call run backtest(future,1m,100000,2020-01-21~2020-04-01) ...
[2023-05-22 22:28:13.191239] INFO hfbacktest: run_algo: PyTradeEngine ver=1.0.0
INFO:hfbacktest:run_algo: PyTradeEngine ver=1.0.0
[2023-05-22 22:28:13.203510] INFO hfbacktest: run algo: init rv=0
INFO:hfbacktest:run algo: init rv=0
[2023-05-22 22:28:13.217097] INFO hfbacktest: run_algo: set_history_data frequency='1m', len=13125, rv=0
INFO:hfbacktest:run_algo: set_history_data frequency='1m', len=13125, rv=0
[2023-05-22 22:28:13.222320] INFO hfbacktest: run_algo: add strategy funcs done rv=2, running...
INFO:hfbacktest:run_algo: add strategy funcs done rv=2, running...
initialize
2023-05-22 22:28:13.306761 2020-02-03 09:01:00 开空 for RB2005.SHF  最新价=3233.0 下单函数返回=1
2023-05-22 22:28:13.314293 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3233.0000,6(Unknown),20200203 90100000,1_0_0,pystrategy]
2023-05-22 22:28:13.320020 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 22:28:13.327382 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 22:28:13.333434 handle_trade data:PyTradeData(bktfut,2,RB2005.SHF,'2','0',2,3233.0000,     1,20200203 90200000,pystrategy,1_0_0)
2023-05-22 22:28:13.338944 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3233.0000,3233.0000,8405.80,20200203) at 0x0x7f7f4f838760
2023-05-22 22:28:13.347995 达到止损点,全部平仓
2023-05-22 22:28:13.354496 2020-02-03 09:59:00 止损平空 for RB2005.SHF  最新价=3288.0 下单函数返回=2
2023-05-22 22:28:13.360063 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3288.0000,6(Unknown),20200203 95900000,2_0_0,pystrategy]
2023-05-22 22:28:13.365441 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 22:28:13.370686 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 22:28:13.376248 handle_trade data:PyTradeData(bktfut,3,RB2005.SHF,'1','2',2,3288.0000,     2,20200203 100000000,pystrategy,2_0_0)
2023-05-22 22:28:13.383332 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3233.0000,3289.0000,0.00,20200203) at 0x0x7f7f4f838760
2023-05-22 22:28:13.391189 2020-02-03 10:00:00 开空 for RB2005.SHF  最新价=3289.0 下单函数返回=3
2023-05-22 22:28:13.397364 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3289.0000,6(Unknown),20200203 100000000,3_0_0,pystrategy]
2023-05-22 22:28:13.404168 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 22:28:13.412510 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 22:28:13.420607 handle_trade data:PyTradeData(bktfut,4,RB2005.SHF,'2','0',2,3289.0000,     3,20200203 100100000,pystrategy,3_0_0)
2023-05-22 22:28:13.430909 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3289.0000,0.00,20200203) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3289.0000,3289.0000,8551.40,20200203) at 0x0x7f7f4f838760
2023-05-22 22:28:13.448401 2020-02-03 14:58:00 尾盘平空 for RB2005.SHF  最新价=3233.0 下单函数返回=4
2023-05-22 22:28:13.457160 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3233.0000,6(Unknown),20200203 145800000,4_0_0,pystrategy]
2023-05-22 22:28:13.464444 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 22:28:13.472267 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 22:28:13.478401 handle_trade data:PyTradeData(bktfut,5,RB2005.SHF,'1','2',2,3233.0000,     4,20200203 145900000,pystrategy,4_0_0)
2023-05-22 22:28:13.486126 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3233.0000,0.00,20200203) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3289.0000,3233.0000,0.00,20200203) at 0x0x7f7f4f838760
2023-05-22 22:28:13.545131 2020-02-11 09:20:00 开多 for RB2005.SHF  最新价=3368.0 下单函数返回=5
2023-05-22 22:28:13.551655 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3368.0000,6(Unknown),20200211 92000000,5_0_0,pystrategy]
2023-05-22 22:28:13.557814 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 22:28:13.564221 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 22:28:13.569455 handle_trade data:PyTradeData(bktfut,6,RB2005.SHF,'1','0',2,3367.0000,     5,20200211 92100000,pystrategy,5_0_0)
2023-05-22 22:28:13.574824 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3367.0000,3367.0000,8754.20,20200211) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3371.0000,0.00,20200211) at 0x0x7f7f4f838760
2023-05-22 22:28:13.586185 2020-02-11 14:58:00 尾盘平多 for RB2005.SHF  最新价=3395.0 下单函数返回=6
2023-05-22 22:28:13.591973 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3395.0000,6(Unknown),20200211 145800000,6_0_0,pystrategy]
2023-05-22 22:28:13.597549 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 22:28:13.603210 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 22:28:13.608527 handle_trade data:PyTradeData(bktfut,7,RB2005.SHF,'2','2',2,3395.0000,     6,20200211 145900000,pystrategy,6_0_0)
2023-05-22 22:28:13.613979 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3367.0000,3394.0000,0.00,20200211) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3394.0000,0.00,20200211) at 0x0x7f7f4f838760
2023-05-22 22:28:13.668265 2020-02-20 09:28:00 开多 for RB2005.SHF  最新价=3441.0 下单函数返回=7
2023-05-22 22:28:13.674789 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','0',0,2,3441.0000,6(Unknown),20200220 92800000,7_0_0,pystrategy]
2023-05-22 22:28:13.682089 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 22:28:13.689199 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 22:28:13.694961 handle_trade data:PyTradeData(bktfut,8,RB2005.SHF,'1','0',2,3441.0000,     7,20200220 92900000,pystrategy,7_0_0)
2023-05-22 22:28:13.700730 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',2,2,2,0|0,3441.0000,3441.0000,8946.60,20200220) at 0x0x7f7f4f838760 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3444.0000,0.00,20200220) at 0x0x7f7f4f838480
2023-05-22 22:28:13.712603 2020-02-20 14:58:00 尾盘平多 for RB2005.SHF  最新价=3457.0 下单函数返回=8
2023-05-22 22:28:13.719660 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','2',0,2,3457.0000,6(Unknown),20200220 145800000,8_0_0,pystrategy]
2023-05-22 22:28:13.725666 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 22:28:13.731920 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 22:28:13.737409 handle_trade data:PyTradeData(bktfut,9,RB2005.SHF,'2','2',2,3458.0000,     8,20200220 145900000,pystrategy,8_0_0)
2023-05-22 22:28:13.742779 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,3441.0000,3457.0000,0.00,20200220) at 0x0x7f7f4f838760 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,0.0000,3457.0000,0.00,20200220) at 0x0x7f7f4f838480
2023-05-22 22:28:13.793466 2020-02-28 09:05:00 开空 for RB2005.SHF  最新价=3347.0 下单函数返回=9
2023-05-22 22:28:13.799932 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3347.0000,6(Unknown),20200228 90500000,9_0_0,pystrategy]
2023-05-22 22:28:13.805441 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 22:28:13.812035 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 22:28:13.817730 handle_trade data:PyTradeData(bktfut,10,RB2005.SHF,'2','0',2,3347.0000,     9,20200228 90600000,pystrategy,9_0_0)
2023-05-22 22:28:13.826707 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3340.0000,0.00,20200228) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3347.0000,3347.0000,8702.20,20200228) at 0x0x7f7f4f838760
2023-05-22 22:28:13.844583 2020-02-28 14:58:00 尾盘平空 for RB2005.SHF  最新价=3333.0 下单函数返回=10
2023-05-22 22:28:13.853922 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3333.0000,6(Unknown),20200228 145800000,10_0_0,pystrategy]
2023-05-22 22:28:13.859853 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 22:28:13.865176 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 22:28:13.871293 handle_trade data:PyTradeData(bktfut,11,RB2005.SHF,'1','2',2,3334.0000,    10,20200228 145900000,pystrategy,10_0_0)
2023-05-22 22:28:13.878177 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3336.0000,0.00,20200228) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3347.0000,3336.0000,0.00,20200228) at 0x0x7f7f4f838760
2023-05-22 22:28:13.925569 2020-03-09 09:02:00 开空 for RB2005.SHF  最新价=3390.0 下单函数返回=11
2023-05-22 22:28:13.934297 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3390.0000,6(Unknown),20200309 90200000,11_0_0,pystrategy]
2023-05-22 22:28:13.940585 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 22:28:13.947779 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 22:28:13.955401 handle_trade data:PyTradeData(bktfut,12,RB2005.SHF,'2','0',2,3390.0000,    11,20200309 90300000,pystrategy,11_0_0)
2023-05-22 22:28:13.962779 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3393.0000,0.00,20200309) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3390.0000,3390.0000,8814.00,20200309) at 0x0x7f7f4f838760
2023-05-22 22:28:13.981945 2020-03-09 14:58:00 尾盘平空 for RB2005.SHF  最新价=3439.0 下单函数返回=12
2023-05-22 22:28:13.989084 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3439.0000,6(Unknown),20200309 145800000,12_0_0,pystrategy]
2023-05-22 22:28:13.995224 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 22:28:14.001179 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 22:28:14.007370 handle_trade data:PyTradeData(bktfut,13,RB2005.SHF,'1','2',2,3439.0000,    12,20200309 145900000,pystrategy,12_0_0)
2023-05-22 22:28:14.013000 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3438.0000,0.00,20200309) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3390.0000,3438.0000,0.00,20200309) at 0x0x7f7f4f838760
2023-05-22 22:28:14.090294 2020-03-19 10:14:00 开空 for RB2005.SHF  最新价=3456.0 下单函数返回=13
2023-05-22 22:28:14.097221 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3456.0000,6(Unknown),20200319 101400000,13_0_0,pystrategy]
2023-05-22 22:28:14.103593 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 22:28:14.108800 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 22:28:14.115199 handle_trade data:PyTradeData(bktfut,14,RB2005.SHF,'2','0',2,3457.0000,    13,20200319 101500000,pystrategy,13_0_0)
2023-05-22 22:28:14.122128 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3460.0000,0.00,20200319) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3457.0000,3457.0000,8988.20,20200319) at 0x0x7f7f4f838760
2023-05-22 22:28:14.132243 达到止损点,全部平仓
2023-05-22 22:28:14.137998 2020-03-19 14:20:00 止损平空 for RB2005.SHF  最新价=3507.0 下单函数返回=14
2023-05-22 22:28:14.144398 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3507.0000,6(Unknown),20200319 142000000,14_0_0,pystrategy]
2023-05-22 22:28:14.150598 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 22:28:14.156075 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 22:28:14.161864 handle_trade data:PyTradeData(bktfut,15,RB2005.SHF,'1','2',2,3507.0000,    14,20200319 142100000,pystrategy,14_0_0)
2023-05-22 22:28:14.169986 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3510.0000,0.00,20200319) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3457.0000,3510.0000,0.00,20200319) at 0x0x7f7f4f838760
2023-05-22 22:28:14.250160 2020-03-30 09:11:00 开空 for RB2005.SHF  最新价=3408.0 下单函数返回=15
2023-05-22 22:28:14.257712 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'2','0',0,2,3408.0000,6(Unknown),20200330 91100000,15_0_0,pystrategy]
2023-05-22 22:28:14.264382 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 22:28:14.270843 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 22:28:14.277018 handle_trade data:PyTradeData(bktfut,16,RB2005.SHF,'2','0',2,3406.0000,    15,20200330 91200000,pystrategy,15_0_0)
2023-05-22 22:28:14.284100 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3409.0000,0.00,20200330) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',2,2,2,0|0,3406.0000,3406.0000,8855.60,20200330) at 0x0x7f7f4f838760
2023-05-22 22:28:14.300402 2020-03-30 14:58:00 尾盘平空 for RB2005.SHF  最新价=3403.0 下单函数返回=16
2023-05-22 22:28:14.307827 handle_order data:PyOrderData[bktfut,,RB2005.SHF,'1','2',0,2,3403.0000,6(Unknown),20200330 145800000,16_0_0,pystrategy]
2023-05-22 22:28:14.313897 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 22:28:14.320172 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 22:28:14.325666 handle_trade data:PyTradeData(bktfut,17,RB2005.SHF,'1','2',2,3404.0000,    16,20200330 145900000,pystrategy,16_0_0)
2023-05-22 22:28:14.333605 当前多头持仓:PyPositionData('1',bktfut,RB2005.SHF,'1',0,0,0,0|0,0.0000,3403.0000,0.00,20200330) at 0x0x7f7f4f838480 当前空头持仓:PyPositionData('1',bktfut,RB2005.SHF,'2',0,0,0,0|0,3406.0000,3403.0000,0.00,20200330) at 0x0x7f7f4f838760
[2023-05-22 22:28:14.360687] INFO hfbacktest: run_algo: done
INFO:hfbacktest:run_algo: done
[2023-05-22 22:28:14.639926] INFO hfbacktest: backtest done, raw_perf_ds:DataSource(16a40d6f9aa544ff8aca28e6938419faT)
INFO:hfbacktest:backtest done, raw_perf_ds:DataSource(16a40d6f9aa544ff8aca28e6938419faT)
/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())
[2023-05-22 22:28:15.172030] INFO: bigcharts.impl.render:render.py:407:render_chart Data is None, skip loading it to chart.
2023-05-22 22:28:15.601326 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 22:28:15.659162] INFO moduleinvoker: hfbacktest.v2 运行完成[4.944414s].
INFO:moduleinvoker:hfbacktest.v2 运行完成[4.944414s].
[2023-05-22 22:28:15.663222] INFO moduleinvoker: hftrade.v2 运行完成[4.97861s].
INFO:moduleinvoker:hftrade.v2 运行完成[4.97861s].
In [ ]: