复制链接
克隆策略

    {"description":"实验创建于2022/4/24","graph":{"edges":[{"to_node_id":"-18:instruments","from_node_id":"-5:data"},{"to_node_id":"-18:features","from_node_id":"-13:data"},{"to_node_id":"-25:features","from_node_id":"-13:data"},{"to_node_id":"-25:input_data","from_node_id":"-18:data"}],"nodes":[{"node_id":"-5","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2020-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2020-02-02","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":"300","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-5"}],"output_ports":[{"name":"data","node_id":"-5"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-13","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"ts_max(close_0, 5)\nmy_max( 5)","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-13"}],"output_ports":[{"name":"data","node_id":"-13"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-18","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":"-18"},{"name":"features","node_id":"-18"}],"output_ports":[{"name":"data","node_id":"-18"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-25","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":"def my_max(data,day):\n def func(df):\n return df['close_0'].rolling(day).max()\n return data.groupby(\"instrument\", group_keys=False).apply(func)\n\n\nbigquant_run = {\n 'my_max':my_max\n}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-25"},{"name":"features","node_id":"-25"}],"output_ports":[{"name":"data","node_id":"-25"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-5' Position='30.2265625,174,200,200'/><node_position Node='-13' Position='343.2265625,176,200,200'/><node_position Node='-18' Position='184.2265625,331,200,200'/><node_position Node='-25' Position='180.2265625,400,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [34]:
    # 本代码由可视化策略环境自动生成 2022年4月24日 14:09
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def my_max(data,day):
        def func(df):
            return df['close_0'].rolling(day).max()
        return data.groupby("instrument", group_keys=False).apply(func)
    
    
    m4_user_functions_bigquant_run = {
        'my_max':my_max
    }
    
    m1 = M.instruments.v2(
        start_date='2020-01-01',
        end_date='2020-02-02',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=300
    )
    
    m2 = M.input_features.v1(
        features="""ts_max(close_0, 5)
    my_max( 5)"""
    )
    
    m3 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m2.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m3.data,
        features=m2.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions=m4_user_functions_bigquant_run
    )
    
    In [36]:
    df = m4.data.read()
    df[df['instrument'] =='000691.SZA']
    
    Out[36]:
    close_0 date instrument ts_max(close_0, 5) my_max( 5)
    14561 11.576945 2019-10-08 000691.SZA NaN NaN
    14562 11.821314 2019-10-09 000691.SZA NaN NaN
    14563 12.157320 2019-10-10 000691.SZA NaN NaN
    14564 12.554419 2019-10-11 000691.SZA NaN NaN
    14565 12.462780 2019-10-14 000691.SZA 12.554419 12.554419
    ... ... ... ... ... ...
    21979 11.851860 2020-01-17 000691.SZA 12.554419 12.554419
    21980 11.943498 2020-01-20 000691.SZA 12.371142 12.371142
    21981 12.035136 2020-01-21 000691.SZA 12.187866 12.187866
    21982 12.004590 2020-01-22 000691.SZA 12.035136 12.035136
    21983 11.454762 2020-01-23 000691.SZA 12.035136 12.035136

    77 rows × 5 columns