3 分钟快速生成代码
输入想法,AI 即刻生成可运行代码
在 QMT (迅投 Python API) 平台中,若需要获取期权合约的行权价、多空头保证金率、到期日以及合约乘数等详细参数,可以使用内置的 ContextInfo.get_option_detail_data() 函数。
ContextInfo.get_option_detail_dataContextInfo.get_option_detail_data(optioncode)
optioncode (str):期权合约代码,如 '10001506.SHO'。若传入空字符串 '',则默认获取当前主图的期权品种明细。返回一个 dict 字典,其中包含该期权合约的全面属性。核心 key 如下:
OptExercisePrice:期权行权价LongMarginRatio:多头保证金率ShortMarginRatio:空头保证金率MarginUnit:期权单位保证金ExpireDate:到期日EndDelivDate:期权行权终止日VolumeMultiple / OptUnit:合约乘数 / 期权合约单位optType:期权类型(CALL 认购 或 PUT 认沽)OptUndlCode:期权标的证券代码以下示例展示了如何在 handlebar 函数中读取并打印指定期权合约(如 '10001506.SHO')的详细数据:
#encoding:gbk
def init(ContextInfo):
pass
def handlebar(ContextInfo):
# 仅在最后一根 Bar 上执行输出
if not ContextInfo.is_last_bar():
return
option_code = '10001506.SHO'
# 获取期权合约明细
detail = ContextInfo.get_option_detail_data(option_code)
if detail:
print(f"--- 期权合约 {option_code} 属性明细 ---")
print(f"行权价格 (OptExercisePrice): {detail.get('OptExercisePrice')}")
print(f"多头保证金率 (LongMarginRatio): {detail.get('LongMarginRatio')}")
print(f"空头保证金率 (ShortMarginRatio): {detail.get('ShortMarginRatio')}")
print(f"单位保证金 (MarginUnit): {detail.get('MarginUnit')}")
print(f"到期日 (ExpireDate): {detail.get('ExpireDate')}")
print(f"期权类型 (optType): {detail.get('optType')}")
print(f"标的证券 (OptUndlCode): {detail.get('OptUndlCode')}")
print(f"合约乘数 (VolumeMultiple): {detail.get('VolumeMultiple')}")
else:
print(f"未能获取到期权合约 {option_code} 的详细信息,请检查代码或数据是否补充库完整。")
.SHO,深交所期权市场代码后缀为 .SZO。