请教如何实现两个数据连接时一一对应?

新手专区
标签: #<Tag:0x00007fb12b968bb8>

(189) #1

我的意思很简单,就是510300对应另外一边的000300,等等

克隆策略
In [25]:
m2.data.read_df().tail()
Out[25]:
date instrument_x close_x mean(close,5)_x instrument_y close_y mean(close,5)_y
1900 2019-11-15 000300.HIX 3877.089111 3897.918896 510500.HOF 5.267 5.2734
1901 2019-11-15 000300.HIX 3877.089111 3897.918896 510300.HOF 3.943 3.9586
1902 2019-11-15 000905.HIX 4868.436523 4882.772070 510050.HOF 3.003 3.0122
1903 2019-11-15 000905.HIX 4868.436523 4882.772070 510500.HOF 5.267 5.2734
1904 2019-11-15 000905.HIX 4868.436523 4882.772070 510300.HOF 3.943 3.9586

    {"Description":"实验创建于2019/11/19","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-6453:instruments","SourceOutputPortId":"-5:data"},{"DestinationInputPortId":"-6489:instruments","SourceOutputPortId":"-6437:data"},{"DestinationInputPortId":"-6471:input_data","SourceOutputPortId":"-6453:data"},{"DestinationInputPortId":"-6453:features","SourceOutputPortId":"-6459:data"},{"DestinationInputPortId":"-6471:features","SourceOutputPortId":"-6459:data"},{"DestinationInputPortId":"-6480:features","SourceOutputPortId":"-6459:data"},{"DestinationInputPortId":"-6489:features","SourceOutputPortId":"-6459:data"},{"DestinationInputPortId":"-6446:data1","SourceOutputPortId":"-6471:data"},{"DestinationInputPortId":"-6446:data2","SourceOutputPortId":"-6480:data"},{"DestinationInputPortId":"-6480:input_data","SourceOutputPortId":"-6489:data"}],"ModuleNodes":[{"Id":"-5","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-11-15","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_FUND","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"510300.HOF\n510050.HOF\n510500.HOF\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-5"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-5","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-6437","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-11-15","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000300.HIX\n000016.HIX\n000905.HIX\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-6437"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6437","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"-6446","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":"-6446"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-6446"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6446","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-6453","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_CN_FUND","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-6453"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-6453"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6453","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-6459","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nmean(close,5)","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-6459"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6459","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-6471","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":"-6471"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-6471"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6471","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"Comment":"","CommentCollapsed":true},{"Id":"-6480","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":"-6480"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-6480"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6480","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"Comment":"","CommentCollapsed":true},{"Id":"-6489","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":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-6489"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-6489"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-6489","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"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='-5' Position='-110.70603942871094,63.41117477416992,200,200'/><NodePosition Node='-6437' Position='604.007194519043,32.4265022277832,200,200'/><NodePosition Node='-6446' Position='250.58248901367188,527.4982299804688,200,200'/><NodePosition Node='-6453' Position='-9.091079711914062,226.1339111328125,200,200'/><NodePosition Node='-6459' Position='213.65643310546875,-34.73083829879761,200,200'/><NodePosition Node='-6471' Position='31.408477783203125,334.52978515625,200,200'/><NodePosition Node='-6480' Position='529.3300170898438,353.57391357421875,200,200'/><NodePosition Node='-6489' Position='592.4617462158203,222.5460205078125,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 [24]:
    # 本代码由可视化策略环境自动生成 2019年11月19日 01:23
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m3 = M.instruments.v2(
        start_date='2019-01-01',
        end_date='2019-11-15',
        market='CN_FUND',
        instrument_list="""510300.HOF
    510050.HOF
    510500.HOF
    """,
        max_count=0
    )
    
    m1 = M.instruments.v2(
        start_date='2019-01-01',
        end_date='2019-11-15',
        market='CN_STOCK_A',
        instrument_list="""000300.HIX
    000016.HIX
    000905.HIX
    """,
        max_count=0
    )
    
    m5 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    mean(close,5)"""
    )
    
    m4 = M.use_datasource.v1(
        instruments=m3.data,
        features=m5.data,
        datasource_id='bar1d_CN_FUND',
        start_date='',
        end_date=''
    )
    
    m7 = M.derived_feature_extractor.v3(
        input_data=m4.data,
        features=m5.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m9 = M.use_datasource.v1(
        instruments=m1.data,
        features=m5.data,
        datasource_id='bar1d_index_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m8 = 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.join.v3(
        data1=m7.data,
        data2=m8.data,
        on='date',
        how='inner',
        sort=False
    )
    

    (xysgs) #2

    你这个是将数据进行上下合并,应该用数据合并模块,拖进去,连接上数据,直接运行就可以了。


    (189) #3

    多谢,我是想instrment_x对应000300,然后instrument_y对应510300,同一行所以要左右合并,目前的情况是不能按顺序排列,不知道为什么不能按照我在股票代码列表那里的排序?