3 分钟快速生成代码
输入想法,AI 即刻生成可运行代码
在 JoinQuant(聚宽)量化交易平台中,get_industry 函数用于查询指定股票在某一特定日期所所属的行业分类信息。
get_industry 函数返回一个 Python 字典(dict):
'000001.XSHE')。每个标的对应的嵌套字典中,包含以下多套行业分类体系:
| 分类代码字段 | 行业分类标准 | 包含属性 | 说明 |
|---|---|---|---|
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 |
证监会行业分类代码与名称 |
以查询 '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': '房地产业'}
}
}
在 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
date 参数支持字符串(YYYY-MM-DD)或 datetime 对象。若传入 datetime,其时分秒部分会被忽略。date 默认为当天,在回测环境中 date 默认随回测逻辑时间 context.current_dt 动态变化。print 打印包含中文的字典,可使用 print(repr(res).decode("unicode-escape")) 进行解码显示。