- #coding:gbk
- def after_init(C):
- etf_code = '510050.SH' #etf品种代码
- option_codes =C.get_option_undl_data(etf_code)
- print('期权合约列表', option_codes)
- all_option_list = []
- for code in option_codes:
- #print(code, C.get_stock_name(code), C.get_option_detail_data(code)['ExpireDate'])
- detail = C.get_option_detail_data(code)
- #print(detail)
- exp_date = detail['ExpireDate']
- strike_price = detail['OptExercisePrice']
- opt_type = detail['optType']
- name = C.get_stock_name(code)
- line = [code, exp_date, strike_price, opt_type, name]
- all_option_list.append(line)
- all_dates = list(set([i[1] for i in all_option_list]))
- all_dates.sort()
- current_month = all_dates[0]
- next_month = all_dates[1]
- current_month_call = [i for i in all_option_list if i[1] == current_month and i[3] == 'CALL']
- current_month_put = [i for i in all_option_list if i[1] == current_month and i[3] == 'PUT']
- next_month_call = [i for i in all_option_list if i[1] == next_month and i[3] == 'CALL']
- next_month_put = [i for i in all_option_list if i[1] == next_month and i[3] == 'PUT']
- current_month_call.sort(key = lambda x:x[2])
- current_month_put.sort(key = lambda x:x[2])
- next_month_call.sort(key = lambda x:x[2])
- next_month_put.sort(key = lambda x:x[2])
- current_month, next_month = str(current_month), str(next_month)
- print(current_month, '当月认购', current_month_call)
- print(current_month, '当月认沽', current_month_put)
- print(next_month,'下月认购', next_month_call)
- print(next_month,'下月认沽', next_month_put)
-
- #获取etf当前价格
- full_tick = C.get_full_tick([etf_code])
- etf_price = full_tick[etf_code]['lastPrice']
-
- in_the_money_call = [i for i in current_month_call if i[2] <= etf_price]
- out_the_money_call = [i for i in current_month_call if i[2] > etf_price]
- in_the_money_put = [i for i in current_month_put if i[2] >= etf_price]
- out_the_money_put = [i for i in current_month_put if i[2] < etf_price]
- print('当月实值认购', in_the_money_call, '虚值认购', out_the_money_call)
- print('当月实值认沽', in_the_money_put, '虚值认沽', out_the_money_put)
复制代码
不清楚的内容可添加下方助理微信咨询,有其他 QMT 小技巧想学习的吗?欢迎在下方留言,笔者将根据大家的留言持续更新哦! 欢迎和我一起加入迅投组建的 QMT 实战交流社群,交流群内有许多做量化交易的高手和大佬,具有良好的分享和互助氛围。且迅投官方会不定期为多次分享、乐于助人的群友申请送投研专业版的机会。 只需扫描下方的二维码,名额有限,限时加入。一起分享见解、交换信息、并共同进步,就像群友说的:“就算周末,晚上也有地方沟通交流!” |