克隆策略

案例

  • 利用表名__列名实现跨表因子的混合抽取
  • 分别实现滚动2日成交额均值、明日收盘价、(收盘价+开盘价)、每日pb_lf和每日pe_ttm的跨表因子数据提取、合并和表达式计算

    {"description":"实验创建于2020/2/23","graph":{"edges":[{"to_node_id":"-96:instruments","from_node_id":"-11:data"},{"to_node_id":"-24:features","from_node_id":"-19:data"},{"to_node_id":"-96:features","from_node_id":"-19:data"},{"to_node_id":"-24:input_data","from_node_id":"-96:data"}],"nodes":[{"node_id":"-11","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-02-10","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-04-15","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"000001.SZA\n300023.SZA","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-11"}],"output_ports":[{"name":"data","node_id":"-11"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-19","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\navg_amount=mean(bar1d_CN_STOCK_A__amount, 2)\nclose_1=shift(bar1d_CN_STOCK_A__close, 1)\nclose_avg=(bar1d_CN_STOCK_A__close + bar1d_CN_STOCK_A__open)/2\npb_lf=market_value_CN_STOCK_A__pb_lf\npe_ttm=market_value_CN_STOCK_A__pe_ttm\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-19"}],"output_ports":[{"name":"data","node_id":"-19"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-24","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":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-24"},{"name":"features","node_id":"-24"}],"output_ports":[{"name":"data","node_id":"-24"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-96","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":"-96"},{"name":"features","node_id":"-96"}],"output_ports":[{"name":"data","node_id":"-96"}],"cacheable":false,"seq_num":1,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-11' Position='317,149,200,200'/><node_position Node='-19' Position='555,232,200,200'/><node_position Node='-24' Position='424,396,200,200'/><node_position Node='-96' Position='323,321,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [1]:
    # 本代码由可视化策略环境自动生成 2021年10月16日08:11
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m2 = M.instruments.v2(
        start_date='2021-02-10',
        end_date='2021-04-15',
        market='CN_STOCK_A',
        instrument_list="""000001.SZA
    300023.SZA""",
        max_count=0
    )
    
    m3 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    avg_amount=mean(bar1d_CN_STOCK_A__amount, 2)
    close_1=shift(bar1d_CN_STOCK_A__close, 1)
    close_avg=(bar1d_CN_STOCK_A__close + bar1d_CN_STOCK_A__open)/2
    pb_lf=market_value_CN_STOCK_A__pb_lf
    pe_ttm=market_value_CN_STOCK_A__pe_ttm
    """
    )
    
    m1 = M.general_feature_extractor.v7(
        instruments=m2.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0,
        m_cached=False
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m1.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=True,
        user_functions={}
    )
    
    In [2]:
    m4.data.read()
    
    Out[2]:
    date instrument avg_amount close_1 close_avg pb_lf pe_ttm
    0 2021-02-10 000001.SZA NaN NaN 2688.489258 1.571276 15.979293
    1 2021-02-18 000001.SZA 4.094565e+09 2645.180420 2681.826416 1.602939 16.301292
    2 2021-02-19 000001.SZA 2.908473e+09 2698.483643 2654.619385 1.573255 15.999417
    3 2021-02-22 000001.SZA 3.321688e+09 2648.511719 2564.114746 1.476287 15.013289
    4 2021-02-23 000001.SZA 4.303298e+09 2485.270264 2460.284180 1.446603 14.711414
    ... ... ... ... ... ... ... ...
    77 2021-04-09 300023.SZA 3.504994e+07 34.102509 34.177872 5.897033 -14.584646
    78 2021-04-12 300023.SZA 2.308277e+07 34.215557 34.592381 5.897033 -14.584646
    79 2021-04-13 300023.SZA 1.976612e+07 34.215557 34.422810 5.773637 -14.279461
    80 2021-04-14 300023.SZA 1.651450e+07 33.499592 33.914097 5.858066 -14.488273
    81 2021-04-15 300023.SZA 1.350108e+07 33.989460 33.970619 5.890539 -14.568584

    82 rows × 7 columns