复制链接
克隆策略

    {"description":"实验创建于2022/7/29","graph":{"edges":[{"to_node_id":"-124:instruments","from_node_id":"-111:data"},{"to_node_id":"-124:features","from_node_id":"-119:data"},{"to_node_id":"-3256:features","from_node_id":"-119:data"},{"to_node_id":"-3256:input_data","from_node_id":"-124:data"},{"to_node_id":"-6195:input_1","from_node_id":"-3256:data"}],"nodes":[{"node_id":"-111","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2019-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2020-01-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":"-111"}],"output_ports":[{"name":"data","node_id":"-111"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-119","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmax_shift_date = ts_argmax(volume_20, 30)\nmax_vol = ts_max(volume_20, 30)\n\nvolume_0\nclose_0\nclose_1","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-119"}],"output_ports":[{"name":"data","node_id":"-119"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-124","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":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-124"},{"name":"features","node_id":"-124"}],"output_ports":[{"name":"data","node_id":"-124"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-3256","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":"-3256"},{"name":"features","node_id":"-3256"}],"output_ports":[{"name":"data","node_id":"-3256"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-6195","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 df = input_1.read_df()\n def func(_x):\n x = _x.copy()\n x.sort_values(\"date\", inplace=True)\n x.reset_index(drop=True, inplace=True)\n x[\"index2\"] = x.index - 20 - (30 - x.max_shift_date) + 1\n def del_neg(x):\n x = np.nan if x < 0 else x\n return x\n x[\"index2\"] = x[\"index2\"].apply(del_neg)\n x.replace(np.nan, 0, inplace=True)\n x[\"max_date\"] = x.iloc[x.index2.values,:][\"date\"].values\n x[\"max_close_0\"] = x.iloc[x.index2.values,:][\"close_0\"].values\n x[\"max_close_1\"] = x.iloc[x.index2.values,:][\"close_1\"].values\n x = x.iloc[50:,]\n return x\n result = df.groupby(\"instrument\").apply(func)\n \n result.reset_index(drop=True, inplace=True)\n data_1 = DataSource.write_df(result)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\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":"-6195"},{"name":"input_2","node_id":"-6195"},{"name":"input_3","node_id":"-6195"}],"output_ports":[{"name":"data_1","node_id":"-6195"},{"name":"data_2","node_id":"-6195"},{"name":"data_3","node_id":"-6195"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-111' Position='115,153,200,200'/><node_position Node='-119' Position='516,153,200,200'/><node_position Node='-124' Position='310,282,200,200'/><node_position Node='-3256' Position='417,385,200,200'/><node_position Node='-6195' Position='331.0874328613281,503.5379638671875,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [195]:
    # 本代码由可视化策略环境自动生成 2022年7月30日 13:17
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m4_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df()
        def func(_x):
            x = _x.copy()
            x.sort_values("date", inplace=True)
            x.reset_index(drop=True, inplace=True)
            x["index2"] = x.index - 20 - (30 - x.max_shift_date) + 1
            def del_neg(x):
                x = np.nan if x < 0 else x
                return x
            x["index2"] = x["index2"].apply(del_neg)
            x.replace(np.nan, 0, inplace=True)
            x["max_date"] = x.iloc[x.index2.values,:]["date"].values
            x["max_close_0"] = x.iloc[x.index2.values,:]["close_0"].values
            x["max_close_1"] = x.iloc[x.index2.values,:]["close_1"].values
            x = x.iloc[50:,]
            return x
        result = df.groupby("instrument").apply(func)
        
        result.reset_index(drop=True, inplace=True)
        data_1 = DataSource.write_df(result)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m4_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.instruments.v2(
        start_date='2019-01-01',
        end_date='2020-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    max_shift_date = ts_argmax(volume_20, 30)
    max_vol = ts_max(volume_20, 30)
    
    volume_0
    close_0
    close_1"""
    )
    
    m3 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m2.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m5 = 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 = M.cached.v3(
        input_1=m5.data,
        run=m4_run_bigquant_run,
        post_run=m4_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    In [197]:
    df = m4.data_1.read()
    x = df.groupby("instrument").get_group("000002.SZA")
    x.reset_index(drop=True, inplace=True)
    x.head(60)
    
    Out[197]:
    close_0 close_1 date instrument volume_0 volume_20 max_shift_date max_vol index2 max_date max_close_0 max_close_1
    0 4212.985840 4158.771973 2019-03-20 000002.SZA 61858857 70806979.0 29.0 70806979.0 30.0 2019-02-20 3941.916748 3856.315918
    1 4215.839355 4212.985840 2019-03-21 000002.SZA 67337269 61652727.0 28.0 70806979.0 30.0 2019-02-20 3941.916748 3856.315918
    2 4164.479004 4215.839355 2019-03-22 000002.SZA 40311517 61604902.0 27.0 70806979.0 30.0 2019-02-20 3941.916748 3856.315918
    3 4017.530762 4164.479004 2019-03-25 000002.SZA 48541176 132851283.0 29.0 132851283.0 33.0 2019-02-25 4050.344482 3847.755859
    4 4036.077637 4017.530762 2019-03-26 000002.SZA 61443793 98251978.0 28.0 132851283.0 33.0 2019-02-25 4050.344482 3847.755859
    5 4130.238770 4036.077637 2019-03-27 000002.SZA 45642421 91916628.0 27.0 132851283.0 33.0 2019-02-25 4050.344482 3847.755859
    6 4108.838379 4130.238770 2019-03-28 000002.SZA 51732489 60637498.0 26.0 132851283.0 33.0 2019-02-25 4050.344482 3847.755859
    7 4382.760742 4108.838379 2019-03-29 000002.SZA 97032993 85178537.0 25.0 132851283.0 33.0 2019-02-25 4050.344482 3847.755859
    8 4575.362793 4382.760742 2019-04-01 000002.SZA 107851511 141479523.0 29.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    9 4563.949219 4575.362793 2019-04-02 000002.SZA 50927285 83555595.0 28.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    10 4635.283203 4563.949219 2019-04-03 000002.SZA 45311653 81347026.0 27.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    11 4596.762695 4635.283203 2019-04-04 000002.SZA 69209274 74410687.0 26.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    12 4499.748535 4596.762695 2019-04-08 000002.SZA 74488141 83738306.0 25.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    13 4776.524414 4499.748535 2019-04-09 000002.SZA 90418699 96860959.0 24.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    14 4675.230469 4776.524414 2019-04-10 000002.SZA 53905288 79619289.0 23.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    15 4542.548828 4675.230469 2019-04-11 000002.SZA 57378188 79146059.0 22.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    16 4435.547852 4542.548828 2019-04-12 000002.SZA 48243677 57570624.0 21.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    17 4414.147949 4435.547852 2019-04-15 000002.SZA 55780853 77818137.0 20.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    18 4514.015625 4414.147949 2019-04-16 000002.SZA 70918500 98462778.0 19.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    19 4419.854492 4514.015625 2019-04-17 000002.SZA 54353405 76997894.0 18.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    20 4379.907715 4419.854492 2019-04-18 000002.SZA 45926360 61858858.0 17.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    21 4491.188477 4379.907715 2019-04-19 000002.SZA 45455696 67337269.0 16.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    22 4210.132812 4491.188477 2019-04-22 000002.SZA 125461075 40311517.0 15.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    23 4210.132812 4210.132812 2019-04-23 000002.SZA 59906379 48541176.0 14.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    24 4222.972656 4210.132812 2019-04-24 000002.SZA 44745667 61443794.0 13.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    25 4193.012695 4222.972656 2019-04-25 000002.SZA 47222093 45642421.0 12.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    26 4148.785156 4193.012695 2019-04-26 000002.SZA 39688302 51732489.0 11.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    27 4187.305664 4148.785156 2019-04-29 000002.SZA 49838608 97032993.0 10.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    28 4120.251953 4187.305664 2019-04-30 000002.SZA 50376388 107851511.0 9.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    29 3866.302734 4120.251953 2019-05-06 000002.SZA 70069643 50927285.0 8.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    30 3991.850586 3866.302734 2019-05-07 000002.SZA 50303208 45311653.0 7.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    31 3907.676514 3991.850586 2019-05-08 000002.SZA 35387944 69209274.0 6.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    32 3854.889404 3907.676514 2019-05-09 000002.SZA 35094363 74488141.0 5.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    33 3998.983887 3854.889404 2019-05-10 000002.SZA 47186116 90418699.0 4.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    34 4001.837402 3998.983887 2019-05-13 000002.SZA 31244453 53905288.0 3.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    35 3937.636719 4001.837402 2019-05-14 000002.SZA 34395188 57378188.0 2.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    36 3997.557373 3937.636719 2019-05-15 000002.SZA 37456659 48243677.0 1.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    37 4013.250732 3997.557373 2019-05-16 000002.SZA 30726523 55780853.0 0.0 141479523.0 38.0 2019-03-04 4237.239746 4071.744629
    38 3903.396484 4013.250732 2019-05-17 000002.SZA 32665096 70918500.0 19.0 107851511.0 58.0 2019-04-01 4575.362793 4382.760742
    39 3889.129639 3903.396484 2019-05-20 000002.SZA 25596834 54353405.0 18.0 107851511.0 58.0 2019-04-01 4575.362793 4382.760742
    40 3926.223389 3889.129639 2019-05-21 000002.SZA 26560389 45926360.0 17.0 107851511.0 58.0 2019-04-01 4575.362793 4382.760742
    41 3903.396484 3926.223389 2019-05-22 000002.SZA 20464814 45455696.0 16.0 107851511.0 58.0 2019-04-01 4575.362793 4382.760742
    42 3812.088867 3903.396484 2019-05-23 000002.SZA 27074052 125461075.0 29.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    43 3826.355713 3812.088867 2019-05-24 000002.SZA 19782977 59906379.0 28.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    44 3852.035889 3826.355713 2019-05-27 000002.SZA 25196780 44745667.0 27.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    45 3940.489990 3852.035889 2019-05-28 000002.SZA 40994638 47222093.0 26.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    46 3874.862793 3940.489990 2019-05-29 000002.SZA 21472853 39688302.0 25.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    47 3840.622559 3874.862793 2019-05-30 000002.SZA 20052645 49838608.0 24.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    48 3809.235596 3840.622559 2019-05-31 000002.SZA 20014595 50376388.0 23.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    49 3772.141846 3809.235596 2019-06-03 000002.SZA 31756796 70069643.0 22.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    50 3752.168457 3772.141846 2019-06-04 000002.SZA 20326070 50303208.0 21.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    51 3856.315918 3752.168457 2019-06-05 000002.SZA 57616447 35387944.0 20.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    52 3869.156006 3856.315918 2019-06-06 000002.SZA 33379205 35094363.0 19.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    53 3967.596924 3869.156006 2019-06-10 000002.SZA 52754702 47186116.0 18.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    54 4041.784424 3967.596924 2019-06-11 000002.SZA 44963005 31244454.0 17.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    55 3994.703857 4041.784424 2019-06-12 000002.SZA 26937224 34395188.0 16.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    56 3970.450439 3994.703857 2019-06-13 000002.SZA 25043108 37456659.0 15.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    57 3984.717285 3970.450439 2019-06-14 000002.SZA 31141781 30726523.0 14.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    58 3981.863770 3984.717285 2019-06-17 000002.SZA 17167279 32665096.0 13.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477
    59 3951.903564 3981.863770 2019-06-18 000002.SZA 21916216 25596834.0 12.0 125461075.0 72.0 2019-04-22 4210.132812 4491.188477