克隆策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-50:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-57:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-50:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-102:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-57:input_data","from_node_id":"-50:data"},{"to_node_id":"-689:input_data","from_node_id":"-57:data"},{"to_node_id":"-102:options_data","from_node_id":"-689:data"}],"nodes":[{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nbuy_condition=where(mean(close_0,5)>mean(close_0,10),1,0)\nsell_condition=where(mean(close_0,5)<mean(close_0,10),1,0)","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"cacheable":false,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-05-01","type":"Literal","bound_global_parameter":"交易日期"},{"name":"end_date","value":"2021-06-01","type":"Literal","bound_global_parameter":"交易日期"},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"600519.SHA\n600333.SHA","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"cacheable":true,"seq_num":2,"comment":"预测数据,用于回测和模拟","comment_collapsed":false},{"node_id":"-50","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"60","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-50"},{"name":"features","node_id":"-50"}],"output_ports":[{"name":"data","node_id":"-50"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-57","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-57"},{"name":"features","node_id":"-57"}],"output_ports":[{"name":"data","node_id":"-57"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-102","module_id":"BigQuantSpace.trade.trade-v4","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"initialize","value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 获取今日的日期\n today = data.current_dt.strftime('%Y-%m-%d') \n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items()}\n\n # 记录用于买入股票的可用现金,因为是早盘卖股票,需要记录卖出的股票市值并在买入下单前更新可用现金;\n # 如果是早盘买尾盘卖,则卖出时不需更新可用现金,因为尾盘卖出股票所得现金无法使用\n cash_for_buy = context.portfolio.cash \n \n try:\n buy_stock = context.daily_stock_buy[today] # 当日符合买入条件的股票\n except:\n buy_stock=[] # 如果没有符合条件的股票,就设置为空\n \n try:\n sell_stock = context.daily_stock_sell[today] # 当日符合卖出条件的股票\n except:\n sell_stock=[] # 如果没有符合条件的股票,就设置为空\n \n # 需要卖出的股票:已有持仓中符合卖出条件的股票\n stock_to_sell = [ i for i in stock_hold_now if i in sell_stock ]\n # 需要买入的股票:没有持仓且符合买入条件的股票\n stock_to_buy = [ i for i in buy_stock if i not in stock_hold_now ] \n # 需要调仓的股票:已有持仓且不符合卖出条件的股票\n stock_to_adjust=[ i for i in stock_hold_now if i not in sell_stock ]\n \n # 如果有卖出信号\n if len(stock_to_sell)>0:\n for instrument in stock_to_sell:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n cur_position = context.portfolio.positions[sid].amount # 持仓\n if cur_position > 0 and data.can_trade(sid):\n context.order_target_percent(sid, 0) # 全部卖出 \n # 因为设置的是早盘卖出早盘买入,需要根据卖出的股票更新可用现金;如果设置尾盘卖出早盘买入,则不需更新可用现金(可以删除下面的语句)\n cash_for_buy += stock_hold_now[instrument]\n \n # 如果有买入信号/有持仓\n if len(stock_to_buy)+len(stock_to_adjust)>0:\n weight = 1/(len(stock_to_buy)+len(stock_to_adjust)) # 每只股票的比重为等资金比例持有\n for instrument in stock_to_buy+stock_to_adjust:\n sid = context.symbol(instrument) # 将标的转化为equity格式\n if data.can_trade(sid):\n context.order_target_value(sid, weight*cash_for_buy) # 买入","type":"Literal","bound_global_parameter":null},{"name":"prepare","value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n # 加载预测数据\n df = context.options['data'].read_df()\n\n # 函数:求满足开仓条件的股票列表\n def open_pos_con(df):\n return list(df[df['buy_condition']>0].instrument)\n\n # 函数:求满足平仓条件的股票列表\n def close_pos_con(df):\n return list(df[df['sell_condition']>0].instrument)\n\n # 每日买入股票的数据框\n context.daily_stock_buy= df.groupby('date').apply(open_pos_con)\n # 每日卖出股票的数据框\n context.daily_stock_sell= df.groupby('date').apply(close_pos_con)","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"","type":"Literal","bound_global_parameter":null},{"name":"volume_limit","value":0.025,"type":"Literal","bound_global_parameter":null},{"name":"order_price_field_buy","value":"open","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_sell","value":"open","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":1000000,"type":"Literal","bound_global_parameter":null},{"name":"auto_cancel_non_tradable_orders","value":"True","type":"Literal","bound_global_parameter":null},{"name":"data_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":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-102"},{"name":"options_data","node_id":"-102"},{"name":"history_ds","node_id":"-102"},{"name":"benchmark_ds","node_id":"-102"},{"name":"trading_calendar","node_id":"-102"}],"output_ports":[{"name":"raw_perf","node_id":"-102"}],"cacheable":false,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-689","module_id":"BigQuantSpace.dropnan.dropnan-v2","parameters":[],"input_ports":[{"name":"input_data","node_id":"-689"},{"name":"features","node_id":"-689"}],"output_ports":[{"name":"data","node_id":"-689"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-3055","module_id":"BigQuantSpace.hyper_run.hyper_run-v1","parameters":[{"name":"run","value":"def bigquant_run(bq_graph, inputs):\n\n parameters_list = []\n \n # 在这里设置需要调优的参数备选\n for p in [[10,20],[5,20],[5,10]]:\n paras = \"\"\"buy_condition=where(mean(close_0,%s)>mean(close_0,%s),1,0)\n sell_condition=where(mean(close_0,%s)<mean(close_0,%s),1,0)\"\"\"%(p[0],p[1],p[0],p[1])\n parameters = {'m1.features':paras}\n parameters_list.append({'parameters': parameters})\n \n# print(\"parameters_list=\\n\",parameters_list)\n def run(parameters):\n try:\n print(parameters)\n return g.run(parameters)\n except Exception as e:\n print('ERROR --------', e)\n return None\n \n results = T.parallel_map(run, parameters_list, max_workers=3, remote_run=True, silent=True)\n\n return results\n","type":"Literal","bound_global_parameter":null},{"name":"run_now","value":"True","type":"Literal","bound_global_parameter":null},{"name":"bq_graph","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"bq_graph_port","node_id":"-3055"},{"name":"input_1","node_id":"-3055"},{"name":"input_2","node_id":"-3055"},{"name":"input_3","node_id":"-3055"}],"output_ports":[{"name":"result","node_id":"-3055"}],"cacheable":false,"seq_num":6,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='1232,40,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='879,25,200,200'/><node_position Node='-50' Position='1078,234,200,200'/><node_position Node='-57' Position='1076,327,200,200'/><node_position Node='-102' Position='1047,531,200,200'/><node_position Node='-689' Position='1078,418,200,200'/><node_position Node='-3055' Position='577.3263549804688,238.53646850585938,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [52]:
    # 本代码由可视化策略环境自动生成 2021年8月19日 09:17
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m3_initialize_bigquant_run(context):
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m3_handle_data_bigquant_run(context, data):
        # 获取今日的日期
        today = data.current_dt.strftime('%Y-%m-%d')  
        # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
        stock_hold_now = {e.symbol: p.amount * p.last_sale_price
                     for e, p in context.perf_tracker.position_tracker.positions.items()}
    
        # 记录用于买入股票的可用现金,因为是早盘卖股票,需要记录卖出的股票市值并在买入下单前更新可用现金;
        # 如果是早盘买尾盘卖,则卖出时不需更新可用现金,因为尾盘卖出股票所得现金无法使用
        cash_for_buy = context.portfolio.cash    
        
        try:
            buy_stock = context.daily_stock_buy[today]  # 当日符合买入条件的股票
        except:
            buy_stock=[]  # 如果没有符合条件的股票,就设置为空
        
        try:
            sell_stock = context.daily_stock_sell[today]  # 当日符合卖出条件的股票
        except:
            sell_stock=[] # 如果没有符合条件的股票,就设置为空
        
        # 需要卖出的股票:已有持仓中符合卖出条件的股票
        stock_to_sell = [ i for i in stock_hold_now if i in sell_stock ]
        # 需要买入的股票:没有持仓且符合买入条件的股票
        stock_to_buy = [ i for i in buy_stock if i not in stock_hold_now ]  
        # 需要调仓的股票:已有持仓且不符合卖出条件的股票
        stock_to_adjust=[ i for i in stock_hold_now if i not in sell_stock ]
        
        # 如果有卖出信号
        if len(stock_to_sell)>0:
            for instrument in stock_to_sell:
                sid = context.symbol(instrument) # 将标的转化为equity格式
                cur_position = context.portfolio.positions[sid].amount # 持仓
                if cur_position > 0 and data.can_trade(sid):
                    context.order_target_percent(sid, 0) # 全部卖出 
                    # 因为设置的是早盘卖出早盘买入,需要根据卖出的股票更新可用现金;如果设置尾盘卖出早盘买入,则不需更新可用现金(可以删除下面的语句)
                    cash_for_buy += stock_hold_now[instrument]
        
        # 如果有买入信号/有持仓
        if len(stock_to_buy)+len(stock_to_adjust)>0:
            weight = 1/(len(stock_to_buy)+len(stock_to_adjust)) # 每只股票的比重为等资金比例持有
            for instrument in stock_to_buy+stock_to_adjust:
                sid = context.symbol(instrument) # 将标的转化为equity格式
                if  data.can_trade(sid):
                    context.order_target_value(sid, weight*cash_for_buy) # 买入
    # 回测引擎:准备数据,只执行一次
    def m3_prepare_bigquant_run(context):
        # 加载预测数据
        df = context.options['data'].read_df()
    
        # 函数:求满足开仓条件的股票列表
        def open_pos_con(df):
            return list(df[df['buy_condition']>0].instrument)
    
        # 函数:求满足平仓条件的股票列表
        def close_pos_con(df):
            return list(df[df['sell_condition']>0].instrument)
    
        # 每日买入股票的数据框
        context.daily_stock_buy= df.groupby('date').apply(open_pos_con)
        # 每日卖出股票的数据框
        context.daily_stock_sell= df.groupby('date').apply(close_pos_con)
    
    g = T.Graph({
    
        'm1': 'M.input_features.v1',
        'm1.features': """# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    buy_condition=where(mean(close_0,5)>mean(close_0,10),1,0)
    sell_condition=where(mean(close_0,5)<mean(close_0,10),1,0)""",
        'm1.m_cached': False,
    
        'm2': 'M.instruments.v2',
        'm2.start_date': T.live_run_param('trading_date', '2021-05-01'),
        'm2.end_date': T.live_run_param('trading_date', '2021-06-01'),
        'm2.market': 'CN_STOCK_A',
        'm2.instrument_list': """600519.SHA
    600333.SHA""",
        'm2.max_count': 0,
    
        'm7': 'M.general_feature_extractor.v7',
        'm7.instruments': T.Graph.OutputPort('m2.data'),
        'm7.features': T.Graph.OutputPort('m1.data'),
        'm7.start_date': '',
        'm7.end_date': '',
        'm7.before_start_days': 60,
    
        'm8': 'M.derived_feature_extractor.v3',
        'm8.input_data': T.Graph.OutputPort('m7.data'),
        'm8.features': T.Graph.OutputPort('m1.data'),
        'm8.date_col': 'date',
        'm8.instrument_col': 'instrument',
        'm8.drop_na': False,
        'm8.remove_extra_columns': False,
    
        'm4': 'M.dropnan.v2',
        'm4.input_data': T.Graph.OutputPort('m8.data'),
    
        'm3': 'M.trade.v4',
        'm3.instruments': T.Graph.OutputPort('m2.data'),
        'm3.options_data': T.Graph.OutputPort('m4.data'),
        'm3.start_date': '',
        'm3.end_date': '',
        'm3.initialize': m3_initialize_bigquant_run,
        'm3.handle_data': m3_handle_data_bigquant_run,
        'm3.prepare': m3_prepare_bigquant_run,
        'm3.volume_limit': 0.025,
        'm3.order_price_field_buy': 'open',
        'm3.order_price_field_sell': 'open',
        'm3.capital_base': 1000000,
        'm3.auto_cancel_non_tradable_orders': True,
        'm3.data_frequency': 'daily',
        'm3.price_type': '后复权',
        'm3.product_type': '股票',
        'm3.plot_charts': True,
        'm3.backtest_only': False,
        'm3.benchmark': '',
    })
    
    # g.run({})
    
    
    def m6_run_bigquant_run(bq_graph, inputs):
    
        parameters_list = []
        
        # 在这里设置需要调优的参数备选
        for p in [[10,20],[5,20],[5,10]]:
            paras = """buy_condition=where(mean(close_0,%s)>mean(close_0,%s),1,0)
            sell_condition=where(mean(close_0,%s)<mean(close_0,%s),1,0)"""%(p[0],p[1],p[0],p[1])
            parameters = {'m1.features':paras}
            parameters_list.append({'parameters': parameters})
            
    #     print("parameters_list=\n",parameters_list)
        def run(parameters):
            try:
                print(parameters)
                return g.run(parameters)
            except Exception as e:
                print('ERROR --------', e)
                return None
            
        results = T.parallel_map(run, parameters_list, max_workers=3, remote_run=True, silent=True)
    
        return results
    
    
    m6 = M.hyper_run.v1(
        run=m6_run_bigquant_run,
        run_now=True,
        bq_graph=g
    )
    
    In [58]:
    m6.result[1]["m3"].read_raw_perf().columns
    
    Out[58]:
    Index(['ending_value', 'ending_exposure', 'capital_used', 'starting_value',
           'starting_exposure', 'starting_cash', 'ending_cash', 'portfolio_value',
           'pnl', 'returns', 'period_open', 'period_close', 'gross_leverage',
           'net_leverage', 'short_exposure', 'long_exposure', 'short_value',
           'long_value', 'longs_count', 'shorts_count', 'need_settle', 'positions',
           'transactions', 'orders', 'LOG', 'TRA_FAC', 'POS_FAC', 'trading_days',
           'benchmark_volatility', 'algo_volatility', 'treasury_period_return',
           'algorithm_period_return', 'benchmark_period_return', 'beta', 'alpha',
           'sharpe', 'sortino', 'information', 'excess_return', 'max_drawdown',
           'max_leverage', 'period_label', 'trade_times', 'win_percent',
           'pnl_ratio'],
          dtype='object')
    In [61]:
    m6.result[1]["m3"].read_raw_perf()[['algo_volatility', 'max_drawdown', 'max_leverage', 'period_label', 'trade_times', 'win_percent','pnl_ratio']]
    
    Out[61]:
    algo_volatility max_drawdown max_leverage period_label trade_times win_percent pnl_ratio
    2021-05-06 15:00:00+00:00 0.000000 0.000000 0.000000 2021-05 0 0.000000 0.000000
    2021-05-07 15:00:00+00:00 0.000000 0.000000 0.000000 2021-05 0 0.000000 0.000000
    2021-05-10 15:00:00+00:00 0.000000 0.000000 0.000000 2021-05 0 0.000000 0.000000
    2021-05-11 15:00:00+00:00 0.000000 0.000000 0.000000 2021-05 0 0.000000 0.000000
    2021-05-12 15:00:00+00:00 0.000000 0.000000 0.000000 2021-05 0 0.000000 0.000000
    2021-05-13 15:00:00+00:00 0.000000 0.000000 0.000000 2021-05 0 0.000000 0.000000
    2021-05-14 15:00:00+00:00 0.047844 0.000000 1.000005 2021-05 0 1.000000 0.000000
    2021-05-17 15:00:00+00:00 0.050979 -0.003357 1.000005 2021-05 1 1.000000 0.000000
    2021-05-18 15:00:00+00:00 0.062021 -0.003357 1.000005 2021-05 1 1.000000 0.000000
    2021-05-19 15:00:00+00:00 0.073736 -0.007539 1.000005 2021-05 2 1.000000 0.000000
    2021-05-20 15:00:00+00:00 0.092938 -0.019715 1.000005 2021-05 2 0.000000 0.000000
    2021-05-21 15:00:00+00:00 0.089706 -0.023336 1.000005 2021-05 4 0.500000 -1.125212
    2021-05-24 15:00:00+00:00 0.087362 -0.023336 1.000005 2021-05 5 0.400000 -1.229555
    2021-05-25 15:00:00+00:00 0.106478 -0.023336 1.000005 2021-05 6 0.500000 -0.822564
    2021-05-26 15:00:00+00:00 0.103900 -0.023336 1.000005 2021-05 7 0.571429 -0.671013
    2021-05-27 15:00:00+00:00 0.100398 -0.023336 1.000005 2021-05 7 0.571429 -0.671013
    2021-05-28 15:00:00+00:00 0.100437 -0.023336 1.000005 2021-05 8 0.625000 -0.548691
    2021-05-31 15:00:00+00:00 0.097439 -0.023336 1.000005 2021-05 8 0.625000 -0.548691
    2021-06-01 15:00:00+00:00 0.095021 -0.023336 1.000005 2021-06 9 0.555556 -0.717218
    In [55]:
    m6.result[0]["m3"].read_raw_perf()
    
    Out[55]:
    ending_value ending_exposure capital_used starting_value starting_exposure starting_cash ending_cash portfolio_value pnl returns ... sharpe sortino information excess_return max_drawdown max_leverage period_label trade_times win_percent pnl_ratio
    2021-05-06 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 1000000.000000 1000000.000000 1000000.000000 0.000000 0.000000 ... 0.000000 0.000000 0.000000 0 0.000000 0.000000 2021-05 0 0.000000 0.000000
    2021-05-07 15:00:00+00:00 968156.387760 968156.387760 -999998.990914 0.000000 0.000000 1000000.000000 1.009086 968157.396847 -31842.603153 -0.031843 ... -11.307672 -11.224972 -0.154622 0 -0.031843 0.999999 2021-05 0 0.000000 0.000000
    2021-05-10 15:00:00+00:00 0.000000 0.000000 965373.524346 968156.387760 968156.387760 1.009086 965374.533432 965374.533432 -2782.863415 -0.002874 ... -10.535624 -9.952014 -0.191522 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-11 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 965374.533432 965374.533432 965374.533432 0.000000 0.000000 ... -9.008176 -8.618697 -0.294167 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-12 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 965374.533432 965374.533432 965374.533432 0.000000 0.000000 ... -8.020623 -7.708797 -0.348668 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-13 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 965374.533432 965374.533432 965374.533432 0.000000 0.000000 ... -7.311931 -7.037136 -0.132787 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-14 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 965374.533432 965374.533432 965374.533432 0.000000 0.000000 ... -6.771024 -6.515122 -0.348959 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-17 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 965374.533432 965374.533432 965374.533432 0.000000 0.000000 ... -6.340700 -6.094339 -0.458707 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-18 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 965374.533432 965374.533432 965374.533432 0.000000 0.000000 ... -5.987919 -5.745798 -0.435702 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-19 15:00:00+00:00 0.000000 0.000000 0.000000 0.000000 0.000000 965374.533432 965374.533432 965374.533432 0.000000 0.000000 ... -5.692029 -5.450942 -0.380469 0 -0.034625 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-20 15:00:00+00:00 943251.364763 943251.364763 -959638.650841 0.000000 0.000000 965374.533432 5735.882591 948987.247354 -16387.286078 -0.016975 ... -7.400565 -6.834888 -0.485546 0 -0.051013 0.999999 2021-05 1 0.000000 -0.000000
    2021-05-21 15:00:00+00:00 5992.713142 5992.713142 938291.274555 943251.364763 943251.364763 5735.882591 944027.157147 950019.870289 1032.622935 0.001088 ... -6.886259 -6.406156 -0.355043 0 -0.051013 0.999999 2021-05 2 0.000000 -0.000000
    2021-05-24 15:00:00+00:00 936320.786781 936320.786781 -936405.182352 5992.713142 5992.713142 944027.157147 7621.974794 943942.761575 -6077.108713 -0.006397 ... -7.455840 -6.827089 -0.406074 0 -0.056057 0.999999 2021-05 2 0.000000 -0.000000
    2021-05-25 15:00:00+00:00 3810.987397 3810.987397 925541.112761 936320.786781 936320.786781 7621.974794 933163.087555 936974.074952 -6968.686623 -0.007383 ... -8.098804 -7.285335 -0.497567 0 -0.063026 0.999999 2021-05 3 0.000000 -0.000000
    2021-05-26 15:00:00+00:00 941464.881198 941464.881198 -930593.641485 3810.987397 3810.987397 933163.087555 2569.446070 944034.327268 7060.252316 0.007535 ... -6.568513 -6.214567 -0.433774 0 -0.063026 0.999999 2021-05 3 0.000000 -0.000000
    2021-05-27 15:00:00+00:00 2576.031954 2576.031954 935772.111775 941464.881198 941464.881198 2569.446070 938341.557845 940917.589799 -3116.737469 -0.003302 ... -6.745339 -6.342145 -0.450015 0 -0.063026 0.999999 2021-05 5 0.200000 -0.027735
    2021-05-28 15:00:00+00:00 927483.820433 927483.820433 -936169.910260 2576.031954 2576.031954 938341.557845 2171.647585 929655.468018 -11262.121781 -0.011969 ... -7.642664 -7.030229 -0.474440 0 -0.070345 0.999999 2021-05 5 0.200000 -0.027735
    2021-05-31 15:00:00+00:00 2172.619329 2172.619329 919164.982073 927483.820433 927483.820433 2171.647585 921336.629658 923509.248987 -6146.219031 -0.006611 ... -8.099358 -7.356127 -0.497210 0 -0.076491 0.999999 2021-05 7 0.142857 -0.030030
    2021-06-01 15:00:00+00:00 926103.270107 926103.270107 -919314.285662 2172.619329 2172.619329 921336.629658 2022.343996 928125.614103 4616.365116 0.004999 ... -7.194975 -6.705331 -0.465295 0 -0.076491 0.999999 2021-06 7 0.142857 -0.030030

    19 rows × 45 columns

    In [56]:
    import pandas as pd
    target = ["sharpe","max_drawdown","win_percent","pnl_ratio"]
    results = pd.DataFrame()
    for i in range(len(m6.result)):
        r = m6.result[i]["m3"].read_raw_perf()[target].tail(1).reset_index(drop=True)
        r["para_id"] = i
        results = results.append(r)
    results = results.sort_values("sharpe",ascending = False).reset_index(drop = True)
    results
    
    Out[56]:
    sharpe max_drawdown win_percent pnl_ratio para_id
    0 1.015303 -0.023336 0.555556 -0.717218 1
    1 -5.145532 -0.081329 0.300000 -0.113349 2
    2 -7.194975 -0.076491 0.142857 -0.030030 0
    In [63]:
    m6.result[1]["m3"].display()
    
    • 收益率0.92%
    • 年化收益率12.95%
    • 基准收益率4.26%
    • 阿尔法-0.06
    • 贝塔0.28
    • 夏普比率1.02
    • 胜率0.56
    • 盈亏比0.72
    • 收益波动率9.5%
    • 信息比率-0.18
    • 最大回撤2.33%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-cbaf08d7f01d4ababa7cd0aad3439c3c"}/bigcharts-data-end
    In [ ]: