克隆策略

    {"Description":"实验创建于2019/1/21","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-228:input_data","SourceOutputPortId":"-106:data"},{"DestinationInputPortId":"-252:features","SourceOutputPortId":"-131:data"},{"DestinationInputPortId":"-245:features","SourceOutputPortId":"-131:data"},{"DestinationInputPortId":"-106:features","SourceOutputPortId":"-150:data"},{"DestinationInputPortId":"-245:instruments","SourceOutputPortId":"-154:data"},{"DestinationInputPortId":"-106:instruments","SourceOutputPortId":"-184:data"},{"DestinationInputPortId":"-277:input_ds","SourceOutputPortId":"-228:data"},{"DestinationInputPortId":"-228:features","SourceOutputPortId":"-271:data"},{"DestinationInputPortId":"-252:input_data","SourceOutputPortId":"-245:data"},{"DestinationInputPortId":"-197:data2","SourceOutputPortId":"-252:data"},{"DestinationInputPortId":"-197:data1","SourceOutputPortId":"-277:data"}],"ModuleNodes":[{"Id":"-106","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_index_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-106"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-106"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-106","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":1,"Comment":"bar1d_index_CN_STOCK_A表中抽取指数close数据","CommentCollapsed":false},{"Id":"-131","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nreturn_5\nclose_0 / close_1","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-131"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-131","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-150","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nclose\ninstrument\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-150"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-150","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-154","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-154"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-154","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-184","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000300.HIX","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-184"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-184","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-197","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"inner","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"-197"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-197"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-197","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"Comment":"","CommentCollapsed":false},{"Id":"-228","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-228"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-228"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-228","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"Comment":"计算指数5日收益率","CommentCollapsed":false},{"Id":"-271","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nbenchmark_5day_ret=close/shift(close,5)-1\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-271"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-271","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"Comment":"表达式引擎因子计算5日收益率","CommentCollapsed":false},{"Id":"-245","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":90,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-245"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-245"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-245","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"Comment":"","CommentCollapsed":true},{"Id":"-252","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-252"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-252"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-252","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"","CommentCollapsed":true},{"Id":"-277","ModuleId":"BigQuantSpace.select_columns.select_columns-v3","ModuleParameters":[{"Name":"columns","Value":"close,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"reverse_select","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-277"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"columns_ds","NodeId":"-277"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-277","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":12,"Comment":"","CommentCollapsed":true}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='-106' Position='-750,91,200,200'/><NodePosition Node='-131' Position='64.25262451171875,-11.614038467407227,200,200'/><NodePosition Node='-150' Position='-558,-17,200,200'/><NodePosition Node='-154' Position='-248,-14,200,200'/><NodePosition Node='-184' Position='-900,-13.677192687988281,200,200'/><NodePosition Node='-197' Position='-274.92918395996094,456.411865234375,200,200'/><NodePosition Node='-228' Position='-525.0919189453125,252.79034423828125,200,200'/><NodePosition Node='-271' Position='-426,130,200,200'/><NodePosition Node='-245' Position='-81.8656120300293,146.3516387939453,200,200'/><NodePosition Node='-252' Position='-95.09368896484375,256.1446838378906,200,200'/><NodePosition Node='-277' Position='-517.0692138671875,368.46307373046875,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":true}
    In [14]:
    # 本代码由可视化策略环境自动生成 2019年1月30日 13:58
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m5 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    return_5
    close_0 / close_1"""
    )
    
    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
    )
    
    m9 = M.general_feature_extractor.v7(
        instruments=m6.data,
        features=m5.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m10 = M.derived_feature_extractor.v3(
        input_data=m9.data,
        features=m5.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    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
    )
    
    m15 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    benchmark_5day_ret=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={}
    )
    
    m12 = M.select_columns.v3(
        input_ds=m7.data,
        columns='close,instrument',
        reverse_select=True
    )
    
    m8 = M.join.v3(
        data1=m12.data,
        data2=m10.data,
        on='date',
        how='inner',
        sort=False
    )
    
    [2019-01-30 13:58:19.496266] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-30 13:58:19.501326] INFO: bigquant: 命中缓存
    [2019-01-30 13:58:19.502278] INFO: bigquant: input_features.v1 运行完成[0.006026s].
    [2019-01-30 13:58:19.504538] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-30 13:58:19.508151] INFO: bigquant: 命中缓存
    [2019-01-30 13:58:19.508903] INFO: bigquant: input_features.v1 运行完成[0.004367s].
    [2019-01-30 13:58:19.510932] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-30 13:58:19.514856] INFO: bigquant: 命中缓存
    [2019-01-30 13:58:19.515584] INFO: bigquant: instruments.v2 运行完成[0.004649s].
    [2019-01-30 13:58:19.520482] INFO: bigquant: general_feature_extractor.v7 开始运行..
    [2019-01-30 13:58:19.523959] INFO: bigquant: 命中缓存
    [2019-01-30 13:58:19.524703] INFO: bigquant: general_feature_extractor.v7 运行完成[0.004226s].
    [2019-01-30 13:58:19.526672] INFO: bigquant: derived_feature_extractor.v3 开始运行..
    [2019-01-30 13:58:19.530303] INFO: bigquant: 命中缓存
    [2019-01-30 13:58:19.531090] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.004376s].
    [2019-01-30 13:58:19.533201] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-30 13:58:19.536673] INFO: bigquant: 命中缓存
    [2019-01-30 13:58:19.537359] INFO: bigquant: instruments.v2 运行完成[0.00416s].
    [2019-01-30 13:58:19.539060] INFO: bigquant: use_datasource.v1 开始运行..
    [2019-01-30 13:58:19.722810] INFO: bigquant: use_datasource.v1 运行完成[0.183729s].
    [2019-01-30 13:58:19.724923] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-30 13:58:19.729072] INFO: bigquant: 命中缓存
    [2019-01-30 13:58:19.729812] INFO: bigquant: input_features.v1 运行完成[0.0049s].
    [2019-01-30 13:58:19.732027] INFO: bigquant: derived_feature_extractor.v3 开始运行..
    [2019-01-30 13:58:19.754411] INFO: derived_feature_extractor: 提取完成 benchmark_5day_ret=close/shift(close,5)-1, 0.004s
    [2019-01-30 13:58:19.771802] INFO: derived_feature_extractor: /data, 732
    [2019-01-30 13:58:19.791443] INFO: bigquant: derived_feature_extractor.v3 运行完成[0.059401s].
    [2019-01-30 13:58:19.794414] INFO: bigquant: select_columns.v3 开始运行..
    列: ['close', 'instrument']
    /data: 732
    [2019-01-30 13:58:19.821147] INFO: bigquant: select_columns.v3 运行完成[0.026711s].
    [2019-01-30 13:58:19.823438] INFO: bigquant: join.v3 开始运行..
    [2019-01-30 13:58:19.916919] INFO: join: /y_2014, 行数=0/141569, 耗时=0.05523s
    [2019-01-30 13:58:20.569672] INFO: join: /y_2015, 行数=569698/569698, 耗时=0.648436s
    [2019-01-30 13:58:21.366822] INFO: join: /y_2016, 行数=641546/641546, 耗时=0.751008s
    [2019-01-30 13:58:22.057885] INFO: join: /y_2017, 行数=743233/743233, 耗时=0.64183s
    [2019-01-30 13:58:22.117354] INFO: join: 最终行数: 1954477
    [2019-01-30 13:58:22.119265] INFO: bigquant: join.v3 运行完成[2.295813s].
    

    查看结果

    大盘的5日收益率计算值与其余抽取的因子合并在一张表中,如下所示

    In [18]:
    m8.data.read_df().tail(5)
    
    Out[18]:
    close_0 close_1 date instrument return_5 close_0 / close_1 benchmark_5day_ret
    743228 22.207243 22.626858 2017-12-29 603993.SHA 1.058462 0.981455 -0.005856
    743229 28.209347 29.296677 2017-12-29 603996.SHA 0.979266 0.962886 -0.005856
    743230 17.260906 17.337486 2017-12-29 603997.SHA 0.969880 0.995583 -0.005856
    743231 43.968544 44.361469 2017-12-29 603998.SHA 1.000000 0.991143 -0.005856
    743232 18.602217 18.674788 2017-12-29 603999.SHA 1.040595 0.996114 -0.005856