克隆策略

    {"description":"实验创建于2019/1/21","graph":{"edges":[{"to_node_id":"-797:input_data","from_node_id":"-778:data"},{"to_node_id":"-778:features","from_node_id":"-792:data"},{"to_node_id":"-803:input_data","from_node_id":"-797:data"},{"to_node_id":"-821:input_data","from_node_id":"-803:data"},{"to_node_id":"-803:features","from_node_id":"-811:data"},{"to_node_id":"-761:data1","from_node_id":"-821:data"},{"to_node_id":"-948:input_ds","from_node_id":"-754:data"},{"to_node_id":"-775:input_1","from_node_id":"-761:data"},{"to_node_id":"-784:data1","from_node_id":"-775:data_1"},{"to_node_id":"-778:instruments","from_node_id":"-860:data"},{"to_node_id":"-754:instruments","from_node_id":"-860:data"},{"to_node_id":"-754:features","from_node_id":"-937:data"},{"to_node_id":"-948:columns_ds","from_node_id":"-937:data"},{"to_node_id":"-761:data2","from_node_id":"-948:data"},{"to_node_id":"-784:data2","from_node_id":"-948:data"}],"nodes":[{"node_id":"-778","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"financial_statement_CN_STOCK_A","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}],"input_ports":[{"name":"instruments","node_id":"-778"},{"name":"features","node_id":"-778"}],"output_ports":[{"name":"data","node_id":"-778"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-784","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":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"-784"},{"name":"data2","node_id":"-784"}],"output_ports":[{"name":"data","node_id":"-784"}],"cacheable":true,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-792","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nfs_roe\nfs_quarter_index","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-792"}],"output_ports":[{"name":"data","node_id":"-792"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-797","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"fs_quarter_index==4","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-797"}],"output_ports":[{"name":"data","node_id":"-797"},{"name":"left_data","node_id":"-797"}],"cacheable":true,"seq_num":4,"comment":"过滤4季报","comment_collapsed":false},{"node_id":"-803","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":"-803"},{"name":"features","node_id":"-803"}],"output_ports":[{"name":"data","node_id":"-803"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-811","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nfs_eps_avg3=mean(fs_roe,3)","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-811"}],"output_ports":[{"name":"data","node_id":"-811"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-821","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"-821"}],"output_ports":[{"name":"data","node_id":"-821"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-754","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"stock_status_CN_STOCK_A","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}],"input_ports":[{"name":"instruments","node_id":"-754"},{"name":"features","node_id":"-754"}],"output_ports":[{"name":"data","node_id":"-754"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-761","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date,instrument","type":"Literal","bound_global_parameter":null},{"name":"how","value":"outer","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"-761"},{"name":"data2","node_id":"-761"}],"output_ports":[{"name":"data","node_id":"-761"}],"cacheable":true,"seq_num":9,"comment":"","comment_collapsed":true},{"node_id":"-775","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 cal_g(x):\n return x.ffill().bfill()\n result = df.groupby('instrument').apply(cal_g)\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":"-775"},{"name":"input_2","node_id":"-775"},{"name":"input_3","node_id":"-775"}],"output_ports":[{"name":"data_1","node_id":"-775"},{"name":"data_2","node_id":"-775"},{"name":"data_3","node_id":"-775"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true},{"node_id":"-860","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2012-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2018-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":"-860"}],"output_ports":[{"name":"data","node_id":"-860"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-937","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nst_status","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-937"}],"output_ports":[{"name":"data","node_id":"-937"}],"cacheable":true,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"-948","module_id":"BigQuantSpace.select_columns.select_columns-v3","parameters":[{"name":"columns","value":"st_status","type":"Literal","bound_global_parameter":null},{"name":"reverse_select","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_ds","node_id":"-948"},{"name":"columns_ds","node_id":"-948"}],"output_ports":[{"name":"data","node_id":"-948"}],"cacheable":true,"seq_num":14,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-778' Position='-963,162,200,200'/><node_position Node='-784' Position='-336,735,200,200'/><node_position Node='-792' Position='-750,56,200,200'/><node_position Node='-797' Position='-950,241,200,200'/><node_position Node='-803' Position='-827,357,200,200'/><node_position Node='-811' Position='-652,254,200,200'/><node_position Node='-821' Position='-816,439,200,200'/><node_position Node='-754' Position='-346.2185516357422,187.42266845703125,200,200'/><node_position Node='-761' Position='-631,546,200,200'/><node_position Node='-775' Position='-513,634,200,200'/><node_position Node='-860' Position='-1069,51,200,200'/><node_position Node='-937' Position='-157.73195838928223,65.54226684570312,200,200'/><node_position Node='-948' Position='-348,348,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [9]:
    # 本代码由可视化策略环境自动生成 2021年11月25日 19:33
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m11_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df()
        def cal_g(x):
            return x.ffill().bfill()
        result = df.groupby('instrument').apply(cal_g)
        data_1 = DataSource.write_df(result)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m11_post_run_bigquant_run(outputs):
        return outputs
    
    
    m3 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    fs_roe
    fs_quarter_index"""
    )
    
    m6 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    fs_eps_avg3=mean(fs_roe,3)"""
    )
    
    m2 = M.instruments.v2(
        start_date='2012-01-01',
        end_date='2018-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m1 = M.use_datasource.v1(
        instruments=m2.data,
        features=m3.data,
        datasource_id='financial_statement_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m4 = M.filter.v3(
        input_data=m1.data,
        expr='fs_quarter_index==4',
        output_left_data=False
    )
    
    m5 = M.derived_feature_extractor.v3(
        input_data=m4.data,
        features=m6.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m7 = M.dropnan.v1(
        input_data=m5.data
    )
    
    m10 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    st_status"""
    )
    
    m8 = M.use_datasource.v1(
        instruments=m2.data,
        features=m10.data,
        datasource_id='stock_status_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m14 = M.select_columns.v3(
        input_ds=m8.data,
        columns_ds=m10.data,
        columns='st_status',
        reverse_select=True
    )
    
    m9 = M.join.v3(
        data1=m7.data,
        data2=m14.data,
        on='date,instrument',
        how='outer',
        sort=False
    )
    
    m11 = M.cached.v3(
        input_1=m9.data,
        run=m11_run_bigquant_run,
        post_run=m11_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m12 = M.join.v3(
        data1=m11.data_1,
        data2=m14.data,
        on='date,instrument',
        how='inner',
        sort=True
    )
    
    列: ['st_status', 'st_status']
    /data: 4183479
    

    查看结果

    roe的3年滚动平均值与如下表所示

    In [10]:
    m12.data.read_df().head()
    
    Out[10]:
    instrument date fs_roe fs_quarter_index fs_eps_avg3
    0 000001.SZA 2012-01-04 12.428300 4.0 14.559067
    1 000002.SZA 2012-01-04 19.681499 4.0 19.333399
    2 000004.SZA 2012-01-04 38.843700 4.0 15.079067
    3 000005.SZA 2012-01-04 8.938500 4.0 3.178200
    4 000006.SZA 2012-01-04 16.568701 4.0 12.897567
    In [ ]: