自定义因子分析

策略分享
标签: #<Tag:0x00007fcf721a7860>

(tiantianz) #1

可以自选因子进行分析,这里我选择当日收益率,在m9输入特征列表模块中定义factor=rank_return_0
在因子分析的特征列表模块中输入factor;

克隆策略

    {"Description":"实验创建于2020/2/14","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-140:features","SourceOutputPortId":"-70:data"},{"DestinationInputPortId":"-271:instruments","SourceOutputPortId":"-248:data"},{"DestinationInputPortId":"-278:input_data","SourceOutputPortId":"-271:data"},{"DestinationInputPortId":"-290:input_1","SourceOutputPortId":"-278:data"},{"DestinationInputPortId":"-140:user_factor_data","SourceOutputPortId":"-290:data_1"},{"DestinationInputPortId":"-271:features","SourceOutputPortId":"-298:data"},{"DestinationInputPortId":"-278:features","SourceOutputPortId":"-298:data"}],"ModuleNodes":[{"Id":"-70","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nfactor","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-70"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-70","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-140","ModuleId":"BigQuantSpace.factorlens.factorlens-v1","ModuleParameters":[{"Name":"title","Value":"因子分析: {factor_name}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-12-31","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"rebalance_period","Value":"22","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"stock_pool","Value":"沪深300","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"quantile_count","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"commission_rate","Value":0.0016,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"returns_calculation_method","Value":"累乘","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"无","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_price_limit_stocks","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_st_stocks","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_new_stocks","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"normalization","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"neutralization","Value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E8%A1%8C%E4%B8%9A%22%2C%22displayValue%22%3A%22%E8%A1%8C%E4%B8%9A%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%B8%82%E5%80%BC%22%2C%22displayValue%22%3A%22%E5%B8%82%E5%80%BC%22%2C%22selected%22%3Atrue%7D%5D%7D","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"metrics","Value":"%7B%22enumItems%22%3A%5B%7B%22value%22%3A%22%E5%9B%A0%E5%AD%90%E8%A1%A8%E7%8E%B0%E6%A6%82%E8%A7%88%22%2C%22displayValue%22%3A%22%E5%9B%A0%E5%AD%90%E8%A1%A8%E7%8E%B0%E6%A6%82%E8%A7%88%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%9B%A0%E5%AD%90%E5%88%86%E5%B8%83%22%2C%22displayValue%22%3A%22%E5%9B%A0%E5%AD%90%E5%88%86%E5%B8%83%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%9B%A0%E5%AD%90%E8%A1%8C%E4%B8%9A%E5%88%86%E5%B8%83%22%2C%22displayValue%22%3A%22%E5%9B%A0%E5%AD%90%E8%A1%8C%E4%B8%9A%E5%88%86%E5%B8%83%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%9B%A0%E5%AD%90%E5%B8%82%E5%80%BC%E5%88%86%E5%B8%83%22%2C%22displayValue%22%3A%22%E5%9B%A0%E5%AD%90%E5%B8%82%E5%80%BC%E5%88%86%E5%B8%83%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22IC%E5%88%86%E6%9E%90%22%2C%22displayValue%22%3A%22IC%E5%88%86%E6%9E%90%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E4%B9%B0%E5%85%A5%E4%BF%A1%E5%8F%B7%E9%87%8D%E5%90%88%E5%88%86%E6%9E%90%22%2C%22displayValue%22%3A%22%E4%B9%B0%E5%85%A5%E4%BF%A1%E5%8F%B7%E9%87%8D%E5%90%88%E5%88%86%E6%9E%90%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%9B%A0%E5%AD%90%E4%BC%B0%E5%80%BC%E5%88%86%E6%9E%90%22%2C%22displayValue%22%3A%22%E5%9B%A0%E5%AD%90%E4%BC%B0%E5%80%BC%E5%88%86%E6%9E%90%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%9B%A0%E5%AD%90%E6%8B%A5%E6%8C%A4%E5%BA%A6%E5%88%86%E6%9E%90%22%2C%22displayValue%22%3A%22%E5%9B%A0%E5%AD%90%E6%8B%A5%E6%8C%A4%E5%BA%A6%E5%88%86%E6%9E%90%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%9B%A0%E5%AD%90%E5%80%BC%E6%9C%80%E5%A4%A7%2F%E6%9C%80%E5%B0%8F%E8%82%A1%E7%A5%A8%22%2C%22displayValue%22%3A%22%E5%9B%A0%E5%AD%90%E5%80%BC%E6%9C%80%E5%A4%A7%2F%E6%9C%80%E5%B0%8F%E8%82%A1%E7%A5%A8%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%9B%A0%E5%AD%90%E5%80%BC%22%2C%22displayValue%22%3A%22%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%9B%A0%E5%AD%90%E5%80%BC%22%2C%22selected%22%3Atrue%7D%2C%7B%22value%22%3A%22%E5%A4%9A%E5%9B%A0%E5%AD%90%E7%9B%B8%E5%85%B3%E6%80%A7%E5%88%86%E6%9E%90%22%2C%22displayValue%22%3A%22%E5%A4%9A%E5%9B%A0%E5%AD%90%E7%9B%B8%E5%85%B3%E6%80%A7%E5%88%86%E6%9E%90%22%2C%22selected%22%3Atrue%7D%5D%7D","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-140"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"user_factor_data","NodeId":"-140"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-140","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-248","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2020-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2020-08-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":"-248"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-248","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-271","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":"-271"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-271"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-271","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-278","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":"-278"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-278"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-278","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-290","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read()\n df = df[['factor','date','instrument']]\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1)","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-290"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-290"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-290"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-290","OutputType":null},{"Name":"data_2","NodeId":"-290","OutputType":null},{"Name":"data_3","NodeId":"-290","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-298","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nfactor=rank_return_0\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-298"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-298","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"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='-70' Position='185,266,200,200'/><NodePosition Node='-140' Position='383,425,200,200'/><NodePosition Node='-248' Position='314,89,200,200'/><NodePosition Node='-271' Position='486,169,200,200'/><NodePosition Node='-278' Position='632,251,200,200'/><NodePosition Node='-290' Position='588,337,200,200'/><NodePosition Node='-298' Position='643.0394287109375,75.03941345214844,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]:
    # 本代码由可视化策略环境自动生成 2020年8月15日 15:31
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m8_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read()
        df = df[['factor','date','instrument']]
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1)
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m8_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    factor"""
    )
    
    m3 = M.instruments.v2(
        start_date='2020-01-01',
        end_date='2020-08-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m9 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    factor=rank_return_0
    """
    )
    
    m6 = M.general_feature_extractor.v7(
        instruments=m3.data,
        features=m9.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m7 = M.derived_feature_extractor.v3(
        input_data=m6.data,
        features=m9.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m8 = M.cached.v3(
        input_1=m7.data,
        run=m8_run_bigquant_run,
        post_run=m8_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m2 = M.factorlens.v1(
        features=m1.data,
        user_factor_data=m8.data_1,
        title='因子分析: {factor_name}',
        start_date='2019-01-01',
        end_date='2019-12-31',
        rebalance_period=22,
        stock_pool='沪深300',
        quantile_count=5,
        commission_rate=0.0016,
        returns_calculation_method='累乘',
        benchmark='无',
        drop_price_limit_stocks=True,
        drop_st_stocks=True,
        drop_new_stocks=True,
        normalization=True,
        neutralization=['行业', '市值'],
        metrics=['因子表现概览', '因子分布', '因子行业分布', '因子市值分布', 'IC分析', '买入信号重合分析', '因子估值分析', '因子拥挤度分析', '因子值最大/最小股票', '表达式因子值', '多因子相关性分析']
    )
    

    因子分析: factor

    { "type": "factor-track", "data": { "exprs": ["factor"], "options": {"BacktestInterval": ["2019-01-01", "2019-12-31"], "Benchmark": "none", "StockPool": "in_csi300_0", "DropSTStocks": 1, "DropPriceLimitStocks": 1, "DropNewStocks": 1, "QuantileCount": 5, "CommissionRates": 0.0016, "Normalization": 1, "Neutralization": "industry,size", "RebalancePeriod": 22, "ReturnsCalculationMethod": "cumprod", "_HASH": "4d97138db2d4abe309937f7bc5d20a69"} } }

    因子表现概览

      累计收益 近1年收益 近3月收益 近1月收益 近1周收益 昨日收益 最大回撤 盈亏比 胜率 夏普比率 收益波动率
    最小分位 5.81% 5.81% 5.81% 9.15% 2.91% 0.82% 3.77% 0.66 0.69 1.70 12.06%
    最大分位 6.76% 6.76% 6.76% 6.87% 2.34% 0.58% 2.91% 0.88 0.64 2.14 11.29%
    多空组合 -0.44% -0.44% -0.44% 1.06% 0.27% 0.12% 1.70% 0.60 0.59 -2.29 2.32%

    基本特征分析

    IC分析

    IC均值

    0.02

    IC标准差

    0.12

    IR值

    0.17

    |IC| > 0.02比率

    100.00%

    因子估值分析

    因子拥挤度分析

    因子值最小的20只股票 (2019-12-31)

    股票名称 股票代码 因子值
    世纪华通 002602.SZA 0.0123
    江西铜业 600362.SHA 0.0401
    同花顺 300033.SZA 0.0455
    浙商证券 601878.SHA 0.0465
    方大炭素 600516.SHA 0.0468
    白云机场 600004.SHA 0.0479
    中信建投 601066.SHA 0.0551
    美锦能源 000723.SZA 0.0693
    华泰证券 601688.SHA 0.0843
    中信证券 600030.SHA 0.0848
    招商证券 600999.SHA 0.0851
    信维通信 300136.SZA 0.0859
    顺丰控股 002352.SZA 0.0891
    三安光电 600703.SHA 0.0950
    三环集团 300408.SZA 0.0960
    海通证券 600837.SHA 0.0975
    铜陵有色 000630.SZA 0.0984
    兆易创新 603986.SHA 0.1059
    红塔证券 601236.SHA 0.1091
    东旭光电 000413.SZA 0.1096

    因子值最大的20只股票 (2019-12-31)

    股票名称 股票代码 因子值
    新希望 000876.SZA 0.9204
    福耀玻璃 600660.SHA 0.9230
    中兴通讯 000063.SZA 0.9238
    济川药业 600566.SHA 0.9312
    金隅集团 601992.SHA 0.9339
    中国电建 601669.SHA 0.9345
    大族激光 002008.SZA 0.9371
    中国交建 601800.SHA 0.9395
    新和成 002001.SZA 0.9403
    乐普医疗 300003.SZA 0.9417
    立讯精密 002475.SZA 0.9462
    工业富联 601138.SHA 0.9476
    海螺水泥 600585.SHA 0.9486
    葛洲坝 600068.SHA 0.9567
    牧原股份 002714.SZA 0.9588
    华兰生物 002007.SZA 0.9631
    九州通 600998.SHA 0.9682
    天风证券 601162.SHA 0.9708
    白云山 600332.SHA 0.9762
    天齐锂业 002466.SZA 0.9797