克隆策略

    {"description":"实验创建于2021/11/17","graph":{"edges":[{"to_node_id":"-243:instruments","from_node_id":"-213:data"},{"to_node_id":"-255:instruments","from_node_id":"-213:data"},{"to_node_id":"-243:features","from_node_id":"-229:data"},{"to_node_id":"-234:features","from_node_id":"-229:data"},{"to_node_id":"-281:features","from_node_id":"-229:data"},{"to_node_id":"-288:features","from_node_id":"-229:data"},{"to_node_id":"-374:features","from_node_id":"-229:data"},{"to_node_id":"-266:data2","from_node_id":"-234:data"},{"to_node_id":"-234:input_data","from_node_id":"-243:data"},{"to_node_id":"-266:data1","from_node_id":"-255:data"},{"to_node_id":"-374:training_ds","from_node_id":"-266:data"},{"to_node_id":"-281:instruments","from_node_id":"-272:data"},{"to_node_id":"-288:input_data","from_node_id":"-281:data"}],"nodes":[{"node_id":"-213","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2015-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2016-11-01","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-213"}],"output_ports":[{"name":"data","node_id":"-213"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-229","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nreturn_10\nreturn_20\n\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-229"}],"output_ports":[{"name":"data","node_id":"-229"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-234","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":"True","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-234"},{"name":"features","node_id":"-234"}],"output_ports":[{"name":"data","node_id":"-234"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-243","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":90,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-243"},{"name":"features","node_id":"-243"}],"output_ports":[{"name":"data","node_id":"-243"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-255","module_id":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","parameters":[{"name":"label_expr","value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html\n# 添加benchmark_前缀,可使用对应的benchmark数据\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":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.SHA","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":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-255"}],"output_ports":[{"name":"data","node_id":"-255"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-266","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":"-266"},{"name":"data2","node_id":"-266"}],"output_ports":[{"name":"data","node_id":"-266"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-272","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2020-1-1","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-1-1","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-272"}],"output_ports":[{"name":"data","node_id":"-272"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-281","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":90,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-281"},{"name":"features","node_id":"-281"}],"output_ports":[{"name":"data","node_id":"-281"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-288","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":"True","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-288"},{"name":"features","node_id":"-288"}],"output_ports":[{"name":"data","node_id":"-288"}],"cacheable":true,"seq_num":9,"comment":"","comment_collapsed":true},{"node_id":"-374","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.2","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":"False","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":"-374"},{"name":"features","node_id":"-374"},{"name":"test_ds","node_id":"-374"},{"name":"base_model","node_id":"-374"}],"output_ports":[{"name":"model","node_id":"-374"},{"name":"feature_gains","node_id":"-374"},{"name":"m_lazy_run","node_id":"-374"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-213' Position='83,22,200,200'/><node_position Node='-229' Position='457,-60,200,200'/><node_position Node='-234' Position='349,328,200,200'/><node_position Node='-243' Position='351,211,200,200'/><node_position Node='-255' Position='17,190,200,200'/><node_position Node='-266' Position='185,413,200,200'/><node_position Node='-272' Position='779,47,200,200'/><node_position Node='-281' Position='774,161,200,200'/><node_position Node='-288' Position='786,286,200,200'/><node_position Node='-374' Position='424,588,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [13]:
    # 本代码由可视化策略环境自动生成 2021年11月17日 16:26
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.instruments.v2(
        start_date='2015-01-01',
        end_date='2016-11-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.advanced_auto_labeler.v2(
        instruments=m1.data,
        label_expr="""# #号开始的表示注释
    # 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
    # 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html
    #   添加benchmark_前缀,可使用对应的benchmark数据
    # 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)
    """,
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=True,
        cast_label_int=True,
        user_functions={}
    )
    
    m3 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    return_10
    return_20
    
    """
    )
    
    m5 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m5.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=True,
        user_functions={}
    )
    
    m6 = M.join.v3(
        data1=m2.data,
        data2=m4.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m11 = M.stock_ranker_train.v6(
        training_ds=m6.data,
        features=m3.data,
        learning_algorithm='排序',
        number_of_leaves=30,
        minimum_docs_per_leaf=1000,
        number_of_trees=20,
        learning_rate=0.2,
        max_bins=1023,
        feature_fraction=1,
        data_row_fraction=1,
        plot_charts=False,
        ndcg_discount_base=1,
        m_lazy_run=False
    )
    
    m7 = M.instruments.v2(
        start_date='2020-1-1',
        end_date='2021-1-1',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m8 = M.general_feature_extractor.v7(
        instruments=m7.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m9 = M.derived_feature_extractor.v3(
        input_data=m8.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=True,
        user_functions={}
    )