克隆策略

    {"description":"实验创建于2019/1/21","graph":{"edges":[{"to_node_id":"-228:input_data","from_node_id":"-106:data"},{"to_node_id":"-204:features","from_node_id":"-131:data"},{"to_node_id":"-266:columns_ds","from_node_id":"-131:data"},{"to_node_id":"-106:features","from_node_id":"-150:data"},{"to_node_id":"-242:columns_ds","from_node_id":"-150:data"},{"to_node_id":"-204:instruments","from_node_id":"-154:data"},{"to_node_id":"-106:instruments","from_node_id":"-184:data"},{"to_node_id":"-528:input_data","from_node_id":"-197:data"},{"to_node_id":"-248:input_data","from_node_id":"-204:data"},{"to_node_id":"-242:input_ds","from_node_id":"-228:data"},{"to_node_id":"-197:data1","from_node_id":"-242:data"},{"to_node_id":"-266:input_ds","from_node_id":"-248:data"},{"to_node_id":"-248:features","from_node_id":"-256:data"},{"to_node_id":"-197:data2","from_node_id":"-266:data"},{"to_node_id":"-228:features","from_node_id":"-271:data"},{"to_node_id":"-528:features","from_node_id":"-546:data"}],"nodes":[{"node_id":"-106","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_index_CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2015-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2018-01-01","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-106"},{"name":"features","node_id":"-106"}],"output_ports":[{"name":"data","node_id":"-106"}],"cacheable":false,"seq_num":1,"comment":"bar1d_index_CN_STOCK_A表中抽取指数close数据","comment_collapsed":false},{"node_id":"-131","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nclose\nopen\nlow\nhigh\nadjust_factor","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-131"}],"output_ports":[{"name":"data","node_id":"-131"}],"cacheable":true,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-150","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nclose\ninstrument\n\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-150"}],"output_ports":[{"name":"data","node_id":"-150"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-154","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2015-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":"-154"}],"output_ports":[{"name":"data","node_id":"-154"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-184","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2015-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":"000300.HIX","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-184"}],"output_ports":[{"name":"data","node_id":"-184"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-197","module_id":"BigQuantSpace.join.join-v3","parameters":[{"name":"on","value":"date","type":"Literal","bound_global_parameter":null},{"name":"how","value":"inner","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"data1","node_id":"-197"},{"name":"data2","node_id":"-197"}],"output_ports":[{"name":"data","node_id":"-197"}],"cacheable":true,"seq_num":8,"comment":"合并股票真实价格和大盘5日收益率","comment_collapsed":false},{"node_id":"-204","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_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":"-204"},{"name":"features","node_id":"-204"}],"output_ports":[{"name":"data","node_id":"-204"}],"cacheable":true,"seq_num":4,"comment":"bar1d_CN_STOCK_A表中抽取全市场股票的基础行情数据","comment_collapsed":false},{"node_id":"-228","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":"-228"},{"name":"features","node_id":"-228"}],"output_ports":[{"name":"data","node_id":"-228"}],"cacheable":true,"seq_num":7,"comment":"计算指数5日收益率","comment_collapsed":false},{"node_id":"-242","module_id":"BigQuantSpace.select_columns.select_columns-v3","parameters":[{"name":"columns","value":"instrument,close","type":"Literal","bound_global_parameter":null},{"name":"reverse_select","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_ds","node_id":"-242"},{"name":"columns_ds","node_id":"-242"}],"output_ports":[{"name":"data","node_id":"-242"}],"cacheable":true,"seq_num":9,"comment":"过滤指定的列","comment_collapsed":false},{"node_id":"-248","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":"-248"},{"name":"features","node_id":"-248"}],"output_ports":[{"name":"data","node_id":"-248"}],"cacheable":true,"seq_num":11,"comment":"抽取真实价格","comment_collapsed":false},{"node_id":"-256","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nstockret=close/shift(close,5)-1","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-256"}],"output_ports":[{"name":"data","node_id":"-256"}],"cacheable":true,"seq_num":12,"comment":"表达式引擎计算个股过去5日收益率","comment_collapsed":false},{"node_id":"-266","module_id":"BigQuantSpace.select_columns.select_columns-v3","parameters":[{"name":"columns","value":"","type":"Literal","bound_global_parameter":null},{"name":"reverse_select","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_ds","node_id":"-266"},{"name":"columns_ds","node_id":"-266"}],"output_ports":[{"name":"data","node_id":"-266"}],"cacheable":true,"seq_num":14,"comment":"过滤指定的列","comment_collapsed":false},{"node_id":"-271","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nbmret=close/shift(close,5)-1\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-271"}],"output_ports":[{"name":"data","node_id":"-271"}],"cacheable":true,"seq_num":15,"comment":"表达式引擎因子计算5日收益率","comment_collapsed":false},{"node_id":"-528","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":"-528"},{"name":"features","node_id":"-528"}],"output_ports":[{"name":"data","node_id":"-528"}],"cacheable":true,"seq_num":17,"comment":"抽取相对收益率","comment_collapsed":false},{"node_id":"-546","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nrelative_ret=stockret-bmret","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-546"}],"output_ports":[{"name":"data","node_id":"-546"}],"cacheable":true,"seq_num":18,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-106' Position='-750,91,200,200'/><node_position Node='-131' Position='96,-6,200,200'/><node_position Node='-150' Position='-558,-17,200,200'/><node_position Node='-154' Position='-248,-14,200,200'/><node_position Node='-184' Position='-900,-15,200,200'/><node_position Node='-197' Position='-180,467,200,200'/><node_position Node='-204' Position='-99,110,200,200'/><node_position Node='-228' Position='-579.5868225097656,243.1961669921875,200,200'/><node_position Node='-242' Position='-492.19964599609375,350.19793701171875,200,200'/><node_position Node='-248' Position='38,227,200,200'/><node_position Node='-256' Position='202,109,200,200'/><node_position Node='-266' Position='187,339,200,200'/><node_position Node='-271' Position='-426,130,200,200'/><node_position Node='-528' Position='-38,589,200,200'/><node_position Node='-546' Position='131,505,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [10]:
    # 本代码由可视化策略环境自动生成 2021年11月25日 18:47
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m5 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    close
    open
    low
    high
    adjust_factor"""
    )
    
    m3 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    close
    instrument
    
    """
    )
    
    m6 = M.instruments.v2(
        start_date='2015-01-01',
        end_date='2018-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m4 = M.use_datasource.v1(
        instruments=m6.data,
        features=m5.data,
        datasource_id='bar1d_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m2 = M.instruments.v2(
        start_date='2015-01-01',
        end_date='2018-01-01',
        market='CN_STOCK_A',
        instrument_list='000300.HIX',
        max_count=0
    )
    
    m1 = M.use_datasource.v1(
        instruments=m2.data,
        features=m3.data,
        datasource_id='bar1d_index_CN_STOCK_A',
        start_date='2015-01-01',
        end_date='2018-01-01',
        m_cached=False
    )
    
    m12 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    stockret=close/shift(close,5)-1"""
    )
    
    m11 = M.derived_feature_extractor.v3(
        input_data=m4.data,
        features=m12.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m14 = M.select_columns.v3(
        input_ds=m11.data,
        columns_ds=m5.data,
        columns='',
        reverse_select=True
    )
    
    m15 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    bmret=close/shift(close,5)-1
    """
    )
    
    m7 = M.derived_feature_extractor.v3(
        input_data=m1.data,
        features=m15.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m9 = M.select_columns.v3(
        input_ds=m7.data,
        columns_ds=m3.data,
        columns='instrument,close',
        reverse_select=True
    )
    
    m8 = M.join.v3(
        data1=m9.data,
        data2=m14.data,
        on='date',
        how='inner',
        sort=False
    )
    
    m18 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    relative_ret=stockret-bmret"""
    )
    
    m17 = M.derived_feature_extractor.v3(
        input_data=m8.data,
        features=m18.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    列: ['instrument', 'close', 'close', 'instrument']
    /data: 732
    

    查看结果

    相对大盘5日收益率计算值与如下表所示

    In [11]:
    m17.data.read_df().tail()
    
    Out[11]:
    instrument date stockret bmret relative_ret
    2169369 002039.SZA 2017-12-29 -0.012087 -0.005856 -0.006231
    2169370 600636.SHA 2017-12-29 0.049365 -0.005856 0.055221
    2169371 002264.SZA 2017-12-29 -0.064423 -0.005856 -0.058567
    2169372 603678.SHA 2017-12-29 -0.010335 -0.005856 -0.004479
    2169373 300386.SZA 2017-12-29 -0.082176 -0.005856 -0.076320
    In [ ]: