请问如何获取行业数据?


(ZjFy) #1

例如,行业的市盈率 和 某个股票属于哪个行业 等等


(大胡子) #2
克隆策略

文档:行业列表 ,可以通过该文档查阅某只股票属于哪个行业

    {"Description":"实验创建于2018/4/30","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-24:input_1","SourceOutputPortId":"-16:data_1"}],"ModuleNodes":[{"Id":"-8","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 df = D.history_data(['000001.SZA'],'2017-01-01','2017-01-10',['industry_sw_level1'])\n print('---'*30)\n print('查看000001属于哪个行业:')\n print(df)\n print('看出000001属于480000行业,该行业是银行业')\n return Outputs(data_1=None, data_2=None, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-8"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-8"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-8"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-8","OutputType":null},{"Name":"data_2","NodeId":"-8","OutputType":null},{"Name":"data_3","NodeId":"-8","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":1,"Comment":"查看480000,属于银行行业","CommentCollapsed":false},{"Id":"-16","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 start_date = '2017-01-10'\n end_date = '2017-01-10'\n fields = ['pe_ttm_0','industry_sw_level1_0','market_cap_0']\n instruments = D.instruments(start_date=start_date, end_date=end_date)\n df = D.features(instruments=instruments, start_date=start_date, end_date=end_date, fields=fields)\n print('---'*30)\n print('简单计算申万一级行业行业平均市盈率: ')\n print(df.groupby('industry_sw_level1_0').mean())\n ds = DataSource.write_df(df)\n return Outputs(data_1=ds, data_2=None, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-16"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-16"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-16"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-16","OutputType":null},{"Name":"data_2","NodeId":"-16","OutputType":null},{"Name":"data_3","NodeId":"-16","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":2,"Comment":"计算简单行业收益率","CommentCollapsed":false},{"Id":"-24","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"def calcu(tmp):\n tmp['weight'] = tmp['market_cap_0']/tmp['market_cap_0'].sum()\n return (tmp['weight']*tmp['pe_ttm_0']).sum()\n\n# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n df = input_1.read_df()\n print('---'*30)\n print('计算按市值加权后的行业市盈率: ')\n print(df.groupby('industry_sw_level1_0').apply(lambda df:calcu(df)))\n return Outputs(data_1=None, data_2=None, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-24"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-24"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-24"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-24","OutputType":null},{"Name":"data_2","NodeId":"-24","OutputType":null},{"Name":"data_3","NodeId":"-24","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":3,"Comment":"市值加权行业市盈率","CommentCollapsed":false}],"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='-8' Position='134,179,200,200'/><NodePosition Node='-16' Position='475,177,200,200'/><NodePosition Node='-24' Position='436,319,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 [11]:
    # 本代码由可视化策略环境自动生成 2018年4月30日 08:44
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m1_run_bigquant_run(input_1, input_2, input_3):   
        df = D.history_data(['000001.SZA'],'2017-01-01','2017-01-10',['industry_sw_level1'])
        print('---'*30)
        print('查看000001属于哪个行业:')
        print(df)
        print('看出000001属于480000行业,该行业是银行业')
        return Outputs(data_1=None, data_2=None, data_3=None)
    
    m1 = M.cached.v3(
        run=m1_run_bigquant_run,
        m_cached=False
    )
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m2_run_bigquant_run(input_1, input_2, input_3):
        
        start_date = '2017-01-10'
        end_date = '2017-01-10'
        fields = ['pe_ttm_0','industry_sw_level1_0','market_cap_0']
        instruments = D.instruments(start_date=start_date, end_date=end_date)
        df = D.features(instruments=instruments, start_date=start_date, end_date=end_date, fields=fields)
        print('---'*30)
        print('简单计算申万一级行业行业平均市盈率:   ')
        print(df.groupby('industry_sw_level1_0').mean())
        ds = DataSource.write_df(df)
        return Outputs(data_1=ds, data_2=None, data_3=None)
    
    m2 = M.cached.v3(
        run=m2_run_bigquant_run,
        m_cached=False
    )
    
    def calcu(tmp):
        tmp['weight'] = tmp['market_cap_0']/tmp['market_cap_0'].sum()
        return (tmp['weight']*tmp['pe_ttm_0']).sum()
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m3_run_bigquant_run(input_1, input_2, input_3):
        df = input_1.read_df()
        print('---'*30)
        print('计算按市值加权后的行业市盈率:   ')
        print(df.groupby('industry_sw_level1_0').apply(lambda df:calcu(df)))
        return Outputs(data_1=None, data_2=None, data_3=None)
    
    m3 = M.cached.v3(
        input_1=m2.data_1,
        run=m3_run_bigquant_run,
        m_cached=False
    )
    
    [2018-04-30 08:44:10.266659] INFO: bigquant: cached.v3 开始运行..
    ------------------------------------------------------------------------------------------
    查看000001属于哪个行业:
            date  industry_sw_level1  instrument
    0 2017-01-03              480000  000001.SZA
    1 2017-01-04              480000  000001.SZA
    2 2017-01-05              480000  000001.SZA
    3 2017-01-06              480000  000001.SZA
    4 2017-01-09              480000  000001.SZA
    5 2017-01-10              480000  000001.SZA
    看出000001属于480000行业,该行业是银行业
    [2018-04-30 08:44:10.279831] INFO: bigquant: cached.v3 运行完成[0.013216s].
    [2018-04-30 08:44:10.287284] INFO: bigquant: cached.v3 开始运行..
    ------------------------------------------------------------------------------------------
    简单计算申万一级行业行业平均市盈率:   
                             pe_ttm_0  market_cap_0
    industry_sw_level1_0                           
    0                       -5.964437  3.664042e+10
    110000                 213.452236  1.195096e+10
    210000                  96.741622  4.755603e+10
    220000                  96.347094  1.287148e+10
    230000                 -24.416614  2.099347e+10
    240000                  39.193150  1.563141e+10
    270000                 287.365204  1.224716e+10
    280000                 128.393798  1.770449e+10
    330000                  22.472964  1.783398e+10
    340000                -109.557767  2.189027e+10
    350000                  91.428753  9.136326e+09
    360000                  98.894392  9.328596e+09
    370000                  99.877993  1.464792e+10
    410000                  63.702341  1.787003e+10
    420000                 165.728186  2.143311e+10
    430000                  14.337929  1.890871e+10
    450000                 104.155256  1.339291e+10
    460000                 -46.194630  1.262648e+10
    480000                  10.354424  3.476530e+11
    490000                  33.978385  9.624002e+10
    510000                  34.731240  1.022285e+10
    610000                  58.705711  1.041096e+10
    620000                 189.052738  2.140947e+10
    630000                 156.005486  1.028531e+10
    640000                 122.652217  9.286052e+09
    650000                 232.026010  2.464220e+10
    710000                1248.940756  1.240813e+10
    720000                 111.281221  1.827789e+10
    730000                 -86.545723  1.339669e+10
    [2018-04-30 08:44:20.351069] INFO: bigquant: cached.v3 运行完成[10.063751s].
    [2018-04-30 08:44:20.360067] INFO: bigquant: cached.v3 开始运行..
    ------------------------------------------------------------------------------------------
    计算按市值加权后的行业市盈率:   
    industry_sw_level1_0
    0          -5.964437
    110000    132.646852
    210000    209.916377
    220000     77.401760
    230000    -16.635468
    240000     14.203028
    270000    163.787194
    280000     68.235973
    330000     32.093443
    340000      1.756613
    350000     60.127396
    360000     89.401538
    370000     88.202278
    410000     32.500819
    420000    285.493697
    430000     21.275428
    450000    177.094735
    460000     35.666585
    480000      6.549057
    490000     27.510644
    510000    131.541711
    610000     81.864644
    620000     58.705924
    630000    170.502511
    640000    109.724225
    650000    137.061143
    710000    762.799396
    720000     90.742706
    730000     10.546142
    dtype: float64
    [2018-04-30 08:44:20.547359] INFO: bigquant: cached.v3 运行完成[0.187263s].
    

    (ZjFy) #3

    恩,谢谢了