复制链接
克隆策略

StockRanker多因子选股策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-288:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-295:features","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"to_node_id":"-288:instruments","from_node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"to_node_id":"-295:input_data","from_node_id":"-288:data"},{"to_node_id":"-1834:input_1","from_node_id":"-295:data"}],"nodes":[{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"return_0\nopen_0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-01-15","type":"Literal","bound_global_parameter":"交易日期"},{"name":"end_date","value":"2022-06-07","type":"Literal","bound_global_parameter":"交易日期"},{"name":"market","value":"CN_FUND","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"510050.HOF","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":"0","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"output_ports":[{"name":"data","node_id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"cacheable":false,"seq_num":9,"comment":"预测数据,用于回测和模拟","comment_collapsed":true},{"node_id":"-288","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":"30","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-288"},{"name":"features","node_id":"-288"}],"output_ports":[{"name":"data","node_id":"-288"}],"cacheable":true,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"-295","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":"-295"},{"name":"features","node_id":"-295"}],"output_ports":[{"name":"data","node_id":"-295"}],"cacheable":true,"seq_num":18,"comment":"","comment_collapsed":true},{"node_id":"-1834","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"import datetime\n# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n d=datetime.datetime.now()\n dstr=str(d.year)+'-%02d-%02d'%(d.month,d.day)\n print (dstr)\n n=50000\n \n df = input_1.read_df()\n \n for x in range(0,len(df),n):\n print (df[x:x+n])\n #df[x:x+n].to_hdf(\"userlib/data_\"+str(x)+'.csv',key=\"data\",mode=\"w\",complevel=9)\n df[x:x+n].to_csv(\"userlib/etf_\"+str(x)+'.csv',index=False)\n return Outputs(data_1=df)\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":"-1834"},{"name":"input_2","node_id":"-1834"},{"name":"input_3","node_id":"-1834"}],"output_ports":[{"name":"data_1","node_id":"-1834"},{"name":"data_2","node_id":"-1834"},{"name":"data_3","node_id":"-1834"}],"cacheable":true,"seq_num":11,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='314,-92,200,200'/><node_position Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='-16,-110,200,200'/><node_position Node='-288' Position='194,-2,200,200'/><node_position Node='-295' Position='203,74,200,200'/><node_position Node='-1834' Position='202,278,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [6]:
    # 本代码由可视化策略环境自动生成 2022年6月9日 19:37
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    import datetime
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m11_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        d=datetime.datetime.now()
        dstr=str(d.year)+'-%02d-%02d'%(d.month,d.day)
        print (dstr)
        n=50000
        
        df = input_1.read_df()
        
        for x in range(0,len(df),n):
            print (df[x:x+n])
            #df[x:x+n].to_hdf("userlib/data_"+str(x)+'.csv',key="data",mode="w",complevel=9)
            df[x:x+n].to_csv("userlib/etf_"+str(x)+'.csv',index=False)
        return Outputs(data_1=df)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m11_post_run_bigquant_run(outputs):
        return outputs
    
    
    m3 = M.input_features.v1(
        features="""return_0
    open_0"""
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2021-01-15'),
        end_date=T.live_run_param('trading_date', '2022-06-07'),
        market='CN_FUND',
        instrument_list='510050.HOF',
        max_count=0,
        m_cached=False
    )
    
    m17 = M.general_feature_extractor.v7(
        instruments=m9.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=30
    )
    
    m18 = M.derived_feature_extractor.v3(
        input_data=m17.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=True
    )
    
    m11 = M.cached.v3(
        input_1=m18.data,
        run=m11_run_bigquant_run,
        post_run=m11_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    ---------------------------------------------------------------------------
    Exception                                 Traceback (most recent call last)
    <ipython-input-6-debe64f32341> in <module>
         39 )
         40 
    ---> 41 m17 = M.general_feature_extractor.v7(
         42     instruments=m9.data,
         43     features=m3.data,
    
    Exception: no features extracted.