想请教一下怎么定义基于分钟数据的日频因子

用户成长系列
新手专区
标签: #<Tag:0x00007fa1aa189748> #<Tag:0x00007fa1aa189608>

(user6503) #1

RT
想在股票多因子策略中加入基于5分钟bar线数据的日频因子,比如说 (10:30-11:00收益率/全天收益率),怎么实现呢?

btw,在模块文档中看到“高频特征抽取-分钟到日频 (feature_extractor_1m.v1)”这个模块,感觉这个模块是可以实现我的需求的,但是没有相关例子,可否提供相关例子呢?~


(adhaha111) #2

您好,这个模块还在测试中,暂时没有开放使用。
对于您的因子,可以使用数据源进行提取后,求出10:30-11:00收益率,再进行组合。

克隆策略
In [2]:
DataSource("bar30m_CN_STOCK_A").read("000001.SZA", start_date="2019-01-01", end_date="2020-01-10").head(10)
Out[2]:
date open close high low volume amount instrument
0 2019-01-02 10:00:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
1 2019-01-02 10:30:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
2 2019-01-02 11:00:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
3 2019-01-02 11:30:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
4 2019-01-02 13:30:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
5 2019-01-02 14:00:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
6 2019-01-02 14:30:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
7 2019-01-02 15:00:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
8 2019-01-03 10:00:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA
9 2019-01-03 10:30:00 9.34 9.34 9.34 9.34 0.0 0.0 000001.SZA

    {"Description":"实验创建于2020/8/19","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-301:input_data","SourceOutputPortId":"-283:data"},{"DestinationInputPortId":"-301:features","SourceOutputPortId":"-289:data"},{"DestinationInputPortId":"-35:data1","SourceOutputPortId":"-301:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-35:data"},{"DestinationInputPortId":"-54:features","SourceOutputPortId":"-41:data"},{"DestinationInputPortId":"-61:features","SourceOutputPortId":"-41:data"},{"DestinationInputPortId":"-54:instruments","SourceOutputPortId":"-45:data"},{"DestinationInputPortId":"-61:input_data","SourceOutputPortId":"-54:data"},{"DestinationInputPortId":"-35:data2","SourceOutputPortId":"-61:data"},{"DestinationInputPortId":"-86:features","SourceOutputPortId":"-81:data"}],"ModuleNodes":[{"Id":"-283","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"dragon_stock","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2020-1-1","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2020-7-1","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-283"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-283"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-283","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-289","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nin_lhb_10d + 1\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-289"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-289","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-301","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":"-301"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-301"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-301","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-35","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date,instrument","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":"-35"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-35"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-35","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-41","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nreturn_5\nreturn_10\nreturn_20\navg_amount_0/avg_amount_5\navg_amount_5/avg_amount_20\nrank_avg_amount_0/rank_avg_amount_5\nrank_avg_amount_5/rank_avg_amount_10\nrank_return_0\nrank_return_5\nrank_return_10\nrank_return_0/rank_return_5\nrank_return_5/rank_return_10\npe_ttm_0\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-41"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-41","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-45","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","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":"-45"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-45","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-54","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":"-54"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-54"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-54","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"Comment":"","CommentCollapsed":true},{"Id":"-61","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":"-61"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-61"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-61","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"Comment":"","CommentCollapsed":true},{"Id":"-81","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nreturn_5\nreturn_10\nreturn_20\navg_amount_0/avg_amount_5\navg_amount_5/avg_amount_20\nrank_avg_amount_0/rank_avg_amount_5\nrank_avg_amount_5/rank_avg_amount_10\nrank_return_0\nrank_return_5\nrank_return_10\nrank_return_0/rank_return_5\nrank_return_5/rank_return_10\npe_ttm_0\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-81"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-81","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"Comment":"","CommentCollapsed":true},{"Id":"-86","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":"-86"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-86"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-86","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"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='-283' Position='731.3524169921875,59.907015562057495,200,200'/><NodePosition Node='-289' Position='1037.874267578125,59.24792146682739,200,200'/><NodePosition Node='-301' Position='988.9554443359375,178.31583404541016,200,200'/><NodePosition Node='-35' Position='1217.4447021484375,363.27008056640625,200,200'/><NodePosition Node='-41' Position='1708.8453369140625,53.90456676483154,200,200'/><NodePosition Node='-45' Position='1357.9798583984375,51.546581983566284,200,200'/><NodePosition Node='-54' Position='1562.6514892578125,136.43344116210938,200,200'/><NodePosition Node='-61' Position='1558.8787841796875,223.20668029785156,200,200'/><NodePosition Node='-81' Position='1551.333251953125,355.7245178222656,200,200'/><NodePosition Node='-86' Position='1325.911376953125,470.79339599609375,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 [7]:
    # 本代码由可视化策略环境自动生成 2020年8月25日 09:26
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.use_datasource.v1(
        datasource_id='dragon_stock',
        start_date='2020-1-1',
        end_date='2020-7-1'
    )
    
    m2 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    in_lhb_10d + 1
    """
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m1.data,
        features=m2.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m5 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    return_5
    return_10
    return_20
    avg_amount_0/avg_amount_5
    avg_amount_5/avg_amount_20
    rank_avg_amount_0/rank_avg_amount_5
    rank_avg_amount_5/rank_avg_amount_10
    rank_return_0
    rank_return_5
    rank_return_10
    rank_return_0/rank_return_5
    rank_return_5/rank_return_10
    pe_ttm_0
    """
    )
    
    m6 = M.instruments.v2(
        start_date='',
        end_date='',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m7 = M.general_feature_extractor.v7(
        instruments=m6.data,
        features=m5.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m8 = M.derived_feature_extractor.v3(
        input_data=m7.data,
        features=m5.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m3 = M.join.v3(
        data1=m4.data,
        data2=m8.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m9 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    return_5
    return_10
    return_20
    avg_amount_0/avg_amount_5
    avg_amount_5/avg_amount_20
    rank_avg_amount_0/rank_avg_amount_5
    rank_avg_amount_5/rank_avg_amount_10
    rank_return_0
    rank_return_5
    rank_return_10
    rank_return_0/rank_return_5
    rank_return_5/rank_return_10
    pe_ttm_0
    """
    )
    
    m10 = M.derived_feature_extractor.v3(
        input_data=m3.data,
        features=m9.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )