复制链接
克隆策略

StockRanker多因子期货策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-209:input_1","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"to_node_id":"-145:data1","from_node_id":"-189:data"},{"to_node_id":"-189:input_data","from_node_id":"-209:data_1"},{"to_node_id":"-451:input_data","from_node_id":"-209:data_1"},{"to_node_id":"-151:input_data","from_node_id":"-145:data"},{"to_node_id":"-468:training_ds","from_node_id":"-151:data"},{"to_node_id":"-145:data2","from_node_id":"-451:data"},{"to_node_id":"-451:features","from_node_id":"-459:data"},{"to_node_id":"-468:features","from_node_id":"-459:data"},{"to_node_id":"-1086:features","from_node_id":"-459:data"},{"to_node_id":"-765:model","from_node_id":"-468:model"},{"to_node_id":"-126:options_data","from_node_id":"-765:predictions"},{"to_node_id":"-781:input_1","from_node_id":"-769:data"},{"to_node_id":"-126:instruments","from_node_id":"-769:data"},{"to_node_id":"-1086:input_data","from_node_id":"-781:data_1"},{"to_node_id":"-1398:input_data","from_node_id":"-1086:data"},{"to_node_id":"-765:data","from_node_id":"-1398:data"}],"nodes":[{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-01-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":"P0000.DCE\nY0000.DCE\nHC0000.SHF\nRB0000.SHF\nJM0000.DCE\nI0000.DCE\nA0000.DCE\nM0000.DCE\nTA0000.CZC\nC0000.DCE","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-8"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-189","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":"-189"}],"output_ports":[{"name":"data","node_id":"-189"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-209","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n instruments = input_1.read()['instruments']\n start_date = input_1.read()['start_date']\n end_date = input_1.read()['end_date']\n df = DataSource('bar1m_CN_FUTURE').read(instruments=instruments,start_date=start_date,end_date=end_date)\n df60 = BarGenerator.aggregate_df(df, \"60m\"),\n df60 = df60[0]\n\n data_1 = DataSource.write_df(df60)\n return Outputs(data_1=data_1)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-209"},{"name":"input_2","node_id":"-209"},{"name":"input_3","node_id":"-209"}],"output_ports":[{"name":"data_1","node_id":"-209"},{"name":"data_2","node_id":"-209"},{"name":"data_3","node_id":"-209"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true},{"node_id":"-145","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":"-145"},{"name":"data2","node_id":"-145"}],"output_ports":[{"name":"data","node_id":"-145"}],"cacheable":true,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-151","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"-151"}],"output_ports":[{"name":"data","node_id":"-151"}],"cacheable":true,"seq_num":19,"comment":"","comment_collapsed":true},{"node_id":"-451","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":"-451"},{"name":"features","node_id":"-451"}],"output_ports":[{"name":"data","node_id":"-451"}],"cacheable":true,"seq_num":22,"comment":"","comment_collapsed":true},{"node_id":"-459","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nclose/shift(close, 20)-1 \nvolume/mean(volume,20)\n\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-459"}],"output_ports":[{"name":"data","node_id":"-459"}],"cacheable":true,"seq_num":23,"comment":"","comment_collapsed":true},{"node_id":"-468","module_id":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v5","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":"100","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":"m_lazy_run","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"training_ds","node_id":"-468"},{"name":"features","node_id":"-468"},{"name":"test_ds","node_id":"-468"},{"name":"base_model","node_id":"-468"}],"output_ports":[{"name":"model","node_id":"-468"},{"name":"feature_gains","node_id":"-468"},{"name":"m_lazy_run","node_id":"-468"}],"cacheable":true,"seq_num":21,"comment":"","comment_collapsed":true},{"node_id":"-765","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":"-765"},{"name":"data","node_id":"-765"}],"output_ports":[{"name":"predictions","node_id":"-765"},{"name":"m_lazy_run","node_id":"-765"}],"cacheable":true,"seq_num":20,"comment":"","comment_collapsed":true},{"node_id":"-769","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-09-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-11-19","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_FUTURE","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"P0000.DCE\nY0000.DCE\nHC0000.SHF\nRB0000.SHF\nJM0000.DCE\nI0000.DCE\nA0000.DCE\nM0000.DCE\nTA0000.CZC\nC0000.DCE","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-769"}],"output_ports":[{"name":"data","node_id":"-769"}],"cacheable":true,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"-781","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n instruments = input_1.read()['instruments']\n start_date = input_1.read()['start_date']\n end_date = input_1.read()['end_date']\n df = DataSource('bar1m_CN_FUTURE').read(instruments=instruments,start_date=start_date,end_date=end_date)\n df60 = BarGenerator.aggregate_df(df, \"60m\"),\n df60 = df60[0]\n\n data_1 = DataSource.write_df(df60)\n return Outputs(data_1=data_1)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-781"},{"name":"input_2","node_id":"-781"},{"name":"input_3","node_id":"-781"}],"output_ports":[{"name":"data_1","node_id":"-781"},{"name":"data_2","node_id":"-781"},{"name":"data_3","node_id":"-781"}],"cacheable":true,"seq_num":24,"comment":"","comment_collapsed":true},{"node_id":"-1086","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":"-1086"},{"name":"features","node_id":"-1086"}],"output_ports":[{"name":"data","node_id":"-1086"}],"cacheable":true,"seq_num":25,"comment":"","comment_collapsed":true},{"node_id":"-1398","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"-1398"}],"output_ports":[{"name":"data","node_id":"-1398"}],"cacheable":true,"seq_num":26,"comment":"","comment_collapsed":true},{"node_id":"-126","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 # 加载预测数据\n context.ranker_prediction = context.options['data'].read_df()\n #设置尾盘可以下单\n context.set_enable_auto_planed_order(1)\n #用于换仓周期\n context.index = 0\n #控制打印\n context.PRINT = 0\n\n\n","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n\n","type":"Literal","bound_global_parameter":null},{"name":"handle_tick","value":"# 交易引擎:tick数据处理函数,每个tick执行一次\ndef bigquant_run(context, data):\n pass","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 交易引擎:bar数据处理函数,每个时间单位执行一次\ndef bigquant_run(context, data):\n # 获取当日指标数据\n now = data.current_dt.strftime('%Y-%m-%d %H:%M:%S')\n now_data = context.ranker_prediction[context.ranker_prediction.date==now]\n if len(now_data)==0:\n return\n context.index += 1\n #每5根K线处理一次\n if context.index % 5 !=0:\n return\n #平仓\n for symbol,position in context.portfolio.positions.items():\n if position.long.avail_qty>0:\n rv = context.sell_close(symbol, position.long.avail_qty, None,order_type=OrderType.MARKET)\n msg = \"{} {} 平多 下单函数返回 {}\".format(now,symbol,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT)\n if position.short.avail_qty>0:\n rv = context.buy_close(symbol, position.short.avail_qty, None, order_type=OrderType.MARKET)\n msg = \"{} {} 平空 下单函数返回 {}\".format(now,symbol,context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT)\n #开仓\n instruments = now_data.instrument.unique()\n rv = context.buy_open(instruments[0], 1, None, order_type=OrderType.MARKET)\n msg = \"{} {} 开多 下单函数返回 {}\".format(now,instruments[0],context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT) \n rv = context.sell_open(instruments[-1], 1, None, order_type=OrderType.MARKET)\n msg = \"{} {} 开空 下单函数返回 {}\".format(now,instruments[-1],context.get_error_msg(rv))\n context.write_log(msg, stdout=context.PRINT)","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, data):\n pass\n\n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, data):\n pass\n\n","type":"Literal","bound_global_parameter":null},{"name":"after_trading","value":"# 交易引擎:盘后处理函数,每日盘后执行一次\ndef bigquant_run(context, data):\n pass\n\n","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":"1000000","type":"Literal","bound_global_parameter":null},{"name":"frequency","value":"minute","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":"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":"-126"},{"name":"options_data","node_id":"-126"},{"name":"history_ds","node_id":"-126"},{"name":"benchmark_ds","node_id":"-126"}],"output_ports":[{"name":"raw_perf","node_id":"-126"}],"cacheable":false,"seq_num":3,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='242,-608,200,200'/><node_position Node='-189' Position='130,-392,200,200'/><node_position Node='-209' Position='234,-498,200,200'/><node_position Node='-145' Position='285,-318,200,200'/><node_position Node='-151' Position='291,-254,200,200'/><node_position Node='-451' Position='451,-399,200,200'/><node_position Node='-459' Position='678,-585,200,200'/><node_position Node='-468' Position='537,-179,200,200'/><node_position Node='-765' Position='736,-93,200,200'/><node_position Node='-769' Position='1110,-552,200,200'/><node_position Node='-781' Position='1048,-433,200,200'/><node_position Node='-1086' Position='1048,-351,200,200'/><node_position Node='-1398' Position='1056,-263,200,200'/><node_position Node='-126' Position='723,142,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [2]:
    # 本代码由可视化策略环境自动生成 2022年3月4日 18:12
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m11_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        instruments = input_1.read()['instruments']
        start_date = input_1.read()['start_date']
        end_date = input_1.read()['end_date']
        df = DataSource('bar1m_CN_FUTURE').read(instruments=instruments,start_date=start_date,end_date=end_date)
        df60 = BarGenerator.aggregate_df(df, "60m"),
        df60 = df60[0]
    
        data_1 = DataSource.write_df(df60)
        return Outputs(data_1=data_1)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m11_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m24_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        instruments = input_1.read()['instruments']
        start_date = input_1.read()['start_date']
        end_date = input_1.read()['end_date']
        df = DataSource('bar1m_CN_FUTURE').read(instruments=instruments,start_date=start_date,end_date=end_date)
        df60 = BarGenerator.aggregate_df(df, "60m"),
        df60 = df60[0]
    
        data_1 = DataSource.write_df(df60)
        return Outputs(data_1=data_1)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m24_post_run_bigquant_run(outputs):
        return outputs
    
    # 交易引擎:初始化函数,只执行一次
    def m3_initialize_bigquant_run(context):
        # 加载预测数据
        context.ranker_prediction = context.options['data'].read_df()
        #设置尾盘可以下单
        context.set_enable_auto_planed_order(1)
        #用于换仓周期
        context.index = 0
        #控制打印
        context.PRINT = 0
    
    
    
    # 交易引擎:每个单位时间开盘前调用一次。
    def m3_before_trading_start_bigquant_run(context, data):
        pass
    
    
    # 交易引擎:tick数据处理函数,每个tick执行一次
    def m3_handle_tick_bigquant_run(context, data):
        pass
    # 交易引擎:bar数据处理函数,每个时间单位执行一次
    def m3_handle_data_bigquant_run(context, data):
        # 获取当日指标数据
        now = data.current_dt.strftime('%Y-%m-%d %H:%M:%S')
        now_data = context.ranker_prediction[context.ranker_prediction.date==now]
        if len(now_data)==0:
            return
        context.index += 1
        #每5根K线处理一次
        if context.index % 5 !=0:
            return
        #平仓
        for symbol,position in context.portfolio.positions.items():
            if position.long.avail_qty>0:
                rv = context.sell_close(symbol, position.long.avail_qty, None,order_type=OrderType.MARKET)
                msg = "{} {} 平多 下单函数返回 {}".format(now,symbol,context.get_error_msg(rv))
                context.write_log(msg, stdout=context.PRINT)
            if position.short.avail_qty>0:
                rv = context.buy_close(symbol, position.short.avail_qty, None, order_type=OrderType.MARKET)
                msg = "{} {} 平空 下单函数返回 {}".format(now,symbol,context.get_error_msg(rv))
                context.write_log(msg, stdout=context.PRINT)
        #开仓
        instruments = now_data.instrument.unique()
        rv = context.buy_open(instruments[0], 1, None, order_type=OrderType.MARKET)
        msg = "{} {} 开多 下单函数返回 {}".format(now,instruments[0],context.get_error_msg(rv))
        context.write_log(msg, stdout=context.PRINT) 
        rv = context.sell_open(instruments[-1], 1, None, order_type=OrderType.MARKET)
        msg = "{} {} 开空 下单函数返回 {}".format(now,instruments[-1],context.get_error_msg(rv))
        context.write_log(msg, stdout=context.PRINT)
    # 交易引擎:成交回报处理函数,每个成交发生时执行一次
    def m3_handle_trade_bigquant_run(context, data):
        pass
    
    
    # 交易引擎:委托回报处理函数,每个委托变化时执行一次
    def m3_handle_order_bigquant_run(context, data):
        pass
    
    
    # 交易引擎:盘后处理函数,每日盘后执行一次
    def m3_after_trading_bigquant_run(context, data):
        pass
    
    
    
    m1 = M.instruments.v2(
        start_date='2021-01-01',
        end_date='2021-08-30',
        market='CN_FUTURE',
        instrument_list="""P0000.DCE
    Y0000.DCE
    HC0000.SHF
    RB0000.SHF
    JM0000.DCE
    I0000.DCE
    A0000.DCE
    M0000.DCE
    TA0000.CZC
    C0000.DCE""",
        max_count=0
    )
    
    m11 = M.cached.v3(
        input_1=m1.data,
        run=m11_run_bigquant_run,
        post_run=m11_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m5 = M.auto_labeler_on_datasource.v1(
        input_data=m11.data_1,
        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={}
    )
    
    m23 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    close/shift(close, 20)-1 
    volume/mean(volume,20)
    
    """
    )
    
    m22 = M.derived_feature_extractor.v3(
        input_data=m11.data_1,
        features=m23.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m12 = M.join.v3(
        data1=m5.data,
        data2=m22.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m19 = M.dropnan.v1(
        input_data=m12.data
    )
    
    m21 = M.stock_ranker_train.v5(
        training_ds=m19.data,
        features=m23.data,
        learning_algorithm='排序',
        number_of_leaves=30,
        minimum_docs_per_leaf=100,
        number_of_trees=20,
        learning_rate=0.1,
        max_bins=1023,
        feature_fraction=1,
        m_lazy_run=False
    )
    
    m10 = M.instruments.v2(
        start_date='2021-09-01',
        end_date='2021-11-19',
        market='CN_FUTURE',
        instrument_list="""P0000.DCE
    Y0000.DCE
    HC0000.SHF
    RB0000.SHF
    JM0000.DCE
    I0000.DCE
    A0000.DCE
    M0000.DCE
    TA0000.CZC
    C0000.DCE""",
        max_count=0
    )
    
    m24 = M.cached.v3(
        input_1=m10.data,
        run=m24_run_bigquant_run,
        post_run=m24_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m25 = M.derived_feature_extractor.v3(
        input_data=m24.data_1,
        features=m23.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m26 = M.dropnan.v1(
        input_data=m25.data
    )
    
    m20 = M.stock_ranker_predict.v5(
        model=m21.model,
        data=m26.data,
        m_lazy_run=False
    )
    
    m3 = M.hftrade.v2(
        instruments=m10.data,
        options_data=m20.predictions,
        start_date='',
        end_date='',
        initialize=m3_initialize_bigquant_run,
        before_trading_start=m3_before_trading_start_bigquant_run,
        handle_tick=m3_handle_tick_bigquant_run,
        handle_data=m3_handle_data_bigquant_run,
        handle_trade=m3_handle_trade_bigquant_run,
        handle_order=m3_handle_order_bigquant_run,
        after_trading=m3_after_trading_bigquant_run,
        capital_base=1000000,
        frequency='minute',
        price_type='真实价格',
        product_type='期货',
        before_start_days='0',
        benchmark='000300.HIX',
        plot_charts=True,
        disable_cache=False,
        replay_bdb=False,
        show_debug_info=False,
        backtest_only=False
    )
    
    设置测试数据集,查看训练迭代过程的NDCG
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-4a9a3d4d0a6e4df6a7444f93f33fa15e"}/bigcharts-data-end
    • 收益率-4.25%
    • 年化收益率-19.3%
    • 基准收益率0.42%
    • 阿尔法-0.22
    • 贝塔0.06
    • 夏普比率-2.68
    • 胜率0.24
    • 盈亏比0.67
    • 收益波动率8.96%
    • 最大回撤5.93%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-57d90a16384a46d2b1e11a7e26dd7855"}/bigcharts-data-end