FRM模型十六:期权策略(期权组合)

2024-03-15 06:04

本文主要是介绍FRM模型十六:期权策略(期权组合),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

    • 备兑看涨期权(Covered Call)
    • 保护看跌期权(protective put)
    • 牛市价差套利
    • 熊市价差套利
    • 写在后面

本文所有代码基于windAPI,复现前先下载客户端并注册账号

备兑看涨期权(Covered Call)

构成:标的资产的多头 + 欧式看涨期权空头
损益:当标的资产市场价格上涨时,标的资产多头获利,看涨期权空头不行权。
当标的资产价格下降时,标的资产多头亏损,看涨期权行权获利弥补多头方损失。

头寸损益
标的资产多头 S T − S 0 S_{T}-S_{0} STS0
看涨期权空头 C − m a x ( S T − K , 0 ) C-max(S_{T}-K,0) Cmax(STK,0)
整体策略 S T − S 0 − m a x ( S T − K , 0 ) + C S_{T}-S_{0}-max(S_{T}-K,0)+C STS0max(STK,0)+C

其中 S T S_{T} ST表示T时刻的市价,K表示执行价,C表示看涨期权价格。损益图如下所示。

在这里插入图片描述
代码实现:

def CoveredCall(UnderlyingCode, OptionCode,StartTime):'''UndelyingCode:标的资产代码OptionCode:对冲期权的代码StartTime:开始回测时间'''error_code, wsd_data = w.wsd(OptionCode, "exe_price,exe_enddate,close,exe_ratio", StartTime, StartTime, usedf=True)StrikePrice = wsd_data['EXE_PRICE'][0]StrikeTime = wsd_data['EXE_ENDDATE'][0]OptionPrice = wsd_data['CLOSE'][0]Ratio = wsd_data['EXE_RATIO'][0]# 取当前系统时间current_time = datetime.datetime.now()# 比较行权日和当前,如果行权日晚于当前时间,只能回测到当前时间,否则可以回测到行权日。if current_time > StrikeTime:BacktestTime = StrikeTimeelse:BacktestTime = current_time# 定义合约份数N_ETF = 10000N_option = 1# 取行情数据error_code, etf_data = w.wsd(UnderlyingCode, "close", StartTime, BacktestTime, usedf=True)S0 = etf_data['CLOSE'][0]Payoff = (etf_data - S0) * N_ETF + N_option * OptionPrice - np.max(etf_data - StrikePrice, 0) * RatioPayoff.plot(legend=None)plt.xlabel('Time', fontsize=8)plt.xticks(rotation=45)plt.ylabel('Payoff', fontsize=8)plt.show()if __name__ == "__main__":UnderlyingCode = "510050.SH"OptionCode = "10005337.SH"StartTime = "2023-04-27"CoveredCall(UnderlyingCode, OptionCode, StartTime)

随着到期日临近,策略损益变化如下图:
请添加图片描述

保护看跌期权(protective put)

构成:标的资产多头+看跌期权多头
损益:当标的资产市场价格上涨时,标的资产多头获利,看跌期权多头不行权,损失期权费。
当标的资产价格下降时,标的资产多头亏损,看跌期权行权获利弥补空头方损失。

头寸损益
标的资产多头 S T − S 0 S_{T}-S_{0} STS0
看跌期权多头 m a x ( K − S T , 0 ) − C max(K-S_{T},0)-C max(KST,0)C
整体策略 S T − S 0 + m a x ( S T − K , 0 ) − C S_{T}-S_{0}+max(S_{T}-K,0)-C STS0+max(STK,0)C

在这里插入图片描述
代码实现:

def ProtectedPut(UnderlyingCode, OptionCode,StartTime):'''UndelyingCode:标的资产代码OptionCode:对冲期权的代码StartTime:开始回测时间'''error_code, wsd_data = w.wsd(OptionCode, "exe_price,exe_enddate, close,exe_ratio", StartTime, StartTime, usedf=True)StrikePrice = wsd_data['EXE_PRICE'][0]StrikeTime = wsd_data['EXE_ENDDATE'][0]OptionPrice = wsd_data['CLOSE'][0]Ratio = wsd_data['EXE_RATIO'][0]# 取当前系统时间current_time = datetime.datetime.now()# 比较行权日和当前,如果行权日晚于当前时间,只能回测到当前时间,否则可以回测到行权日。if current_time > StrikeTime:BacktestTime = StrikeTimeelse:BacktestTime = current_time# 定义合约份数N_etf = 10000N_option = 1# 取现货价格序列error_code, etf_data = w.wsd(UnderlyingCode, "close", StartTime, BacktestTime,  usedf=True)S0 = etf_data['CLOSE'][0]payoff = -N_option * OptionPrice + N_option * np.max(StrikePrice - etf_data) * Ratio + (etf_data - S0) * N_etfpayoff.plot(legend=None)plt.xlabel('Time', fontsize=8)plt.xticks(rotation=45)plt.ylabel('Payoff', fontsize=8)plt.show()if __name__ == "__main__":OptionCode = "10005338.SH"UnderlyingCode = "510050.SH"StartTime = "2023-04-27"ProtectedPut(UnderlyingCode, OptionCode, StartTime)

随着到期日临近,策略损益变化如下图:
请添加图片描述

牛市价差套利

构成:买入行权价低的看涨期权/看跌期权,卖出行权价高的看涨期权/看跌期权,即低买高卖。
损益:以看涨期权为例,当标的资产价格上涨时,看涨期权的多头方获利,空头方亏损。

头寸损益
低行权价看涨期权多头 m a x ( S t − K l o w , 0 ) − C 1 max(S_{t}-K_{low},0)-C1 max(StKlow,0)C1
高行权价看涨期权空头 C 2 − m a x ( S t − K h i g h , 0 ) C2-max(S_{t}-K_{high},0) C2max(StKhigh,0)
整体策略 C 2 − C 1 + m a x ( S t − K l o w , 0 ) − m a x ( S t − K h i g h , 0 ) C2-C1+max(S_{t}-K_{low},0)-max(S_{t}-K_{high},0) C2C1+max(StKlow,0)max(StKhigh,0)

整体损益情况如下图所示:
在这里插入图片描述
代码实现:

############################ BullSpread
def BullSpread(UnderlyingCode, code_high_strike, code_low_strike):'''UnderlyingCode:标的资产代码code_high_strike:行权价高的期权代码code_low_strike:行权价低的期权代码:return:'''# 取期权基本数据error_code, wss_data = w.wss(code_high_strike, "startdate,lasttradingdate", usedf=True)       # 取期权的上市时间及结束时间StartDate = wss_data['STARTDATE'][0]EndDate = wss_data['LASTTRADINGDATE'][0]# 取期权价格及执行价error_code, high_strike_data = w.wsd(code_high_strike, "exe_price,close,exe_ratio,exe_mode", StartDate, StartDate, usedf=True)error_code, low_strike_data = w.wsd(code_low_strike, "exe_price,close,exe_ratio,exe_mode", StartDate, StartDate, usedf=True)K_high = high_strike_data['EXE_PRICE'][0]K_low = low_strike_data['EXE_PRICE'][0]OptionPrice_high_strike = high_strike_data['CLOSE'][0]OptionPrice_low_strike = low_strike_data['CLOSE'][0]Type = high_strike_data['EXE_MODE'][0]Ratio_high_strike = high_strike_data['EXE_RATIO'][0]Ratio_low_strike = low_strike_data['EXE_RATIO'][0]# 取标的资产价格数据error_code, etf_data = w.wsd(UnderlyingCode, "close", StartDate, EndDate,  usedf=True)# 定义合约份数N_option = 1# 判断期权是看涨还是看跌if Type == "认购":Payoff = N_option * OptionPrice_high_strike - np.maximum(etf_data - K_high, 0) * Ratio_high_strike - N_option * OptionPrice_low_strike + np.maximum(etf_data - K_low, 0) * Ratio_low_strikeelif Type == "认沽":Payoff = N_option * OptionPrice_high_strike - np.maximum(K_high - etf_data, 0) * Ratio_high_strike - N_option * OptionPrice_low_strike + np.maximum(K_low - etf_data, 0) * Ratio_low_strikeelse:print("期权类型判断有误")Payoff.plot(legend=None)plt.xlabel('Time', fontsize=8)plt.xticks(rotation=45)plt.ylabel('Payoff', fontsize=8)plt.show()if __name__ == "__main__":code_high_strike = "10006371.SH"code_low_strike = "10006365.SH"UnderlyingCode = "510050.SH"BullSpread(UnderlyingCode, code_high_strike, code_low_strike)

随着到期日临近,策略损益变化如下图:
请添加图片描述

熊市价差套利

构成:卖出行权价低的看涨期权/看跌期权,买入行权价高的看涨期权/看跌期权,即低买高卖。
损益:以看涨期权为例,当标的资产价格上涨时,看涨期权的多头方获利,空头方亏损。

头寸损益
低行权价看涨期权空头 C 1 − m a x ( S t − K l o w , 0 ) C1-max(S_{t}-K_{low},0) C1max(StKlow,0)
高行权价看涨期权多头 m a x ( S t − K h i g h , 0 ) − C 2 max(S_{t}-K_{high},0)-C2 max(StKhigh,0)C2
整体策略 C 1 − C 2 + m a x ( S t − K h i g h , 0 ) − m a x ( S t − K l o w , 0 ) C1-C2+max(S_{t}-K_{high},0)-max(S_{t}-K_{low},0) C1C2+max(StKhigh,0)max(StKlow,0)

整体损益情况如下图所示:
在这里插入图片描述
代码实现:

def BearSpread(UnderlyingCode, code_high_strike, code_low_strike):'''UnderlyingCode:标的资产代码code_high_strike:行权价高的期权代码code_low_strike:行权价低的期权代码:return:'''# 取期权基本数据error_code, wss_data = w.wss(code_high_strike, "startdate,lasttradingdate", usedf=True)       # 取期权的上市时间及结束时间StartDate = wss_data['STARTDATE'][0]EndDate = wss_data['LASTTRADINGDATE'][0]# 取期权价格及执行价error_code, high_strike_data = w.wsd(code_high_strike, "exe_price,close,exe_ratio,exe_mode", StartDate, StartDate, usedf=True)error_code, low_strike_data = w.wsd(code_low_strike, "exe_price,close,exe_ratio,exe_mode", StartDate, StartDate, usedf=True)K_high = high_strike_data['EXE_PRICE'][0]K_low = low_strike_data['EXE_PRICE'][0]OptionPrice_high_strike = high_strike_data['CLOSE'][0]OptionPrice_low_strike = low_strike_data['CLOSE'][0]Type = high_strike_data['EXE_MODE'][0]Ratio_high_strike = high_strike_data['EXE_RATIO'][0]Ratio_low_strike = low_strike_data['EXE_RATIO'][0]# 取标的资产价格数据error_code, etf_data = w.wsd(UnderlyingCode, "close", StartDate, EndDate,  usedf=True)# 定义合约份数N_option = 1# 判断期权是看涨还是看跌if Type == "认购":Payoff = N_option * OptionPrice_low_strike - np.maximum(etf_data - K_low, 0) * Ratio_low_strike - N_option * OptionPrice_high_strike + np.maximum(etf_data - K_high, 0) * Ratio_high_strikeelif Type == "认沽":Payoff = N_option * OptionPrice_low_strike - np.maximum(K_low - etf_data, 0) * Ratio_low_strike - N_option * OptionPrice_high_strike + np.maximum(K_high - etf_data, 0) * Ratio_high_strikeelse:print("期权类型判断有误")Payoff.plot(legend=None)plt.xlabel('Time', fontsize=8)plt.xticks(rotation=45)plt.ylabel('Payoff', fontsize=8)plt.show()if __name__ == "__main__":code_high_strike = "10006371.SH"code_low_strike = "10006365.SH"UnderlyingCode = "510050.SH"BearSpread(UnderlyingCode, code_high_strike, code_low_strike)

随着到期日临近,策略损益变化如下图:
请添加图片描述

写在后面

最近和做期权的朋友交流发现,实际应用这些策略是很复杂的。由于期权买方卖方权利和义务的特点,Covered Call在卖看涨期权时需要缴纳保证金,一旦标的资产价格迅速上涨,期权端可能会被强平。所以可能根本就熬不到合约到期,也就不会有上述的收益曲线了。

Protective Put策略也是一样。如果盘中隐含波动率急速上涨,期权价格上涨,此时将看跌期权平仓会获得不小的收益,根本不用持有到期…

所以期权的策略其实是非常复杂的,不光光只考虑初始时间点的期权价格,更要考虑盘中期权价格的变动。这里只是为了复现FRM中提出的策略,还有很多不严谨的地方。

这篇关于FRM模型十六:期权策略(期权组合)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/811017

相关文章

C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)

《C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)》本文主要介绍了C#集成DeepSeek模型实现AI私有化的方法,包括搭建基础环境,如安装Ollama和下载DeepS... 目录前言搭建基础环境1、安装 Ollama2、下载 DeepSeek R1 模型客户端 ChatBo

MySQL InnoDB引擎ibdata文件损坏/删除后使用frm和ibd文件恢复数据

《MySQLInnoDB引擎ibdata文件损坏/删除后使用frm和ibd文件恢复数据》mysql的ibdata文件被误删、被恶意修改,没有从库和备份数据的情况下的数据恢复,不能保证数据库所有表数据... 参考:mysql Innodb表空间卸载、迁移、装载的使用方法注意!此方法只适用于innodb_fi

mysql通过frm和ibd文件恢复表_mysql5.7根据.frm和.ibd文件恢复表结构和数据

《mysql通过frm和ibd文件恢复表_mysql5.7根据.frm和.ibd文件恢复表结构和数据》文章主要介绍了如何从.frm和.ibd文件恢复MySQLInnoDB表结构和数据,需要的朋友可以参... 目录一、恢复表结构二、恢复表数据补充方法一、恢复表结构(从 .frm 文件)方法 1:使用 mysq

SpringBoot快速接入OpenAI大模型的方法(JDK8)

《SpringBoot快速接入OpenAI大模型的方法(JDK8)》本文介绍了如何使用AI4J快速接入OpenAI大模型,并展示了如何实现流式与非流式的输出,以及对函数调用的使用,AI4J支持JDK8... 目录使用AI4J快速接入OpenAI大模型介绍AI4J-github快速使用创建SpringBoot

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

Spring AI Alibaba接入大模型时的依赖问题小结

《SpringAIAlibaba接入大模型时的依赖问题小结》文章介绍了如何在pom.xml文件中配置SpringAIAlibaba依赖,并提供了一个示例pom.xml文件,同时,建议将Maven仓... 目录(一)pom.XML文件:(二)application.yml配置文件(一)pom.xml文件:首

Deepseek使用指南与提问优化策略方式

《Deepseek使用指南与提问优化策略方式》本文介绍了DeepSeek语义搜索引擎的核心功能、集成方法及优化提问策略,通过自然语言处理和机器学习提供精准搜索结果,适用于智能客服、知识库检索等领域... 目录序言1. DeepSeek 概述2. DeepSeek 的集成与使用2.1 DeepSeek API

Redis的数据过期策略和数据淘汰策略

《Redis的数据过期策略和数据淘汰策略》本文主要介绍了Redis的数据过期策略和数据淘汰策略,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录一、数据过期策略1、惰性删除2、定期删除二、数据淘汰策略1、数据淘汰策略概念2、8种数据淘汰策略

SpringBoot中的404错误:原因、影响及解决策略

《SpringBoot中的404错误:原因、影响及解决策略》本文详细介绍了SpringBoot中404错误的出现原因、影响以及处理策略,404错误常见于URL路径错误、控制器配置问题、静态资源配置错误... 目录Spring Boot中的404错误:原因、影响及处理策略404错误的出现原因1. URL路径错