# 导入dai
import dai
# 获取股票指数代码
sql = '''
select
distinct instrument,name
from cn_stock_index_component
where date > '2015-01-01'
'''
df = dai.query(sql).df()
df
# 上证50指数成分
sql = '''
select
date,
member_code as instrument
from cn_stock_index_component
where instrument = '000016.SH'
and date = '2024-05-30'
limit 10
'''
df = dai.query(sql).df()
df
# 沪深300指数成分
sql = '''
select
date,
member_code as instrument
from cn_stock_index_component
where instrument = '000300.SH'
and date = '2024-05-30'
limit 10
'''
df = dai.query(sql).df()
df
# 中证500指数成分
sql = '''
select
date,
member_code as instrument
from cn_stock_index_component
where instrument = '000905.SH'
and date = '2024-05-30'
limit 10
'''
df = dai.query(sql).df()
df
# 获取股票行业成分
# 申万行业通常取 industry=sw2021,即:申万行业分类标准 2021 版
sql = '''
select
distinct industry,industry_level1_code,industry_level1_name
from cn_stock_industry_component
where date > '2015-01-01' and industry = 'sw2021'
order by industry,industry_level1_name
'''
df = dai.query(sql).df()
df
# 获取国防军工行业股票列表
sql = '''
select
date,
instrument,industry_level1_code,industry_level1_name,industry_name,
from cn_stock_industry_component
where industry_level1_code = '650000' and industry = 'sw2021'
and date = '2024-05-30'
limit 10
'''
df = dai.query(sql).df()
df