克隆策略

期现套利策略

版本 v1.0

目录

期现利策略的交易规则

策略构建步骤

策略的实现

正文

一、期现套利策略的交易规则

  • 关于期货螺纹钢近期合约RB2109.SHF,远期合约RB2111.SHF的价格的相关性:
  • spread = 近期合约收盘价 - 远期合约收盘价
  • spread<-200,近期合约被低估,远期合约被高估,做多近期,做空远期。
  • spread>100,近期合约被高估,远期合约被低估,做空近期,做多远期。
  • 本策略一直持有仓位,即出现买卖信号时,平掉当前持仓。

二、策略构建步骤

1、确定股票池和回测时间

  • 通过证券代码列表输入回测的起止日期

2、确定买卖条件信号

  • spread<-200,近期合约被低估,远期合约被高估,做多近期,做空远期。
  • spread>100,近期合约被高估,远期合约被低估,做空近期,做多远期。

3、回测

  • 通过 trade 模块中的初始化函数定义交易手续费和滑点;
  • 通过 trade 模块中的主函数(handle函数)查看每日的买卖交易信号,按照买卖原则执行相应的买入/卖出/调仓操作。

三、策略的实现

可视化策略实现如下:

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-1659:instruments","from_node_id":"-1681:data"},{"to_node_id":"-39:instruments","from_node_id":"-1681:data"},{"to_node_id":"-1659:options_data","from_node_id":"-39:data"}],"nodes":[{"node_id":"-1659","module_id":"BigQuantSpace.hftrade.hftrade-v1","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"initialize","value":"\n# 交易引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n #输出关键日志\n msg = \"initialize:\" \n context.PRINT = 1\n context.write_log(msg, stdout=context.PRINT)\n contract_date_list=[]\n for ins in context.instruments:\n contract_date_list.append(int(ins.split('.')[0][-4:]))\n \n #获取每个合约代码\n for ins in context.instruments:\n if int(ins.split('.')[0][-4:]) == min(contract_date_list):\n context.instrument_nearby_contract = ins\n elif int(ins.split('.')[0][-4:]) == max(contract_date_list):\n context.instrument_forward_contract = ins\n \n #下单手数\n context.order_num = 1\n\n #获取数据,提前算出开平仓信号,减少回测时间\n all_data = context.options[\"data\"].read()\n df_nearby_contract = all_data[all_data.instrument==context.instrument_nearby_contract][[\"date\",\"close\"]].rename(columns={\"close\":\"close_nearby_contract\"})\n df_forward_contract = all_data[all_data.instrument==context.instrument_forward_contract][[\"date\",\"close\"]].rename(columns={\"close\":\"close_forward_contract\"})\n merge_df = pd.merge(left=df_nearby_contract,right=df_forward_contract,on=[\"date\"])\n \n merge_df[\"spread\"] = merge_df[\"close_nearby_contract\"]-merge_df[\"close_forward_contract\"]\n \n \n #现货正向信号\n positive_signal = (merge_df[\"spread\"].shift(1)>-200)&(merge_df[\"spread\"]<=-200)\n merge_df[\"signal\"] = np.where(positive_signal,1,np.NAN)\n #现货负向信号\n negative_signal = (merge_df[\"spread\"].shift(1)<100)&(merge_df[\"spread\"]>=100)\n merge_df[\"signal\"] = np.where(negative_signal,-1,merge_df[\"signal\"])\n context.mydata = merge_df\n","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n # 订阅要交易的合约的行情\n context.subscribe([context.instrument_nearby_contract,context.instrument_forward_contract])","type":"Literal","bound_global_parameter":null},{"name":"handle_tick","value":"# 交易引擎:tick数据处理函数,每个tick执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"#平仓\ndef close_orders(context,data):\n #获取当前时间\n cur_date = data.current_dt.strftime('%Y-%m-%d')\n\n \n for ins in [context.instrument_nearby_contract,context.instrument_forward_contract]:\n # 分别获取多头持仓和空头持仓\n position_long = context.get_position(ins, Direction.LONG)\n position_short = context.get_position(ins, Direction.SHORT)\n price = data.current(ins,\"close\")\n if(position_long.current_qty != 0):\n rv = context.sell_close(ins, position_long.avail_qty, price, order_type=OrderType.MARKET)\n msg = \"{} 平多 for {} 最新价={} 下单函数返回 {}\".format(cur_date,ins,price,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT) \n if(position_short.current_qty != 0):\n rv = context.buy_close(ins, position_short.avail_qty, price, order_type=OrderType.MARKET)\n msg = \"{} 平空 for {} 最新价={} 下单函数返回 {}\".format(cur_date,ins,price,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT) \n \n# 交易引擎:bar数据处理函数,每个时间单位执行一次\ndef bigquant_run(context, data):\n #获取当前时间\n cur_date = data.current_dt.strftime('%Y-%m-%d')\n #获取当天开仓信号 \n now_data = context.mydata[context.mydata.date==cur_date]\n if len(now_data)==0:\n context.write_log(\"{}无数据,直接返回\".format(cur_date), stdout=context.PRINT)\n return\n #正向开仓 \n if now_data.signal.iloc[0]==1:\n #先平掉所有持仓\n close_orders(context,data)\n #做多2109\n price = data.current(context.instrument_nearby_contract,\"close\")\n rv = context.buy_open(context.instrument_nearby_contract, context.order_num, price, order_type=OrderType.MARKET)\n msg = \"{} 开多 for {} 最新价={} 下单函数返回 {}\".format(cur_date,context.instrument_nearby_contract,price,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT) \n #做空2111\n price = data.current(context.instrument_forward_contract,\"close\")\n rv = context.sell_open(context.instrument_forward_contract, context.order_num, price, order_type=OrderType.MARKET)\n msg = \"{} 开空 for {} 最新价={} 下单函数返回 {}\".format(cur_date,context.instrument_forward_contract,price,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT)\n \n #反向开仓 \n elif now_data.signal.iloc[0]==-1:\n #先平掉所有持仓\n close_orders(context,data)\n #做多2111\n price = data.current(context.instrument_forward_contract,\"close\")\n rv = context.buy_open(context.instrument_forward_contract, context.order_num, price, order_type=OrderType.MARKET)\n msg = \"{} 开多 for {} 最新价={} 下单函数返回 {}\".format(cur_date,context.instrument_forward_contract,price,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT) \n #做空2109\n price = data.current(context.instrument_nearby_contract,\"close\")\n rv = context.sell_open(context.instrument_nearby_contract, context.order_num, price, order_type=OrderType.MARKET)\n msg = \"{} 开空 for {} 最新价={} 下单函数返回 {}\".format(cur_date,context.instrument_nearby_contract,price,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT) \n\n","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, data):\n msg = \"handle_trade data:{}\".format(data.log_str())\n context.write_log(msg, stdout=context.PRINT) \n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, data):\n msg = \"handle_order data:{}\".format(data.log_str())\n context.write_log(msg, stdout=context.PRINT)\n","type":"Literal","bound_global_parameter":null},{"name":"after_trading","value":"# 交易引擎:盘后处理函数,每日盘后执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":"100000","type":"Literal","bound_global_parameter":null},{"name":"frequency","value":"daily","type":"Literal","bound_global_parameter":null},{"name":"price_type","value":"真实价格","type":"Literal","bound_global_parameter":null},{"name":"product_type","value":"期货","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"0","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.HIX","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"disable_cache","value":"False","type":"Literal","bound_global_parameter":null},{"name":"show_debug_info","value":"True","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-1659"},{"name":"history_ds","node_id":"-1659"},{"name":"benchmark_ds","node_id":"-1659"},{"name":"options_data","node_id":"-1659"}],"output_ports":[{"name":"raw_perf","node_id":"-1659"}],"cacheable":false,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-1681","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-04-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-08-30","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_FUTURE","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"RB2109.SHF\nRB2111.SHF\n","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-1681"}],"output_ports":[{"name":"data","node_id":"-1681"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-39","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_CN_FUTURE","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-39"},{"name":"features","node_id":"-39"}],"output_ports":[{"name":"data","node_id":"-39"}],"cacheable":false,"seq_num":3,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-1659' Position='358,264,200,200'/><node_position Node='-1681' Position='359,56,200,200'/><node_position Node='-39' Position='411,145,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [27]:
    # 本代码由可视化策略环境自动生成 2021年12月1日 16:56
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    
    # 交易引擎:初始化函数,只执行一次
    def m1_initialize_bigquant_run(context):
        #输出关键日志
        msg = "initialize:" 
        context.PRINT = 1
        context.write_log(msg, stdout=context.PRINT)
        contract_date_list=[]
        for ins in context.instruments:
            contract_date_list.append(int(ins.split('.')[0][-4:]))
            
        #获取每个合约代码
        for ins in context.instruments:
            if int(ins.split('.')[0][-4:]) == min(contract_date_list):
                context.instrument_nearby_contract = ins
            elif int(ins.split('.')[0][-4:]) == max(contract_date_list):
                context.instrument_forward_contract = ins
           
        #下单手数
        context.order_num = 1
    
        #获取数据,提前算出开平仓信号,减少回测时间
        all_data = context.options["data"].read()
        df_nearby_contract = all_data[all_data.instrument==context.instrument_nearby_contract][["date","close"]].rename(columns={"close":"close_nearby_contract"})
        df_forward_contract = all_data[all_data.instrument==context.instrument_forward_contract][["date","close"]].rename(columns={"close":"close_forward_contract"})
        merge_df = pd.merge(left=df_nearby_contract,right=df_forward_contract,on=["date"])
        
        merge_df["spread"] = merge_df["close_nearby_contract"]-merge_df["close_forward_contract"]
        
        
        #现货正向信号
        positive_signal = (merge_df["spread"].shift(1)>-200)&(merge_df["spread"]<=-200)
        merge_df["signal"] = np.where(positive_signal,1,np.NAN)
        #现货负向信号
        negative_signal = (merge_df["spread"].shift(1)<100)&(merge_df["spread"]>=100)
        merge_df["signal"] = np.where(negative_signal,-1,merge_df["signal"])
        context.mydata = merge_df
    
    # 交易引擎:每个单位时间开盘前调用一次。
    def m1_before_trading_start_bigquant_run(context, data):
        # 订阅要交易的合约的行情
        context.subscribe([context.instrument_nearby_contract,context.instrument_forward_contract])
    # 交易引擎:tick数据处理函数,每个tick执行一次
    def m1_handle_tick_bigquant_run(context, data):
        pass
    
    #平仓
    def close_orders(context,data):
        #获取当前时间
        cur_date = data.current_dt.strftime('%Y-%m-%d')
    
        
        for ins in [context.instrument_nearby_contract,context.instrument_forward_contract]:
            # 分别获取多头持仓和空头持仓
            position_long = context.get_position(ins, Direction.LONG)
            position_short = context.get_position(ins, Direction.SHORT)
            price = data.current(ins,"close")
            if(position_long.current_qty != 0):
                rv = context.sell_close(ins, position_long.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 平多 for {}  最新价={} 下单函数返回 {}".format(cur_date,ins,price,context.get_error_msg(rv))
                context.write_log(msg, stdout=context.PRINT) 
            if(position_short.current_qty != 0):
                rv = context.buy_close(ins, position_short.avail_qty, price, order_type=OrderType.MARKET)
                msg = "{} 平空 for {}  最新价={} 下单函数返回 {}".format(cur_date,ins,price,context.get_error_msg(rv))
                context.write_log(msg, stdout=context.PRINT) 
                
    # 交易引擎:bar数据处理函数,每个时间单位执行一次
    def m1_handle_data_bigquant_run(context, data):
        #获取当前时间
        cur_date = data.current_dt.strftime('%Y-%m-%d')
        #获取当天开仓信号    
        now_data = context.mydata[context.mydata.date==cur_date]
        if len(now_data)==0:
            context.write_log("{}无数据,直接返回".format(cur_date), stdout=context.PRINT)
            return
        #正向开仓    
        if now_data.signal.iloc[0]==1:
            #先平掉所有持仓
            close_orders(context,data)
            #做多2109
            price = data.current(context.instrument_nearby_contract,"close")
            rv = context.buy_open(context.instrument_nearby_contract, context.order_num, price, order_type=OrderType.MARKET)
            msg = "{} 开多 for {}  最新价={} 下单函数返回 {}".format(cur_date,context.instrument_nearby_contract,price,context.get_error_msg(rv))
            context.write_log(msg, stdout=context.PRINT) 
            #做空2111
            price = data.current(context.instrument_forward_contract,"close")
            rv = context.sell_open(context.instrument_forward_contract, context.order_num, price, order_type=OrderType.MARKET)
            msg = "{} 开空 for {}  最新价={} 下单函数返回 {}".format(cur_date,context.instrument_forward_contract,price,context.get_error_msg(rv))
            context.write_log(msg, stdout=context.PRINT)
            
        #反向开仓    
        elif now_data.signal.iloc[0]==-1:
            #先平掉所有持仓
            close_orders(context,data)
            #做多2111
            price = data.current(context.instrument_forward_contract,"close")
            rv = context.buy_open(context.instrument_forward_contract, context.order_num, price, order_type=OrderType.MARKET)
            msg = "{} 开多 for {}  最新价={} 下单函数返回 {}".format(cur_date,context.instrument_forward_contract,price,context.get_error_msg(rv))
            context.write_log(msg, stdout=context.PRINT) 
            #做空2109
            price = data.current(context.instrument_nearby_contract,"close")
            rv = context.sell_open(context.instrument_nearby_contract, context.order_num, price, order_type=OrderType.MARKET)
            msg = "{} 开空 for {}  最新价={} 下单函数返回 {}".format(cur_date,context.instrument_nearby_contract,price,context.get_error_msg(rv))
            context.write_log(msg, stdout=context.PRINT) 
    
    
    # 交易引擎:成交回报处理函数,每个成交发生时执行一次
    def m1_handle_trade_bigquant_run(context, data):
        msg = "handle_trade data:{}".format(data.log_str())
        context.write_log(msg, stdout=context.PRINT) 
    
    # 交易引擎:委托回报处理函数,每个委托变化时执行一次
    def m1_handle_order_bigquant_run(context, data):
        msg = "handle_order data:{}".format(data.log_str())
        context.write_log(msg, stdout=context.PRINT)
    
    # 交易引擎:盘后处理函数,每日盘后执行一次
    def m1_after_trading_bigquant_run(context, data):
        pass
    
    
    m2 = M.instruments.v2(
        start_date='2021-04-01',
        end_date='2021-08-30',
        market='CN_FUTURE',
        instrument_list="""RB2109.SHF
    RB2111.SHF
    """,
        max_count=0
    )
    
    m3 = M.use_datasource.v1(
        instruments=m2.data,
        datasource_id='bar1d_CN_FUTURE',
        start_date='',
        end_date='',
        m_cached=False
    )
    
    m1 = M.hftrade.v1(
        instruments=m2.data,
        options_data=m3.data,
        start_date='',
        end_date='',
        initialize=m1_initialize_bigquant_run,
        before_trading_start=m1_before_trading_start_bigquant_run,
        handle_tick=m1_handle_tick_bigquant_run,
        handle_data=m1_handle_data_bigquant_run,
        handle_trade=m1_handle_trade_bigquant_run,
        handle_order=m1_handle_order_bigquant_run,
        after_trading=m1_after_trading_bigquant_run,
        capital_base=100000,
        frequency='daily',
        price_type='真实价格',
        product_type='期货',
        before_start_days='0',
        benchmark='000300.HIX',
        plot_charts=True,
        disable_cache=False,
        show_debug_info=True,
        backtest_only=False
    )
    
    2021-11-12 18:47:20.862005 run trading v1.7.8_sp2 
    2021-11-12 18:47:20.862182 init history datas... 
    2021-11-12 18:47:20.870027 init trading env... 
    2021-11-12 18:47:20.870388 run_backtest() capital:100000, frequency:1d, product_type:future, date:2021-04-01 00:00:00 ~ 2021-08-30 00:00:00 
    2021-11-12 18:47:20.870791 run_backtest() running... 
    2021-11-12 18:47:20.883717 strategy_20211112(bkt999,): initialize: 
    2021-11-12 18:47:21.055113 strategy_20211112(bkt999,): 2021-04-02 开多 for RB2111.SHF  最新价=4986.0 下单函数返回 OK 
    2021-11-12 18:47:21.056048 strategy_20211112(bkt999,): 2021-04-02 开空 for RB2109.SHF  最新价=5110.0 下单函数返回 OK 
    2021-11-12 18:47:21.066726 strategy_20211112(bkt999,): handle_order data:[bkt999,1,RB2111.SHF,long,open,0,1,4986.0,pending,20210406 08:30:00,1,strategy_20211112] 
    2021-11-12 18:47:21.067686 strategy_20211112(bkt999,): handle_order data:[bkt999,2,RB2109.SHF,short,open,0,1,5110.0,pending,20210406 08:30:00,2,strategy_20211112] 
    2021-11-12 18:47:21.070041 strategy_20211112(bkt999,): handle_order data:[bkt999,1,RB2111.SHF,long,open,1,1,4986.0,filled,20210406 08:30:00,1,strategy_20211112] 
    2021-11-12 18:47:21.071394 strategy_20211112(bkt999,): handle_trade data:[bkt999,1,RB2111.SHF,long,open,1,5071.0,1,20210406 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:21.073542 strategy_20211112(bkt999,): handle_order data:[bkt999,2,RB2109.SHF,short,open,1,1,5110.0,filled,20210406 08:30:00,2,strategy_20211112] 
    2021-11-12 18:47:21.074297 strategy_20211112(bkt999,): handle_trade data:[bkt999,2,RB2109.SHF,short,open,1,5118.0,2,20210406 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:21.557135 strategy_20211112(bkt999,): 2021-05-26 平空 for RB2109.SHF  最新价=4738.0 下单函数返回 OK 
    2021-11-12 18:47:21.558758 strategy_20211112(bkt999,): 2021-05-26 平多 for RB2111.SHF  最新价=4620.0 下单函数返回 OK 
    2021-11-12 18:47:21.559803 strategy_20211112(bkt999,): 2021-05-26 开多 for RB2111.SHF  最新价=4620.0 下单函数返回 OK 
    2021-11-12 18:47:21.561365 strategy_20211112(bkt999,): 2021-05-26 开空 for RB2109.SHF  最新价=4738.0 下单函数返回 OK 
    2021-11-12 18:47:21.574221 strategy_20211112(bkt999,): handle_order data:[bkt999,3,RB2109.SHF,long,close,0,1,4738.0,pending,20210526 20:30:00,3,strategy_20211112] 
    2021-11-12 18:47:21.574715 strategy_20211112(bkt999,): handle_order data:[bkt999,4,RB2111.SHF,short,close,0,1,4620.0,pending,20210526 20:30:00,4,strategy_20211112] 
    2021-11-12 18:47:21.575220 strategy_20211112(bkt999,): handle_order data:[bkt999,5,RB2111.SHF,long,open,0,1,4620.0,pending,20210526 20:30:00,5,strategy_20211112] 
    2021-11-12 18:47:21.575918 strategy_20211112(bkt999,): handle_order data:[bkt999,6,RB2109.SHF,short,open,0,1,4738.0,pending,20210526 20:30:00,6,strategy_20211112] 
    2021-11-12 18:47:21.578728 strategy_20211112(bkt999,): handle_order data:[bkt999,3,RB2109.SHF,long,close,1,1,4738.0,filled,20210526 20:30:00,3,strategy_20211112] 
    2021-11-12 18:47:21.579098 strategy_20211112(bkt999,): handle_trade data:[bkt999,3,RB2109.SHF,long,close,1,4713.0,3,20210527 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:21.581593 strategy_20211112(bkt999,): handle_order data:[bkt999,4,RB2111.SHF,short,close,1,1,4620.0,filled,20210526 20:30:00,4,strategy_20211112] 
    2021-11-12 18:47:21.581970 strategy_20211112(bkt999,): handle_trade data:[bkt999,4,RB2111.SHF,short,close,1,4620.0,4,20210527 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:21.584831 strategy_20211112(bkt999,): handle_order data:[bkt999,5,RB2111.SHF,long,open,1,1,4620.0,filled,20210526 20:30:00,5,strategy_20211112] 
    2021-11-12 18:47:21.585337 strategy_20211112(bkt999,): handle_trade data:[bkt999,5,RB2111.SHF,long,open,1,4620.0,5,20210527 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:21.588034 strategy_20211112(bkt999,): handle_order data:[bkt999,6,RB2109.SHF,short,open,1,1,4738.0,filled,20210526 20:30:00,6,strategy_20211112] 
    2021-11-12 18:47:21.588686 strategy_20211112(bkt999,): handle_trade data:[bkt999,6,RB2109.SHF,short,open,1,4713.0,6,20210527 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.220222 strategy_20211112(bkt999,): 2021-07-20 平空 for RB2109.SHF  最新价=5383.0 下单函数返回 OK 
    2021-11-12 18:47:22.221824 strategy_20211112(bkt999,): 2021-07-20 平多 for RB2111.SHF  最新价=5584.0 下单函数返回 OK 
    2021-11-12 18:47:22.223047 strategy_20211112(bkt999,): 2021-07-20 开多 for RB2109.SHF  最新价=5383.0 下单函数返回 OK 
    2021-11-12 18:47:22.224022 strategy_20211112(bkt999,): 2021-07-20 开空 for RB2111.SHF  最新价=5584.0 下单函数返回 OK 
    2021-11-12 18:47:22.238429 strategy_20211112(bkt999,): handle_order data:[bkt999,7,RB2109.SHF,long,close,0,1,5383.0,pending,20210720 20:30:00,7,strategy_20211112] 
    2021-11-12 18:47:22.238952 strategy_20211112(bkt999,): handle_order data:[bkt999,8,RB2111.SHF,short,close,0,1,5584.0,pending,20210720 20:30:00,8,strategy_20211112] 
    2021-11-12 18:47:22.239407 strategy_20211112(bkt999,): handle_order data:[bkt999,9,RB2109.SHF,long,open,0,1,5383.0,pending,20210720 20:30:00,9,strategy_20211112] 
    2021-11-12 18:47:22.239854 strategy_20211112(bkt999,): handle_order data:[bkt999,10,RB2111.SHF,short,open,0,1,5584.0,pending,20210720 20:30:00,10,strategy_20211112] 
    2021-11-12 18:47:22.243432 strategy_20211112(bkt999,): handle_order data:[bkt999,7,RB2109.SHF,long,close,1,1,5383.0,filled,20210720 20:30:00,7,strategy_20211112] 
    2021-11-12 18:47:22.244204 strategy_20211112(bkt999,): handle_trade data:[bkt999,7,RB2109.SHF,long,close,1,5339.0,7,20210721 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.246853 strategy_20211112(bkt999,): handle_order data:[bkt999,8,RB2111.SHF,short,close,1,1,5584.0,filled,20210720 20:30:00,8,strategy_20211112] 
    2021-11-12 18:47:22.247248 strategy_20211112(bkt999,): handle_trade data:[bkt999,8,RB2111.SHF,short,close,1,5599.0,8,20210721 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.249779 strategy_20211112(bkt999,): handle_order data:[bkt999,9,RB2109.SHF,long,open,1,1,5383.0,filled,20210720 20:30:00,9,strategy_20211112] 
    2021-11-12 18:47:22.250350 strategy_20211112(bkt999,): handle_trade data:[bkt999,9,RB2109.SHF,long,open,1,5339.0,9,20210721 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.252933 strategy_20211112(bkt999,): handle_order data:[bkt999,10,RB2111.SHF,short,open,1,1,5584.0,filled,20210720 20:30:00,10,strategy_20211112] 
    2021-11-12 18:47:22.254457 strategy_20211112(bkt999,): handle_trade data:[bkt999,10,RB2111.SHF,short,open,1,5599.0,10,20210721 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.272687 strategy_20211112(bkt999,): 2021-07-22 平多 for RB2109.SHF  最新价=5433.0 下单函数返回 OK 
    2021-11-12 18:47:22.274103 strategy_20211112(bkt999,): 2021-07-22 平空 for RB2111.SHF  最新价=5636.0 下单函数返回 OK 
    2021-11-12 18:47:22.275182 strategy_20211112(bkt999,): 2021-07-22 开多 for RB2109.SHF  最新价=5433.0 下单函数返回 OK 
    2021-11-12 18:47:22.276402 strategy_20211112(bkt999,): 2021-07-22 开空 for RB2111.SHF  最新价=5636.0 下单函数返回 OK 
    2021-11-12 18:47:22.294884 strategy_20211112(bkt999,): handle_order data:[bkt999,11,RB2109.SHF,short,close,0,1,5433.0,pending,20210722 20:30:00,11,strategy_20211112] 
    2021-11-12 18:47:22.296247 strategy_20211112(bkt999,): handle_order data:[bkt999,12,RB2111.SHF,long,close,0,1,5636.0,pending,20210722 20:30:00,12,strategy_20211112] 
    2021-11-12 18:47:22.297361 strategy_20211112(bkt999,): handle_order data:[bkt999,13,RB2109.SHF,long,open,0,1,5433.0,pending,20210722 20:30:00,13,strategy_20211112] 
    2021-11-12 18:47:22.298075 strategy_20211112(bkt999,): handle_order data:[bkt999,14,RB2111.SHF,short,open,0,1,5636.0,pending,20210722 20:30:00,14,strategy_20211112] 
    2021-11-12 18:47:22.302420 strategy_20211112(bkt999,): handle_order data:[bkt999,11,RB2109.SHF,short,close,1,1,5433.0,filled,20210722 20:30:00,11,strategy_20211112] 
    2021-11-12 18:47:22.302938 strategy_20211112(bkt999,): handle_trade data:[bkt999,11,RB2109.SHF,short,close,1,5442.0,11,20210723 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.307255 strategy_20211112(bkt999,): handle_order data:[bkt999,12,RB2111.SHF,long,close,1,1,5636.0,filled,20210722 20:30:00,12,strategy_20211112] 
    2021-11-12 18:47:22.307833 strategy_20211112(bkt999,): handle_trade data:[bkt999,12,RB2111.SHF,long,close,1,5650.0,12,20210723 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.312028 strategy_20211112(bkt999,): handle_order data:[bkt999,13,RB2109.SHF,long,open,1,1,5433.0,filled,20210722 20:30:00,13,strategy_20211112] 
    2021-11-12 18:47:22.312674 strategy_20211112(bkt999,): handle_trade data:[bkt999,13,RB2109.SHF,long,open,1,5442.0,13,20210723 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.316873 strategy_20211112(bkt999,): handle_order data:[bkt999,14,RB2111.SHF,short,open,1,1,5636.0,filled,20210722 20:30:00,14,strategy_20211112] 
    2021-11-12 18:47:22.317522 strategy_20211112(bkt999,): handle_trade data:[bkt999,14,RB2111.SHF,short,open,1,5650.0,14,20210723 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.563519 strategy_20211112(bkt999,): 2021-08-11 平多 for RB2109.SHF  最新价=5363.0 下单函数返回 OK 
    2021-11-12 18:47:22.565434 strategy_20211112(bkt999,): 2021-08-11 平空 for RB2111.SHF  最新价=5586.0 下单函数返回 OK 
    2021-11-12 18:47:22.566686 strategy_20211112(bkt999,): 2021-08-11 开多 for RB2109.SHF  最新价=5363.0 下单函数返回 OK 
    2021-11-12 18:47:22.567880 strategy_20211112(bkt999,): 2021-08-11 开空 for RB2111.SHF  最新价=5586.0 下单函数返回 OK 
    2021-11-12 18:47:22.584626 strategy_20211112(bkt999,): handle_order data:[bkt999,15,RB2109.SHF,short,close,0,1,5363.0,pending,20210811 20:30:00,15,strategy_20211112] 
    2021-11-12 18:47:22.585337 strategy_20211112(bkt999,): handle_order data:[bkt999,16,RB2111.SHF,long,close,0,1,5586.0,pending,20210811 20:30:00,16,strategy_20211112] 
    2021-11-12 18:47:22.585965 strategy_20211112(bkt999,): handle_order data:[bkt999,17,RB2109.SHF,long,open,0,1,5363.0,pending,20210811 20:30:00,17,strategy_20211112] 
    2021-11-12 18:47:22.586527 strategy_20211112(bkt999,): handle_order data:[bkt999,18,RB2111.SHF,short,open,0,1,5586.0,pending,20210811 20:30:00,18,strategy_20211112] 
    2021-11-12 18:47:22.591846 strategy_20211112(bkt999,): handle_order data:[bkt999,15,RB2109.SHF,short,close,1,1,5363.0,filled,20210811 20:30:00,15,strategy_20211112] 
    2021-11-12 18:47:22.592856 strategy_20211112(bkt999,): handle_trade data:[bkt999,15,RB2109.SHF,short,close,1,5450.0,15,20210812 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.596311 strategy_20211112(bkt999,): handle_order data:[bkt999,16,RB2111.SHF,long,close,1,1,5586.0,filled,20210811 20:30:00,16,strategy_20211112] 
    2021-11-12 18:47:22.597348 strategy_20211112(bkt999,): handle_trade data:[bkt999,16,RB2111.SHF,long,close,1,5561.0,16,20210812 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.600712 strategy_20211112(bkt999,): handle_order data:[bkt999,17,RB2109.SHF,long,open,1,1,5363.0,filled,20210811 20:30:00,17,strategy_20211112] 
    2021-11-12 18:47:22.601832 strategy_20211112(bkt999,): handle_trade data:[bkt999,17,RB2109.SHF,long,open,1,5450.0,17,20210812 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.605389 strategy_20211112(bkt999,): handle_order data:[bkt999,18,RB2111.SHF,short,open,1,1,5586.0,filled,20210811 20:30:00,18,strategy_20211112] 
    2021-11-12 18:47:22.606697 strategy_20211112(bkt999,): handle_trade data:[bkt999,18,RB2111.SHF,short,open,1,5561.0,18,20210812 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.729584 strategy_20211112(bkt999,): 2021-08-24 平多 for RB2109.SHF  最新价=5143.0 下单函数返回 OK 
    2021-11-12 18:47:22.730832 strategy_20211112(bkt999,): 2021-08-24 平空 for RB2111.SHF  最新价=5392.0 下单函数返回 OK 
    2021-11-12 18:47:22.731658 strategy_20211112(bkt999,): 2021-08-24 开多 for RB2109.SHF  最新价=5143.0 下单函数返回 OK 
    2021-11-12 18:47:22.733009 strategy_20211112(bkt999,): 2021-08-24 开空 for RB2111.SHF  最新价=5392.0 下单函数返回 OK 
    2021-11-12 18:47:22.747478 strategy_20211112(bkt999,): handle_order data:[bkt999,19,RB2109.SHF,short,close,0,1,5143.0,pending,20210824 20:30:00,19,strategy_20211112] 
    2021-11-12 18:47:22.747940 strategy_20211112(bkt999,): handle_order data:[bkt999,20,RB2111.SHF,long,close,0,1,5392.0,pending,20210824 20:30:00,20,strategy_20211112] 
    2021-11-12 18:47:22.748321 strategy_20211112(bkt999,): handle_order data:[bkt999,21,RB2109.SHF,long,open,0,1,5143.0,pending,20210824 20:30:00,21,strategy_20211112] 
    2021-11-12 18:47:22.748690 strategy_20211112(bkt999,): handle_order data:[bkt999,22,RB2111.SHF,short,open,0,1,5392.0,pending,20210824 20:30:00,22,strategy_20211112] 
    2021-11-12 18:47:22.751179 strategy_20211112(bkt999,): handle_order data:[bkt999,19,RB2109.SHF,short,close,1,1,5143.0,filled,20210824 20:30:00,19,strategy_20211112] 
    2021-11-12 18:47:22.751625 strategy_20211112(bkt999,): handle_trade data:[bkt999,19,RB2109.SHF,short,close,1,5173.0,19,20210825 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.754640 strategy_20211112(bkt999,): handle_order data:[bkt999,20,RB2111.SHF,long,close,1,1,5392.0,filled,20210824 20:30:00,20,strategy_20211112] 
    2021-11-12 18:47:22.755095 strategy_20211112(bkt999,): handle_trade data:[bkt999,20,RB2111.SHF,long,close,1,5401.0,20,20210825 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.757975 strategy_20211112(bkt999,): handle_order data:[bkt999,21,RB2109.SHF,long,open,1,1,5143.0,filled,20210824 20:30:00,21,strategy_20211112] 
    2021-11-12 18:47:22.758540 strategy_20211112(bkt999,): handle_trade data:[bkt999,21,RB2109.SHF,long,open,1,5173.0,21,20210825 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.761343 strategy_20211112(bkt999,): handle_order data:[bkt999,22,RB2111.SHF,short,open,1,1,5392.0,filled,20210824 20:30:00,22,strategy_20211112] 
    2021-11-12 18:47:22.761811 strategy_20211112(bkt999,): handle_trade data:[bkt999,22,RB2111.SHF,short,open,1,5401.0,22,20210825 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.790072 strategy_20211112(bkt999,): 2021-08-27 平多 for RB2109.SHF  最新价=5108.0 下单函数返回 OK 
    2021-11-12 18:47:22.792978 strategy_20211112(bkt999,): 2021-08-27 平空 for RB2111.SHF  最新价=5314.0 下单函数返回 OK 
    2021-11-12 18:47:22.793860 strategy_20211112(bkt999,): 2021-08-27 开多 for RB2109.SHF  最新价=5108.0 下单函数返回 OK 
    2021-11-12 18:47:22.794634 strategy_20211112(bkt999,): 2021-08-27 开空 for RB2111.SHF  最新价=5314.0 下单函数返回 OK 
    2021-11-12 18:47:22.810937 strategy_20211112(bkt999,): handle_order data:[bkt999,23,RB2109.SHF,short,close,0,1,5108.0,pending,20210827 20:30:00,23,strategy_20211112] 
    2021-11-12 18:47:22.811618 strategy_20211112(bkt999,): handle_order data:[bkt999,24,RB2111.SHF,long,close,0,1,5314.0,pending,20210827 20:30:00,24,strategy_20211112] 
    2021-11-12 18:47:22.812210 strategy_20211112(bkt999,): handle_order data:[bkt999,25,RB2109.SHF,long,open,0,1,5108.0,pending,20210827 20:30:00,25,strategy_20211112] 
    2021-11-12 18:47:22.812774 strategy_20211112(bkt999,): handle_order data:[bkt999,26,RB2111.SHF,short,open,0,1,5314.0,pending,20210827 20:30:00,26,strategy_20211112] 
    2021-11-12 18:47:22.816520 strategy_20211112(bkt999,): handle_order data:[bkt999,23,RB2109.SHF,short,close,1,1,5108.0,filled,20210827 20:30:00,23,strategy_20211112] 
    2021-11-12 18:47:22.817000 strategy_20211112(bkt999,): handle_trade data:[bkt999,23,RB2109.SHF,short,close,1,5053.0,23,20210830 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.820125 strategy_20211112(bkt999,): handle_order data:[bkt999,24,RB2111.SHF,long,close,1,1,5314.0,filled,20210827 20:30:00,24,strategy_20211112] 
    2021-11-12 18:47:22.820695 strategy_20211112(bkt999,): handle_trade data:[bkt999,24,RB2111.SHF,long,close,1,5344.0,24,20210830 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.825168 strategy_20211112(bkt999,): handle_order data:[bkt999,25,RB2109.SHF,long,open,1,1,5108.0,filled,20210827 20:30:00,25,strategy_20211112] 
    2021-11-12 18:47:22.825825 strategy_20211112(bkt999,): handle_trade data:[bkt999,25,RB2109.SHF,long,open,1,5053.0,25,20210830 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.830736 strategy_20211112(bkt999,): handle_order data:[bkt999,26,RB2111.SHF,short,open,1,1,5314.0,filled,20210827 20:30:00,26,strategy_20211112] 
    2021-11-12 18:47:22.831909 strategy_20211112(bkt999,): handle_trade data:[bkt999,26,RB2111.SHF,short,open,1,5344.0,26,20210830 15:00:00.000000,strategy_20211112] 
    2021-11-12 18:47:22.857491 run_backtest() finished! time cost 1.986s! 
    
    • 收益率3.5%
    • 年化收益率8.77%
    • 基准收益率-5.82%
    • 阿尔法0.05
    • 贝塔-0.03
    • 夏普比率1.17
    • 胜率0.27
    • 盈亏比1.18
    • 收益波动率4.78%
    • 最大回撤2.0%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-2b7dbb50423f4b35b3463fffc397ae90"}/bigcharts-data-end