本文所有代码基于windAPI,复现前先下载客户端并注册账号
备兑看涨期权(Covered Call)
构成:标的资产的多头 + 欧式看涨期权空头
损益:当标的资产市场价格上涨时,标的资产多头获利,看涨期权空头不行权。
当标的资产价格下降时,标的资产多头亏损,看涨期权行权获利弥补多头方损失。
头寸 | 损益 |
---|---|
标的资产多头 | S T − S 0 S_{T}-S_{0} ST−S0 |
看涨期权空头 | C − m a x ( S T − K , 0 ) C-max(S_{T}-K,0) C−max(ST−K,0) |
整体策略 | S T − S 0 − m a x ( S T − K , 0 ) + C S_{T}-S_{0}-max(S_{T}-K,0)+C ST−S0−max(ST−K,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 = StrikeTime
else:
BacktestTime = current_time
# 定义合约份数
N_ETF = 10000
N_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) * Ratio
Payoff.plot(legend=None)
plt.xlabel('Time', fontsize=8)
plt.xticks(rotation=45)
plt.ylabel('Payoff', fontsize=8)
plt.show(