如果查看单个股票的衍生特征呢?


(lzh41764176) #1

从别的平台参考,用表达式引擎计算衍生特征,想校验一下特征计算结果准确性。如何实现呢?
看了一下API,感觉有点乱。
简单来讲就是就是想取“000300.XSHG”当日的衍生特征值,做检验。能否给个demo呢?


(lzh41764176) #2

(-1*correlation(rank(delta(log(volume),1)),rank((close-open)/open),6))
这个因子是国泰191因子里的第一个因子,请问如何以衍生特征实现提取出来呢?
能否给个例子呢?


(iQuant) #3

您好,收到您的提问,我们已将问题分配至策略工程师,策略工程师会尽快为您解答。


(达达) #4
克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-106:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-106:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-113:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-113:input_data","SourceOutputPortId":"-106:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2011-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":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\n(-1*correlation(rank(delta(log(volume_0),1)),rank((close_0-open_0)/open_0),6))\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-106","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":0,"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":true,"moduleIdForCode":15,"Comment":"","CommentCollapsed":true},{"Id":"-113","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":"-113"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-113"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-113","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"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='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='211,64,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='576.046875,69.50521469116211,200,200'/><NodePosition Node='-106' Position='381,188,200,200'/><NodePosition Node='-113' Position='385,280,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 [1]:
    # 本代码由可视化策略环境自动生成 2019年1月16日 22:41
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.instruments.v2(
        start_date='2010-01-01',
        end_date='2011-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m3 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    (-1*correlation(rank(delta(log(volume_0),1)),rank((close_0-open_0)/open_0),6))
    """
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    [2019-01-16 22:40:57.599654] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-16 22:40:57.640826] INFO: bigquant: instruments.v2 运行完成[0.041192s].
    [2019-01-16 22:40:57.644407] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-16 22:40:57.649924] INFO: bigquant: 命中缓存
    [2019-01-16 22:40:57.651419] INFO: bigquant: input_features.v1 运行完成[0.007005s].
    [2019-01-16 22:40:57.668734] INFO: bigquant: general_feature_extractor.v7 开始运行..
    [2019-01-16 22:40:58.501575] INFO: 基础特征抽取: 年份 2010, 特征行数=431567
    [2019-01-16 22:40:59.105570] INFO: 基础特征抽取: 年份 2011, 特征行数=0
    [2019-01-16 22:40:59.117664] INFO: 基础特征抽取: 总行数: 431567
    [2019-01-16 22:40:59.120353] INFO: bigquant: general_feature_extractor.v7 运行完成[1.45162s].
    [2019-01-16 22:40:59.124125] INFO: bigquant: derived_feature_extractor.v3 开始运行..
    [2019-01-16 22:41:08.867612] INFO: derived_feature_extractor: 提取完成 (-1*correlation(rank(delta(log(volume_0),1)),rank((close_0-open_0)/open_0),6)), 9.591s
    [2019-01-16 22:41:08.972465] INFO: derived_feature_extractor: /y_2010, 431567
    [2019-01-16 22:41:09.206639] INFO: bigquant: derived_feature_extractor.v3 运行完成[10.0825s].
    
    In [4]:
    m16.data.read_df().tail()
    
    Out[4]:
    close_0 date instrument open_0 volume_0 (-1*correlation(rank(delta(log(volume_0),1)),rank((close_0-open_0)/open_0),6))
    431562 10.228234 2010-12-27 601999.SHA 10.469847 2428294 -0.450274
    431563 9.986623 2010-12-28 601999.SHA 10.228234 3478057 -0.128491
    431564 10.318839 2010-12-29 601999.SHA 9.976556 4042035 -0.462848
    431565 10.721525 2010-12-30 601999.SHA 10.318839 7371113 -0.536952
    431566 10.671189 2010-12-31 601999.SHA 10.691324 8071522 -0.377408

    (lzh41764176) #5

    哦哦,明白来,感谢!