🚀 AI 一键生成 joinquant 策略代码
立即体验

joinquant 股票行业查询:get_industry 函数返回值结构与解析

joinquant | 发布时间: 2026/7/30
以下内容由 EasyQuant 生成。

问题描述

请根据以下 SEO 主题生成完整页面内容:

Title: joinquant 股票行业查询:get_industry 函数返回值结构与解析

Question: joinquant 中 get_industry 函数返回的字典包含哪些行业分类信息?

解决方案

joinquant 股票行业查询:get_industry 函数返回值结构与解析

在 JoinQuant(聚宽)量化交易平台中,get_industry 函数用于查询指定股票在某一特定日期所所属的行业分类信息。


一、get_industry 返回值结构

get_industry 函数返回一个 Python 字典(dict)

  • Key(键):标的代码(如 '000001.XSHE')。
  • Value(值):包含该股票在多种分类标准下行业信息的嵌套字典。

行业分类字段说明

每个标的对应的嵌套字典中,包含以下多套行业分类体系:

分类代码字段 行业分类标准 包含属性 说明
sw_l1 申万一级行业 industry_code, industry_name 申万一级行业代码与名称
sw_l2 申万二级行业 industry_code, industry_name 申万二级行业代码与名称
sw_l3 申万三级行业 industry_code, industry_name 申万三级行业代码与名称
jq_l1 聚宽一级行业 industry_code, industry_name 聚宽自定义一级行业代码与名称
jq_l2 聚宽二级行业 industry_code, industry_name 聚宽自定义二级行业代码与名称
zjw 证监会行业 industry_code, industry_name 证监会行业分类代码与名称

二、返回值 JSON 结构示例

以查询 '000001.XSHE'(平安银行)和 '000002.XSHE'(万科A)在 2018-06-01 的行业信息为例,返回结果结构如下:

{
  '000001.XSHE': {
    'jq_l1': {'industry_code': 'HY007', 'industry_name': '金融指数'},
    'jq_l2': {'industry_code': 'HY493', 'industry_name': '多元化银行指数'},
    'sw_l1': {'industry_code': '801780', 'industry_name': '银行I'},
    'sw_l2': {'industry_code': '801192', 'industry_name': '银行II'},
    'sw_l3': {'industry_code': '851911', 'industry_name': '银行III'},
    'zjw': {'industry_code': 'J66', 'industry_name': '货币金融服务'}
  },
  '000002.XSHE': {
    'jq_l1': {'industry_code': 'HY011', 'industry_name': '房地产指数'},
    'jq_l2': {'industry_code': 'HY509', 'industry_name': '房地产开发指数'},
    'sw_l1': {'industry_code': '801180', 'industry_name': '房地产I'},
    'sw_l2': {'industry_code': '801181', 'industry_name': '房地产开发II'},
    'sw_l3': {'industry_code': '851811', 'industry_name': '房地产开发III'},
    'zjw': {'industry_code': 'K70', 'industry_name': '房地产业'}
  }
}

三、Python 使用示例

在 JoinQuant 策略或研究环境中,可以通过如下代码获取并解析股票的行业分类:

# 查询指定股票在指定日期的行业信息
res = get_industry(security=['000001.XSHE', '000002.XSHE'], date='2018-06-01')

# 获取平安银行的申万一级行业名称
payh_sw1 = res['000001.XSHE']['sw_l1']['industry_name']
print(f'平安银行申万一级行业:{payh_sw1}') # 输出:银行I

# 获取万科A的证监会行业代码
wka_zjw_code = res['000002.XSHE']['zjw']['industry_code']
print(f'万科A证监会行业代码:{wka_zjw_code}') # 输出:K70

四、注意事项

  1. 时间参数说明date 参数支持字符串(YYYY-MM-DD)或 datetime 对象。若传入 datetime,其时分秒部分会被忽略。
  2. 默认日期:在研究环境中 date 默认为当天,在回测环境中 date 默认随回测逻辑时间 context.current_dt 动态变化。
  3. Python 2 格式化输出提示:若在 Python 2 环境中使用 print 打印包含中文的字典,可使用 print(repr(res).decode("unicode-escape")) 进行解码显示。