返回列表 发布新帖

获取期权合约列表与合约信息

1812 1
发表于 2024-1-6 10:54:37 | 显示全部楼层 阅读模式
image.png

  1. #coding:gbk

  2. def after_init(C):
  3.         etf_code = '510050.SH' #etf品种代码
  4.         option_codes =C.get_option_undl_data(etf_code)
  5.         print('期权合约列表', option_codes)
  6.         all_option_list = []
  7.         for code in option_codes:
  8.                 #print(code, C.get_stock_name(code), C.get_option_detail_data(code)['ExpireDate'])
  9.                 detail = C.get_option_detail_data(code)
  10.                 #print(detail)
  11.                 exp_date = detail['ExpireDate']
  12.                 strike_price = detail['OptExercisePrice']
  13.                 opt_type = detail['optType']
  14.                 name = C.get_stock_name(code)
  15.                 line = [code, exp_date, strike_price, opt_type, name]
  16.                 all_option_list.append(line)
  17.         all_dates = list(set([i[1] for i in all_option_list]))
  18.         all_dates.sort()
  19.         current_month = all_dates[0]
  20.         next_month = all_dates[1]
  21.         current_month_call = [i for i in all_option_list if i[1] == current_month and i[3] == 'CALL']
  22.         current_month_put = [i for i in all_option_list if i[1] == current_month and i[3] == 'PUT']
  23.         next_month_call = [i for i in all_option_list if i[1] == next_month and i[3] == 'CALL']
  24.         next_month_put = [i for i in all_option_list if i[1] == next_month and i[3] == 'PUT']
  25.         current_month_call.sort(key = lambda x:x[2])
  26.         current_month_put.sort(key = lambda x:x[2])
  27.         next_month_call.sort(key = lambda x:x[2])
  28.         next_month_put.sort(key = lambda x:x[2])
  29.         current_month, next_month = str(current_month), str(next_month)
  30.         print(current_month, '当月认购', current_month_call)
  31.         print(current_month, '当月认沽', current_month_put)
  32.         print(next_month,'下月认购', next_month_call)
  33.         print(next_month,'下月认沽', next_month_put)
  34.         
  35.         #获取etf当前价格
  36.         full_tick =  C.get_full_tick([etf_code])
  37.         etf_price = full_tick[etf_code]['lastPrice']
  38.         
  39.         in_the_money_call = [i for i in current_month_call if i[2] <= etf_price]
  40.         out_the_money_call = [i for i in current_month_call if i[2] > etf_price]
  41.         in_the_money_put = [i for i in current_month_put if i[2] >= etf_price]
  42.         out_the_money_put = [i for i in current_month_put if i[2] < etf_price]
  43.         print('当月实值认购', in_the_money_call, '虚值认购', out_the_money_call)
  44.         print('当月实值认沽', in_the_money_put, '虚值认沽', out_the_money_put)
复制代码

不清楚的内容可添加下方助理微信咨询,有其他 QMT 小技巧想学习的吗?欢迎在下方留言,笔者将根据大家的留言持续更新哦!
欢迎和我一起加入迅投组建的 QMT 实战交流社群,交流群内有许多做量化交易的高手和大佬,具有良好的分享和互助氛围。且迅投官方会不定期为多次分享、乐于助人的群友申请送投研专业版的机会。
只需扫描下方的二维码,名额有限,限时加入。一起分享见解、交换信息、并共同进步,就像群友说的:“就算周末,晚上也有地方沟通交流!”
企业微信截图_17235220909173.png

评论1

*******6310楼主
发表于 2024-1-6 11:39:35 | 显示全部楼层
  1. {'50ETF(510050)' : '000016.SH',
  2.         '300ETF(510300)' : '000300.SH',
  3.         '500ETF(510500)' : '000905.SH',
  4.         '科创50(588000)' : '000688.SH',
  5.         '科创板50(588080)' : '000688.SH',
  6.         '深证100ETF(159901)' '399330.SZ':,
  7.         '创业板ETF(159915)' : '399673.SZ',
  8.         '沪深300ETF(159919)' '399300.SZ':,
  9.         '中证500ETF(159922)' : '399905.SZ'}
复制代码


有期权的etf对应的指数代码
客服专线

400-080-8112

用思考的速度交易,用真诚的态度合作,我们是认真的!
  • 关注公众号
  • 添加微信客服
Copyright © 2001-2025 迅投QMT社区 版权所有 All Rights Reserved. 蜀ICP备19002686号-2
关灯
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表