克隆策略

    {"Description":"实验创建于2021/3/24","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-66:input_ds","SourceOutputPortId":"-31:data"},{"DestinationInputPortId":"-31:instruments","SourceOutputPortId":"-41:data"},{"DestinationInputPortId":"-51:input_1","SourceOutputPortId":"-41:data"},{"DestinationInputPortId":"-92:instruments","SourceOutputPortId":"-41:data"},{"DestinationInputPortId":"-103:input_1","SourceOutputPortId":"-51:data_1"},{"DestinationInputPortId":"-51:input_2","SourceOutputPortId":"-71:data"},{"DestinationInputPortId":"-103:input_2","SourceOutputPortId":"-76:data"},{"DestinationInputPortId":"-76:input_data","SourceOutputPortId":"-92:data"},{"DestinationInputPortId":"-92:features","SourceOutputPortId":"-98:data"},{"DestinationInputPortId":"-76:features","SourceOutputPortId":"-98:data"},{"DestinationInputPortId":"-110:input_data","SourceOutputPortId":"-103:data"},{"DestinationInputPortId":"-110:features","SourceOutputPortId":"-122:data"}],"ModuleNodes":[{"Id":"-31","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"# 做一个大盘收益率相对于个股的收益率的3天内相关系数因子\ncorrelation(benchmark_close/shift(benchmark_close,1),close/shift(close,1),3)","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.HIX","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na_label","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-31"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-31","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"方法1","CommentCollapsed":false},{"Id":"-41","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-10-31","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":"-41"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-41","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-51","ModuleId":"BigQuantSpace.index_feature_extract.index_feature_extract-v3","ModuleParameters":[{"Name":"before_days","Value":100,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"index","Value":"000300.HIX","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-51"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-51"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-51","OutputType":null},{"Name":"data_2","NodeId":"-51","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-66","ModuleId":"BigQuantSpace.rename_columns.rename_columns-v5","ModuleParameters":[{"Name":"columns","Value":"label:factor","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"keep_old_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-66"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-66","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-71","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nbm_ret=close/shift(close,1)","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-71"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-71","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-76","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":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-76"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-76"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-76","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-92","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":"-92"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-92"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-92","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"Comment":"","CommentCollapsed":true},{"Id":"-98","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nret=close_0/close_1\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-98"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-98","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"Comment":"","CommentCollapsed":true},{"Id":"-103","ModuleId":"BigQuantSpace.data_join.data_join-v3","ModuleParameters":[{"Name":"on","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"right","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-103"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-103"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-103","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"","CommentCollapsed":true},{"Id":"-110","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":"-110"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-110"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-110","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"","CommentCollapsed":true},{"Id":"-122","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nfactor=correlation(bm_ret,ret,3)","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-122"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-122","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"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='-31' Position='86,286,200,200'/><NodePosition Node='-41' Position='186.54165649414062,31.486122131347656,200,200'/><NodePosition Node='-51' Position='398.5555419921875,321.6388854980469,200,200'/><NodePosition Node='-66' Position='65,401,200,200'/><NodePosition Node='-71' Position='446.4305419921875,131.48609924316406,200,200'/><NodePosition Node='-76' Position='706.638916015625,325.45831298828125,200,200'/><NodePosition Node='-92' Position='701.4583129882812,244.52780151367188,200,200'/><NodePosition Node='-98' Position='751.5416259765625,134.3958282470703,200,200'/><NodePosition Node='-103' Position='593.611083984375,415.673583984375,200,200'/><NodePosition Node='-110' Position='689.2916870117188,522.8818969726562,200,200'/><NodePosition Node='-122' Position='881.8055419921875,414.52081298828125,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 [33]:
    # 本代码由可视化策略环境自动生成 2021年3月24日16:02
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m2 = M.instruments.v2(
        start_date='2019-01-01',
        end_date='2019-10-31',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m1 = M.advanced_auto_labeler.v2(
        instruments=m2.data,
        label_expr="""# 做一个大盘收益率相对于个股的收益率的3天内相关系数因子
    correlation(benchmark_close/shift(benchmark_close,1),close/shift(close,1),3)""",
        start_date='',
        end_date='',
        benchmark='000300.HIX',
        drop_na_label=True,
        cast_label_int=False,
        user_functions={}
    )
    
    m4 = M.rename_columns.v5(
        input_ds=m1.data,
        columns='label:factor',
        keep_old_columns=False
    )
    
    m5 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    bm_ret=close/shift(close,1)"""
    )
    
    m3 = M.index_feature_extract.v3(
        input_1=m2.data,
        input_2=m5.data,
        before_days=100,
        index='000300.HIX'
    )
    
    m9 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    ret=close_0/close_1
    """
    )
    
    m8 = M.general_feature_extractor.v7(
        instruments=m2.data,
        features=m9.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m6 = M.derived_feature_extractor.v3(
        input_data=m8.data,
        features=m9.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=True,
        user_functions={}
    )
    
    m10 = M.data_join.v3(
        input_1=m3.data_1,
        input_2=m6.data,
        on='date',
        how='right',
        sort=False
    )
    
    m13 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    factor=correlation(bm_ret,ret,3)"""
    )
    
    m11 = M.derived_feature_extractor.v3(
        input_data=m10.data,
        features=m13.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    In [31]:
    # 自动标注方法的计算结果factor
    m4.data.read()[['date','instrument','factor']].head(10)
    
    Out[31]:
    date instrument factor
    0 2019-01-07 000001.SZA 0.879492
    1 2019-01-07 000002.SZA 0.934842
    2 2019-01-07 000004.SZA 0.158294
    3 2019-01-07 000005.SZA 0.565058
    4 2019-01-07 000006.SZA 0.892669
    5 2019-01-07 000007.SZA 0.872186
    6 2019-01-07 000008.SZA 0.354121
    7 2019-01-07 000009.SZA 0.887204
    8 2019-01-07 000010.SZA 0.298599
    9 2019-01-07 000011.SZA 0.303374
    In [35]:
    # 逐步抽取法的计算结果
    df = m11.data.read()
    df[df.date=='2019-01-07'][['date','instrument','factor']].head(10)
    
    Out[35]:
    date instrument factor
    210564 2019-01-07 000001.SZA 0.879492
    210765 2019-01-07 000002.SZA 0.934842
    210966 2019-01-07 000004.SZA 0.158294
    211157 2019-01-07 000005.SZA 0.565058
    211358 2019-01-07 000006.SZA 0.892669
    211559 2019-01-07 000007.SZA 0.872186
    211760 2019-01-07 000008.SZA 0.354121
    211961 2019-01-07 000009.SZA 0.887204
    212162 2019-01-07 000010.SZA 0.298599
    212362 2019-01-07 000011.SZA 0.303374