复制链接
克隆策略

    {"description":"实验创建于2022/4/8","graph":{"edges":[{"to_node_id":"-1290:features","from_node_id":"-1278:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:features","from_node_id":"-1278:data"},{"to_node_id":"-2427:features","from_node_id":"-1278:data"},{"to_node_id":"-1290:input_data","from_node_id":"-1283:data"},{"to_node_id":"-1079:input_data","from_node_id":"-1283:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","from_node_id":"-1290:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data1","from_node_id":"-1079:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:model"},{"to_node_id":"-3135:options_data","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43:training_ds","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"to_node_id":"-2427:input_data","from_node_id":"-2411:data"},{"to_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:data","from_node_id":"-2427:data"},{"to_node_id":"-760:input","from_node_id":"-512:data"},{"to_node_id":"-2411:instruments","from_node_id":"-760:instrument_list"},{"to_node_id":"-3135:instruments","from_node_id":"-760:instrument_list"}],"nodes":[{"node_id":"-1278","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"return_5 = close/shift(close, 5)\nreturn_10 = close/shift(close, 10)\nreturn_20 = close/shift(close, 20)\namount/mean(amount,5)\nmean(amount,5)/mean(amount,20)\nrank(amount)/rank(mean(amount,5))\nrank(mean(amount,5))/rank(mean(amount,10))\nrank(close/shift(close, 1))\nrank(close/shift(close, 5))\nrank(close/shift(close, 10)) \nrank(close/shift(close, 1))/rank(close/shift(close, 5)) \nrank(close/shift(close, 5))/rank(close/shift(close, 10))","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-1278"}],"output_ports":[{"name":"data","node_id":"-1278"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true},{"node_id":"-1283","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_CN_CONBOND","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2017-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2020-12-31","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-1283"},{"name":"features","node_id":"-1283"}],"output_ports":[{"name":"data","node_id":"-1283"}],"cacheable":false,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-1290","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":"-1290"},{"name":"features","node_id":"-1290"}],"output_ports":[{"name":"data","node_id":"-1290"}],"cacheable":true,"seq_num":13,"comment":"","comment_collapsed":true},{"node_id":"-1079","module_id":"BigQuantSpace.auto_labeler_on_datasource.auto_labeler_on_datasource-v1","parameters":[{"name":"label_expr","value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html\n# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/develop/bigexpr/usage.html>`_\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -5) / shift(open, -1)\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\nall_wbins(label, 20)\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\n","type":"Literal","bound_global_parameter":null},{"name":"drop_na_label","value":"True","type":"Literal","bound_global_parameter":null},{"name":"cast_label_int","value":"True","type":"Literal","bound_global_parameter":null},{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-1079"}],"output_ports":[{"name":"data","node_id":"-1079"}],"cacheable":true,"seq_num":14,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"how","value":"inner","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"},{"name":"data2","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"cacheable":true,"seq_num":15,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43","module_id":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v6","parameters":[{"name":"learning_algorithm","value":"排序","type":"Literal","bound_global_parameter":null},{"name":"number_of_leaves","value":"30","type":"Literal","bound_global_parameter":null},{"name":"minimum_docs_per_leaf","value":"1000","type":"Literal","bound_global_parameter":null},{"name":"number_of_trees","value":20,"type":"Literal","bound_global_parameter":null},{"name":"learning_rate","value":0.1,"type":"Literal","bound_global_parameter":null},{"name":"max_bins","value":1023,"type":"Literal","bound_global_parameter":null},{"name":"feature_fraction","value":1,"type":"Literal","bound_global_parameter":null},{"name":"data_row_fraction","value":1,"type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"ndcg_discount_base","value":1,"type":"Literal","bound_global_parameter":null},{"name":"m_lazy_run","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"training_ds","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"name":"features","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"name":"test_ds","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"name":"base_model","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"}],"output_ports":[{"name":"model","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"name":"feature_gains","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"},{"name":"m_lazy_run","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-43"}],"cacheable":true,"seq_num":16,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","module_id":"BigQuantSpace.stock_ranker_predict.stock_ranker_predict-v5","parameters":[{"name":"m_lazy_run","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"model","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"output_ports":[{"name":"predictions","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"name":"m_lazy_run","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"cacheable":true,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"cacheable":false,"seq_num":18,"comment":"","comment_collapsed":true},{"node_id":"-2411","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_CN_CONBOND","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2018-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-09-15","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-2411"},{"name":"features","node_id":"-2411"}],"output_ports":[{"name":"data","node_id":"-2411"}],"cacheable":true,"seq_num":28,"comment":"","comment_collapsed":true},{"node_id":"-2427","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":"-2427"},{"name":"features","node_id":"-2427"}],"output_ports":[{"name":"data","node_id":"-2427"}],"cacheable":true,"seq_num":30,"comment":"","comment_collapsed":true},{"node_id":"-3135","module_id":"BigQuantSpace.hftrade.hftrade-v2","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"initialize","value":"# 交易引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 加载股票指标数据,数据继承自m6模块\n context.indicator_data = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n \n # 设置数量\n context.stock_num = 5\n \n # 调仓天数,22个交易日大概就是一个月。可以理解为一个月换仓一次\n context.rebalance_days = 22\n \n # 如果策略运行中,需要将数据进行保存,可以借用extension这个对象,类型为dict\n # 比如当前运行的k线的索引,比如个股持仓天数、买入均价\n context.extension.index = 0\n context.subscribe(context.instruments)\n ","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n pass","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 bigquant_run(context, data):\n \n context.extension.index += 1\n # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月\n if context.extension.index % context.rebalance_days != 0:\n return\n \n # 当前的日期\n date = data.current_dt.strftime('%Y-%m-%d')\n cur_data = context.indicator_data[context.indicator_data['date'] == date]\n\n stock_to_buy = list(cur_data.instrument[:context.stock_num])\n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity for equity in context.portfolio.positions]\n # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有\n no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]\n # 需要卖出的股票\n stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell] \n \n # 卖出\n\n for stock in stock_to_sell:\n context.order_target_percent(stock, 0)\n \n # 如果当天没有买入的股票,就返回\n if len(stock_to_buy) == 0:\n print(date,'当天没有买入的股票')\n return\n\n # 等权重买入 \n weight = 1 / len(stock_to_buy)\n print(stock_to_buy,weight)\n # 买入\n for stock in stock_to_buy:\n context.order_target_percent(stock, weight)\n ","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, data):\n pass\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":"1000001","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":"volume_limit","value":1,"type":"Literal","bound_global_parameter":null},{"name":"order_price_field_buy","value":"close","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_sell","value":"close","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.HIX","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"disable_cache","value":"False","type":"Literal","bound_global_parameter":null},{"name":"replay_bdb","value":"False","type":"Literal","bound_global_parameter":null},{"name":"show_debug_info","value":"False","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-3135"},{"name":"options_data","node_id":"-3135"},{"name":"history_ds","node_id":"-3135"},{"name":"benchmark_ds","node_id":"-3135"}],"output_ports":[{"name":"raw_perf","node_id":"-3135"}],"cacheable":false,"seq_num":19,"comment":"","comment_collapsed":true},{"node_id":"-512","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"market_performance_CN_CONBOND","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2021-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-09-16","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-512"},{"name":"features","node_id":"-512"}],"output_ports":[{"name":"data","node_id":"-512"}],"cacheable":false,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-760","module_id":"BigQuantSpace.trade_data_generation.trade_data_generation-v1","parameters":[{"name":"category","value":"CN_STOCK","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input","node_id":"-760"}],"output_ports":[{"name":"history_data","node_id":"-760"},{"name":"instrument_list","node_id":"-760"},{"name":"calendar","node_id":"-760"}],"cacheable":false,"seq_num":2,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-1278' Position='1318,-545,200,200'/><node_position Node='-1283' Position='991,-558.0519409179688,200,200'/><node_position Node='-1290' Position='1194.9481201171875,-247,200,200'/><node_position Node='-1079' Position='861,-239,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='1097,-104,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-43' Position='1264.103759765625,107.79232788085938,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='1471,245,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='1104,0,200,200'/><node_position Node='-2411' Position='1729,-192,200,200'/><node_position Node='-2427' Position='1722,6,200,200'/><node_position Node='-3135' Position='1742,400,200,200'/><node_position Node='-512' Position='1734,-522.9480895996094,200,200'/><node_position Node='-760' Position='1727,-368,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [83]:
    # 本代码由可视化策略环境自动生成 2022年9月17日 13:52
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 交易引擎:初始化函数,只执行一次
    def m19_initialize_bigquant_run(context):
           # 加载股票指标数据,数据继承自m6模块
        context.indicator_data = context.options['data'].read_df()
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
        
        # 设置数量
        context.stock_num = 5
        
        # 调仓天数,22个交易日大概就是一个月。可以理解为一个月换仓一次
        context.rebalance_days = 22
        
        # 如果策略运行中,需要将数据进行保存,可以借用extension这个对象,类型为dict
        # 比如当前运行的k线的索引,比如个股持仓天数、买入均价
        context.extension.index = 0
        context.subscribe(context.instruments)
     
    # 交易引擎:每个单位时间开盘前调用一次。
    def m19_before_trading_start_bigquant_run(context, data):
        pass
    # 交易引擎:tick数据处理函数,每个tick执行一次
    def m19_handle_tick_bigquant_run(context, data):
        pass
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m19_handle_data_bigquant_run(context, data):
        
        context.extension.index += 1
        # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月
        if  context.extension.index % context.rebalance_days != 0:
            return
        
        # 当前的日期
        date = data.current_dt.strftime('%Y-%m-%d')
        cur_data = context.indicator_data[context.indicator_data['date'] == date]
    
        stock_to_buy = list(cur_data.instrument[:context.stock_num])
        # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
        stock_hold_now = [equity for equity in context.portfolio.positions]
        # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有
        no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]
        # 需要卖出的股票
        stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell] 
        
        # 卖出
    
        for stock in stock_to_sell:
            context.order_target_percent(stock, 0)
        
        # 如果当天没有买入的股票,就返回
        if len(stock_to_buy) == 0:
            print(date,'当天没有买入的股票')
            return
    
        # 等权重买入 
        weight =  1 / len(stock_to_buy)
        print(stock_to_buy,weight)
        # 买入
        for stock in stock_to_buy:
            context.order_target_percent(stock, weight)
     
    # 交易引擎:成交回报处理函数,每个成交发生时执行一次
    def m19_handle_trade_bigquant_run(context, data):
        pass
    
    # 交易引擎:委托回报处理函数,每个委托变化时执行一次
    def m19_handle_order_bigquant_run(context, data):
        pass
    
    # 交易引擎:盘后处理函数,每日盘后执行一次
    def m19_after_trading_bigquant_run(context, data):
        pass
    
    
    m11 = M.input_features.v1(
        features="""return_5 = close/shift(close, 5)
    return_10 = close/shift(close, 10)
    return_20 = close/shift(close, 20)
    amount/mean(amount,5)
    mean(amount,5)/mean(amount,20)
    rank(amount)/rank(mean(amount,5))
    rank(mean(amount,5))/rank(mean(amount,10))
    rank(close/shift(close, 1))
    rank(close/shift(close, 5))
    rank(close/shift(close, 10))     
    rank(close/shift(close, 1))/rank(close/shift(close, 5))    
    rank(close/shift(close, 5))/rank(close/shift(close, 10))"""
    )
    
    m12 = M.use_datasource.v1(
        datasource_id='bar1d_CN_CONBOND',
        start_date='2017-01-01',
        end_date='2020-12-31',
        m_cached=False
    )
    
    m13 = M.derived_feature_extractor.v3(
        input_data=m12.data,
        features=m11.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m14 = M.auto_labeler_on_datasource.v1(
        input_data=m12.data,
        label_expr="""# #号开始的表示注释
    # 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
    # 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html
    # 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/develop/bigexpr/usage.html>`_
    
    # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    shift(close, -5) / shift(open, -1)
    
    # 极值处理:用1%和99%分位的值做clip
    clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
    
    # 将分数映射到分类,这里使用20个分类
    all_wbins(label, 20)
    
    # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
    where(shift(high, -1) == shift(low, -1), NaN, label)
    """,
        drop_na_label=True,
        cast_label_int=True,
        date_col='date',
        instrument_col='instrument',
        user_functions={}
    )
    
    m15 = M.join.v3(
        data1=m14.data,
        data2=m13.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m18 = M.dropnan.v1(
        input_data=m15.data,
        m_cached=False
    )
    
    m16 = M.stock_ranker_train.v6(
        training_ds=m18.data,
        features=m11.data,
        learning_algorithm='排序',
        number_of_leaves=30,
        minimum_docs_per_leaf=1000,
        number_of_trees=20,
        learning_rate=0.1,
        max_bins=1023,
        feature_fraction=1,
        data_row_fraction=1,
        plot_charts=True,
        ndcg_discount_base=1,
        m_lazy_run=False
    )
    
    m1 = M.use_datasource.v1(
        datasource_id='market_performance_CN_CONBOND',
        start_date='2021-01-01',
        end_date='2022-09-16',
        m_cached=False
    )
    
    m2 = M.trade_data_generation.v1(
        input=m1.data,
        category='CN_STOCK',
        m_cached=False
    )
    
    m28 = M.use_datasource.v1(
        instruments=m2.instrument_list,
        datasource_id='bar1d_CN_CONBOND',
        start_date='2018-01-01',
        end_date='2021-09-15'
    )
    
    m30 = M.derived_feature_extractor.v3(
        input_data=m28.data,
        features=m11.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m17 = M.stock_ranker_predict.v5(
        model=m16.model,
        data=m30.data,
        m_lazy_run=False
    )
    
    m19 = M.hftrade.v2(
        instruments=m2.instrument_list,
        options_data=m17.predictions,
        start_date='',
        end_date='',
        initialize=m19_initialize_bigquant_run,
        before_trading_start=m19_before_trading_start_bigquant_run,
        handle_tick=m19_handle_tick_bigquant_run,
        handle_data=m19_handle_data_bigquant_run,
        handle_trade=m19_handle_trade_bigquant_run,
        handle_order=m19_handle_order_bigquant_run,
        after_trading=m19_after_trading_bigquant_run,
        capital_base=1000001,
        frequency='daily',
        price_type='真实价格',
        product_type='可转债',
        before_start_days='0',
        volume_limit=1,
        order_price_field_buy='close',
        order_price_field_sell='close',
        benchmark='000300.HIX',
        plot_charts=True,
        disable_cache=False,
        replay_bdb=False,
        show_debug_info=False,
        backtest_only=False
    )
    
    设置评估测试数据集,查看训练曲线
    [视频教程]StockRanker训练曲线
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-816774ca1e0a4f2f8fd867aae4944e28"}/bigcharts-data-end
    2022-09-17 13:50:34.547520 init history datas... 
    2022-09-17 13:50:34.548647 init history datas done. 
    2022-09-17 13:50:34.568683 run_backtest() capital_base:1000001, frequency:1d, product_type:conbond, date:2021-01-04 ~ 2022-09-02 
    2022-09-17 13:50:34.568981 run_backtest() running... 
    2022-09-17 13:50:34.578033 initial contracts len=0 
    2022-09-17 13:50:34.578194 backtest inited. 
    2022-09-17 13:50:34.843408 backtest transforming 1d, bars=1... 
    2022-09-17 13:50:34.844104 transform start_trading_day=2021-01-04 00:00:00, simulation period=2021-01-04 ~ 2022-09-02 
    2022-09-17 13:50:34.844140 transform source=None, before_start_days=0 
    2022-09-17 13:50:34.844168 transform replay_func=<cyfunction BacktestEngine.transform.<locals>.replay_bars_dt at 0x7f36e4b2c6c0> 
    ['128103.ZCB', '113587.HCB', '113559.HCB', '113525.HCB', '110058.HCB'] 0.2
    ['123086.ZCB', '110048.HCB', '110058.HCB', '110061.HCB', '113040.HCB'] 0.2
    ['110057.HCB', '128072.ZCB', '128070.ZCB', '128014.ZCB', '113546.HCB'] 0.2
    ['123048.ZCB', '123053.ZCB', '123091.ZCB', '113589.HCB', '123028.ZCB'] 0.2
    ['113505.HCB', '128101.ZCB', '128041.ZCB', '128118.ZCB', '128050.ZCB'] 0.2
    ['123104.ZCB', '110076.HCB', '123056.ZCB', '123114.ZCB', '128014.ZCB'] 0.2
    ['113545.HCB', '128035.ZCB', '110041.HCB', '110073.HCB', '113013.HCB'] 0.2
    ['113051.HCB', '113505.HCB', '113580.HCB', '113603.HCB', '123083.ZCB'] 0.2
    ['113570.HCB', '123078.ZCB', '123113.ZCB', '128131.ZCB', '123073.ZCB'] 0.2
    ['113566.HCB', '113597.HCB', '113609.HCB', '113624.HCB', '123011.ZCB'] 0.2
    ['113504.HCB', '123088.ZCB', '127005.ZCB', '128122.ZCB', '113606.HCB'] 0.2
    ['123011.ZCB', '113606.HCB', '127016.ZCB', '123071.ZCB', '128141.ZCB'] 0.2
    ['128132.ZCB', '113053.HCB', '113618.HCB', '123018.ZCB', '128128.ZCB'] 0.2
    ['113584.HCB', '123117.ZCB', '113519.HCB', '110059.HCB', '127043.ZCB'] 0.2
    ['113549.HCB', '123093.ZCB', '123097.ZCB', '123129.ZCB', '123132.ZCB'] 0.2
    ['113047.HCB', '123137.ZCB', '128014.ZCB', '128042.ZCB', '128109.ZCB'] 0.2
    ['113624.HCB', '113638.HCB', '123044.ZCB', '123050.ZCB', '123120.ZCB'] 0.2
    ['113608.HCB', '113530.HCB', '113596.HCB', '113624.HCB', '127062.ZCB'] 0.2
    2022-09-17 13:50:37.114012 backtest run end! 
    2022-09-17 13:50:38.216441 run_backtest() finished! time cost 3.647s! 
    
    • 收益率39.69%
    • 年化收益率22.05%
    • 基准收益率-23.62%
    • 阿尔法0.23
    • 贝塔0.09
    • 夏普比率1.09
    • 胜率0.68
    • 盈亏比4.7
    • 收益波动率17.68%
    • 信息比率0.09
    • 最大回撤9.99%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-dec83af86eeb42b4b0bf472f6f4fd8d0"}/bigcharts-data-end