复制链接
克隆策略

    {"description":"实验创建于2017/11/15","graph":{"edges":[{"to_node_id":"-300:features","from_node_id":"-2295:data"},{"to_node_id":"-300:instruments","from_node_id":"-620:data"},{"to_node_id":"-7201:input_1","from_node_id":"-300:data"}],"nodes":[{"node_id":"-2295","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"close_0\nopen_0\nlow_0\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-2295"}],"output_ports":[{"name":"data","node_id":"-2295"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-620","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2022-08-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-10-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":"-620"}],"output_ports":[{"name":"data","node_id":"-620"}],"cacheable":true,"seq_num":24,"comment":"","comment_collapsed":true},{"node_id":"-300","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":"100","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-300"},{"name":"features","node_id":"-300"}],"output_ports":[{"name":"data","node_id":"-300"}],"cacheable":true,"seq_num":22,"comment":"","comment_collapsed":true},{"node_id":"-7201","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"def preprocess(df):\n \n for factor in ['open_0']:\n df[factor] = df[factor].all_wbins(factor, 10)\n \n return df \n\n\n# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n df = input_1.read_df()\n\n data_a = df.apply(preprocess)\n data_1 = DataSource.write_df(data_a)\n \n return Outputs(data_1=data_1, data_2=None, data_3=None)\n\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":"-7201"},{"name":"input_2","node_id":"-7201"},{"name":"input_3","node_id":"-7201"}],"output_ports":[{"name":"data_1","node_id":"-7201"},{"name":"data_2","node_id":"-7201"},{"name":"data_3","node_id":"-7201"}],"cacheable":true,"seq_num":18,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-2295' Position='1048.4169921875,-301,200,200'/><node_position Node='-620' Position='726.2252197265625,-253.64591217041016,200,200'/><node_position Node='-300' Position='971.7381591796875,-165.4096450805664,200,200'/><node_position Node='-7201' Position='972.579345703125,-75.31746101379395,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [6]:
    # 本代码由可视化策略环境自动生成 2023年2月1日 15:34
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def preprocess(df):
        
        for factor in ['open_0']:
            df[factor] = df[factor].all_wbins(factor, 10)
                
        return df    
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m18_run_bigquant_run(input_1, input_2, input_3):
        df = input_1.read_df()
    
        data_a = df.apply(preprocess)
        data_1 = DataSource.write_df(data_a)
       
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m18_post_run_bigquant_run(outputs):
        return outputs
    
    
    m8 = M.input_features.v1(
        features="""close_0
    open_0
    low_0
    """
    )
    
    m24 = M.instruments.v2(
        start_date='2022-08-01',
        end_date='2022-10-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m22 = M.general_feature_extractor.v7(
        instruments=m24.data,
        features=m8.data,
        start_date='',
        end_date='',
        before_start_days=100
    )
    
    m18 = M.cached.v3(
        input_1=m22.data,
        run=m18_run_bigquant_run,
        post_run=m18_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    KeyError: 'open_0'
    
    The above exception was the direct cause of the following exception:
    
    KeyError                                  Traceback (most recent call last)
    <ipython-input-6-69b749ff3e14> in <module>
         49 )
         50 
    ---> 51 m18 = M.cached.v3(
         52     input_1=m22.data,
         53     run=m18_run_bigquant_run,
    
    <ipython-input-6-69b749ff3e14> in m18_run_bigquant_run(input_1, input_2, input_3)
         15     df = input_1.read_df()
         16 
    ---> 17     data_a = df.apply(preprocess)
         18     data_1 = DataSource.write_df(data_a)
         19 
    
    <ipython-input-6-69b749ff3e14> in preprocess(df)
          6 
          7     for factor in ['open_0']:
    ----> 8         df[factor] = df[factor].all_wbins(factor, 10)
          9 
         10     return df
    
    KeyError: 'open_0'