复制链接
克隆策略

    {"description":"实验创建于2022/12/3","graph":{"edges":[{"to_node_id":"-3162:input_data","from_node_id":"-824:data"},{"to_node_id":"-5962:input_1","from_node_id":"-3162:data"},{"to_node_id":"-481:training_ds","from_node_id":"-5962:data"},{"to_node_id":"-481:features","from_node_id":"-3512:data"}],"nodes":[{"node_id":"-481","module_id":"BigQuantSpace.random_forest_train.random_forest_train-v2","parameters":[{"name":"n_estimators","value":"10","type":"Literal","bound_global_parameter":null},{"name":"max_features","value":"auto","type":"Literal","bound_global_parameter":null},{"name":"max_depth","value":30,"type":"Literal","bound_global_parameter":null},{"name":"min_samples_leaf","value":200,"type":"Literal","bound_global_parameter":null},{"name":"n_jobs","value":1,"type":"Literal","bound_global_parameter":null},{"name":"random_state","value":"0","type":"Literal","bound_global_parameter":null},{"name":"algo","value":"classifier","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"training_ds","node_id":"-481"},{"name":"features","node_id":"-481"},{"name":"test_ds","node_id":"-481"}],"output_ports":[{"name":"model","node_id":"-481"}],"cacheable":true,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-824","module_id":"BigQuantSpace.use_datasource.use_datasource-v2","parameters":[{"name":"datasource_id","value":"market_performance_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":"2018-07-01","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-824"},{"name":"features","node_id":"-824"}],"output_ports":[{"name":"data","node_id":"-824"}],"cacheable":true,"seq_num":9,"comment":"","comment_collapsed":true},{"node_id":"-3162","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(close, -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)\n#where(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":"-3162"}],"output_ports":[{"name":"data","node_id":"-3162"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-5962","module_id":"BigQuantSpace.standardlize.standardlize-v9","parameters":[{"name":"standard_func","value":"ZScoreNorm","type":"Literal","bound_global_parameter":null},{"name":"columns_input","value":"label","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-5962"},{"name":"input_2","node_id":"-5962"}],"output_ports":[{"name":"data","node_id":"-5962"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-3512","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nbond_prem_ratio\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-3512"}],"output_ports":[{"name":"data","node_id":"-3512"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-481' Position='582,50,200,200'/><node_position Node='-824' Position='197,-319,200,200'/><node_position Node='-3162' Position='197,-213,200,200'/><node_position Node='-5962' Position='195,-99,200,200'/><node_position Node='-3512' Position='635,-309,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [38]:
    # 本代码由可视化策略环境自动生成 2022年12月17日 16:45
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m9 = M.use_datasource.v2(
        datasource_id='market_performance_CN_CONBOND',
        start_date='2018-01-01',
        end_date='2018-07-01',
        before_start_days=0
    )
    
    m4 = M.auto_labeler_on_datasource.v1(
        input_data=m9.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(close, -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={}
    )
    
    m5 = M.standardlize.v9(
        input_1=m4.data,
        standard_func='ZScoreNorm',
        columns_input='label'
    )
    
    m1 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    bond_prem_ratio
    """
    )
    
    m12 = M.random_forest_train.v2(
        training_ds=m5.data,
        features=m1.data,
        n_estimators=10,
        max_features='auto',
        max_depth=30,
        min_samples_leaf=200,
        n_jobs=1,
        random_state=0,
        algo='classifier'
    )
    
    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    <ipython-input-38-750b5bb03b57> in <module>
         50 )
         51 
    ---> 52 m12 = M.random_forest_train.v2(
         53     training_ds=m5.data,
         54     features=m1.data,
    
    KeyError: "None of [Index(['bond_prem_ratio'], dtype='object')] are in the [columns]"