一、标的监控
QMT支持的市场有A股股票、指数、ETF、上证50/沪深300ETF期权、国内期货、国内期货期权、香港股票等,这里先设置好待监控标的,并定期更新。
1.1 A股股票指数以及ETF
获取 上证指数、深证成指、创业板指、科创50、上证50、沪深300、中证500、中证1000等主要指数ticker,以及活跃ETFticker
def get_a_index_etf():
indexes = ['000001.SH', '399001.SZ', '399006.SZ', '000688.SH', '000016.SH', '000300.SH', '000905.SH', '000852.SH']
etf = ["512100.SH", "510050.SH", "510300.SH", "513050.SH", "515790.SH", "563000.SH", "588000.SH", "513180.SH", "513060.SH", "159915.SZ", "512880.SH", "512010.SH", "512660.SH", "159949.SZ", "510500.SH", "512690.SH", "518880.SH", "511260.SH", "512480.SH", "512200.SH", "515030.SH", "511380.SH", "512000.SH", "510330.SH", "513130.SH", "513500.SH", "513100.SH", "512800.SH", "512760.SH", "159920.SZ", "159605.SZ", "159941.SZ", "162411.SZ", "513330.SH", "510900.SH", "513090.SH", "513550.SH"]
return indexes etf
1.2 A股重要指数成分股
获取沪深300(000300)、中证500(000905)、中证1000(000852)指数成分股
import akshare
def get_a_index_component():
hs300 = akshare.index_stock_cons_weight_csindex(symbol="000300")
hs300['stock'] = hs300.apply(lambda row: row['成分券代码'] '.' {'上海证券交易所' :'SH', '深圳证券交易所': 'SZ'}.get(row['交易所']), axis=1)
csi500 = akshare.index_stock_cons_weight_csindex(symbol="000905")
csi500['stock'] = csi500.apply(lambda row: row['成分券代码'] '.' {'上海证券交易所' :'SH', '深圳证券交易所': 'SZ'}.get(row['交易所']), axis=1)
csi1000 = akshare.index_stock_cons_weight_csindex(symbol="000852")
csi1000['stock'] = csi1000.apply(lambda row: row['成分券代码'] '.' {'上海证券交易所' :'SH', '深圳证券交易所': 'SZ'}.get(row['交易所']), axis=1)
hs300_component = hs300.set_index('stock')[['指数代码', '成分券名称', '权重']].to_dict('index')
csi500_component = csi500.set_index('stock')[['指数代码', '成分券名称', '权重']].to_dict('index')
csi1000_component = csi1000.set_index('stock')[['指数代码', '成分券名称', '权重']].to_dict('index')
return {**hs300_component, **csi500_component, **csi1000_component}
1.3 ETF期权
获取50ETF、300ETF对应的当月/次月期权ticker
import re, math, datetime
def get_etf_option():
select_option = {}
etf_price = {}
# 获取ETF行情
etf_tick = xtdata.get_full_tick(['510300.SH', '510050.SH', '159919.SZ'])
# 取今日开盘价/昨日收盘价均值
for code in ['510300.SH', '510050.SH', '159919.SZ']:
etf_price[code] = (etf_tick[code]['open'] etf_tick[code]['lastClose']) / 2
options = xtdata.get_stock_list_in_sector('上证期权') xtdata.get_stock_list_in_sector('深证期权')
# 获取主力期权(标的价格附近上下5档,当月/次月)
option_data = []
for code in options:
meta = xtdata.get_instrument_detail(code)
# 期权名称
name = meta['InstrumentName']
# 对应的ETF
etf = re.findall(r'\((\d )\)', meta['ProductID'])[0]
etf = {'510300': '510300.SH', '510050': '510050.SH', '159919': '159919.SZ'}.get(etf)
# 剩余有效日
days = (datetime.date(year=int(str(meta['ExpireDate'])[:4]), month=int(str(meta['ExpireDate'])[4:6]), day=int(str(meta['ExpireDate'])[6:8])) - datetime.date.today()).days
call_put = 'call' if '购' in name else 'put'
if days < 32:
if math.fabs(etf_price[etf] - int(name[-4:]) / 1000.0) < 0.2:
select_option[code] = [etf, call_put, int(name[-4:]), days]
elif days < 65:
if math.fabs(etf_price[etf] - int(name[-4:]) / 1000.0) < 0.25:
select_option[code] = [etf, call_put, int(name[-4:]), days]
return select_option
温馨提示:投资有风险,选择需谨慎。
版权及免责声明:本文内容由入驻叩富问财的作者自发贡献,该文观点仅代表作者本人,与本网站立场无关,不对您构成任何投资建议。用户应基于自己的独立判断,自行决策投资行为并承担全部风险。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至kf@cofool.com 举报,一经查实,本站将立刻删除。