绘制相同到期日欧式期权组合收益图(python)

This article does not consider option premium.

1.Single option

1.1call option(看涨)

1.1.1buy call

The payoff is max(0,S_T-K), where K is the strike price, S_T is the spot price at maturity T.

import matplotlib.pyplot as plt
import numpy as np
K1=40
St=np.linspace(0,80,81)
def buycall(K,S):
    if S-K>0:
        payoff=S-K
    else:
        payoff=0
    return payoff
buycallpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    buycallpayoff[i]=buycall(K1,St[i])
plt.plot(St,buycallpayoff)
plt.title('buycallpayoff')
plt.xlabel('spot price'+'($S_{t}$)')
plt.ylabel('strike price(K)')
plt.show()

绘制相同到期日欧式期权组合收益图(python)_第1张图片

1.1.2sell call

The payoff is min(0,K-S_T)

def sellcall(K,S):
    if K-S<0:
        payoff=K-S
    else:
        payoff=0
    return payoff
sellcallpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    sellcallpayoff[i]=sellcall(K1,St[i])
plt.plot(St,sellcallpayoff)
plt.title('sellcallpayoff')
plt.xlabel('spot price'+'($S_{t}$)')
plt.ylabel('strike price(K)')
plt.show()

绘制相同到期日欧式期权组合收益图(python)_第2张图片

1.2put option(看跌)

1.2.1buy put

The payoff is max(0,K-S_T)

def buyput(K,S):
    if K-S>0:
        payoff=K-S
    else:
        payoff=0
    return payoff
buyputpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    buyputpayoff[i]=buyput(K1,St[i])
plt.plot(St,buyputpayoff)
plt.title('buy put')
plt.xlabel('spot price'+'($S_{t}$)')
plt.ylabel('payoff')
plt.show()

绘制相同到期日欧式期权组合收益图(python)_第3张图片

1.2.2sell put

The payoff is min(0,S_T-K)

def sellput(K,S):
    if S-K<0:
        payoff=S-K
    else:
        payoff=0
    return payoff
sellputpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    sellputpayoff[i]=sellput(K1,St[i])
plt.plot(St,sellputpayoff)
plt.title('sell put')
plt.xlabel('spot price'+'($S_{t}$)')
plt.ylabel('payoff')
plt.show()

绘制相同到期日欧式期权组合收益图(python)_第4张图片

2.Option portfolio

2.1straddle(跨式组合)

2.1.1bottom (buy) straddle (底部买入的跨式组合)

The portfolio is that buy one call option and one put option with same strike price and expiration date(买入相同交割价格和到期日的一份看涨和一份看跌期权).

The payoff is max(0, S_T-K)+max(0,k- S_T)=| S_T-K|.

def bottomstraddle(K,S):
    payoff=abs(S-K)
    return payoff
bottomstraddlepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstraddlepayoff[i]=bottomstraddle(K1,St[i])
plt.plot(St,bottomstraddlepayoff)
plt.title('bottom (buy) straddle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第5张图片

2.1.2top (sell) straddle(顶部卖出的跨式组合)

The portfolio is that sell one call option and one put option with same strike price and expiration date(卖出相同交割价格和到期日的一份看涨和一份看跌期权).

The payoff is min(0, S_T-K)+min(0,k- S_T)=-| S_T-K|.

def topstraddle(K,S):
    payoff=-abs(S-K)
    return payoff
topstraddlepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    topstraddlepayoff[i]=topstraddle(K1,St[i])
plt.plot(St,topstraddlepayoff)
plt.title('top (sell) straddle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第6张图片

 

2.2strip(条式组合)

2.2.1bottom (buy) strip(底部买入的条式组合)

The portfolio is that buy one call option and two put options with same strike price and expiration date(买入相同交割价格和到期日的一份看涨和两份看跌期权).

The payoff is max(0, S_T-K)+2max(0,k- S_T)=| S_T-K|+max(0,k- S_T).

def bottomstrip(K,S):
    if K-S>0:
        payoff=abs(S-K)+K-S
    else:
        payoff=abs(S-K)
    return payoff
bottomstrippayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstrippayoff[i]=bottomstrip(K1,St[i])
plt.plot(St,bottomstrippayoff)
plt.title('bottom (buy) strip')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第7张图片

2.2.2top (sell) strip(顶部卖出的条式组合)

The portfolio is that sell one call option and two put options with same strike price and expiration date(卖出相同交割价格和到期日的一份看涨和两份看跌期权).

The payoff is 2min(0, S_T-K)+min(0,k- S_T)=-| S_T-K|+min(0, S_T-K).

def topstrip(K,S):
    if S-K<0:
        payoff=-abs(S-K)+S-K
    else:
        payoff=-abs(S-K)
    return payoff
topstrippayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    topstrippayoff[i]=topstrip(K1,St[i])
plt.plot(St,topstrippayoff)
plt.title('top (sell) strip')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第8张图片

2.3strap(带式组合)

2.3.2bottom (buy) strap(底部买入的带式组合)

The portfolio is that buy two call options and one put option with same strike price and expiration date(买入相同交割价格和到期日的两份看涨和一份看跌期权).

The payoff is 2max(0, S_T-K)+max(0,k- S_T)=| S_T-K|+max(0, S_T-K).

def bottomstrap(K,S):
    if S-K>0:
        payoff=abs(S-K)+S-K
    else:
        payoff=abs(S-K)
    return payoff
bottomstrappayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstrappayoff[i]=bottomstrap(K1,St[i])
plt.plot(St,bottomstrappayoff)
plt.title('bottom (buy) strap')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第9张图片

2.3.2top (sell) strap(顶部卖出的带式组合)

The portfolio is that sell two call options and one put option with same strike price and expiration date(卖出相同交割价格和到期日的两份看涨和一份看跌期权).

The payoff is min(0,S_T-K)+2min(0,k-S_T)=-|S_T-K|+min(0,k-S_T).

def topstrap(K,S):
    if K-S<0:
        payoff=-abs(S-K)+K-S
    else:
        payoff=-abs(S-K)
    return payoff
topstrappayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    topstrappayoff[i]=topstrap(K1,St[i])
plt.plot(St,topstrappayoff)
plt.title('top (sell) strap')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

绘制相同到期日欧式期权组合收益图(python)_第10张图片

2.4strangle(宽跨式组合)

2.4.1bottom (buy) strangle(底部买入的宽跨式组合)

The portfolio is that buy one call option with strike price KC and one put option with strike price KP , where KC > KP,and they have same expiration date(买入相同到期日的一份看涨和一份看跌期权,且看涨期权的交割价格高于看跌期权).

The payoff is max(0,S_T-KC)+max(0,KP-S_T).

KC=50
KP=30
def bottomstrangle(KC,KP,S):
    if S-KC>0:
        callpayoff=S-KC
    else:
        callpayoff=0
    if KP-S>0:
        putpayoff=KP-S
    else:
        putpayoff=0
    payoff=callpayoff+putpayoff
    return payoff
bottomstranglepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstranglepayoff[i]=bottomstrangle(KC,KP,St[i])
plt.plot(St,bottomstranglepayoff)
plt.title('bottom (buy) strangle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第11张图片

2.4.2top (sell) strangle(顶部卖出的宽跨式组合)

The portfolio is that sell one call option with strike price KC and one put option with strike price KP , where KC > KP,and they have same expiration date(卖出相同到期日的一份看涨和一份看跌期权,且看涨期权的交割价格高于看跌期权).

The payoff is min(0,S_T-KP)+min(0,KC-S_T).

def topstrangle(KC,KP,S):
    if KC-S<0:
        callpayoff=KC-S
    else:
        callpayoff=0
    if S-KP<0:
        putpayoff=S-KP
    else:
        putpayoff=0
    payoff=callpayoff+putpayoff
    return payoff
topstranglepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    topstranglepayoff[i]=topstrangle(KC,KP,St[i])
plt.plot(St,topstranglepayoff)
plt.title('top (sell) strangle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第12张图片

2.5bull spreads(牛市差价组合)(低价买高价卖)

2.5.1call bull spreads(看涨牛市差价组合)

The portfolio is that buy one call option with low strike price KCL and sell one call option with high strike price KCH , and they have same expiration date(买入一份较低交割价格看涨期权和卖出一份较高交割价格看涨期权,且到期日相同).

The payoff is max(0,S_T-KCL)+min(0,KCH-S_T).

KCL=30
KCH=50
def callbullspreads(KCL,KCH,S):
    if S-KCL>0:
        lowcallpayoff=S-KCL
    else:
        lowcallpayoff=0
    if KCH-S<0:
        highcallpayoff=KCH-S
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+highcallpayoff
    return payoff
callbullspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callbullspreadspayoff[i]=callbullspreads(KCL,KCH,St[i])
plt.plot(St,callbullspreadspayoff)
plt.title('call bull spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第13张图片

2.5.2put bull spreads(看跌牛市差价组合)

The portfolio is that buy one put option with low strike price KPL and sell one put option with high strike price KPH , and they have same expiration date(买入一份较低交割价格看跌期权和卖出一份较高交割价格看跌期权,且到期日相同).

The payoff is max(0,KPL-S_T)+min(0,S_T-KPH).

KPL=30
KPH=50
def putbullspreads(KPL,KPH,S):
    if KPL-S>0:
        lowputpayoff=KPL-S
    else:
        lowputpayoff=0
    if S-KPH<0:
        highputpayoff=S-KPH
    else:
        highputpayoff=0
    payoff=lowputpayoff+highputpayoff
    return payoff
putbullspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putbullspreadspayoff[i]=putbullspreads(KPL,KPH,St[i])
plt.plot(St,putbullspreadspayoff)
plt.title('put bull spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第14张图片

2.6bear spreads(熊市差价组合)(低价卖高价买)

2.6.1call bear spreads(看涨熊市差价组合)

The portfolio is that sell one call option with low strike price KCLB and buy one call option with high strike price KCHB , and they have same expiration date(卖出一份较低交割价格看涨期权和买入一份较高交割价格看涨期权,且到期日相同).

The payoff is min(0,KCLB-S_T)+max(0,S_T-KCHB).

KCLB=30
KCHB=50
def callbearspreads(KCLB,KCHB,S):
    if KCLB-S<0:
        lowcallpayoff=KCLB-S
    else:
        lowcallpayoff=0
    if S-KCHB>0:
        highcallpayoff=S-KCHB
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+highcallpayoff
    return payoff
callbearspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callbearspreadspayoff[i]=callbearspreads(KCLB,KCHB,St[i])
plt.plot(St,callbearspreadspayoff)
plt.title('call bear spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第15张图片

2.6.2put bear spreads(看跌熊市差价组合)

The portfolio is that sell one put option with low strike price KPLB and buy one put option with high strike price KPHB , and they have same expiration date(卖出一份较低交割价格看跌期权和买入一份较高交割价格看跌期权,且到期日相同).

The payoff is min(0,S_T-KPLB)+max(0,KPHB-S_T).

KPLB=30
KPHB=50
def putbearspreads(KPLB,KPHB,S):
    if S-KPLB<0:
        lowputpayoff=S-KPLB
    else:
        lowputpayoff=0
    if KPHB-S>0:
        highputpayoff=KPHB-S
    else:
        highputpayoff=0
    payoff=lowputpayoff+highputpayoff
    return payoff
putbearspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putbearspreadspayoff[i]=putbearspreads(KPLB,KPHB,St[i])
plt.plot(St,putbearspreadspayoff)
plt.title('put bear spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第16张图片

2.7butterfly spreads(蝶式差价组合)

2.7.1forward butterfly spreads(正向蝶式差价组合)(买高低,卖中间)

2.7.1.1call forward butterfly spreads(看涨正向蝶式差价组合)

The portfolio is that buy one call option with low strike price KLb, sell two call options with middle strike price KMb and buy one call option with high strike price KHb, where KHb-KMb=KMb-KLb, and they have same expiration date(买入一份较低交割价格看涨期权,卖出两份中间交割价格看涨期权和买入一份较高交割价格看涨期权,三个价格成等差数列,且到期日相同).

The payoff is max(0,S_T-KLb)+2min(0,KMb-S_T)+max(0,S_T-KHb).

KLb=20
KMb=40
KHb=60
def callforwardbutterflyspreads(KLb,KMb,KHb,S):
    if S-KLb>0:
        lowcallpayoff=S-KLb
    else:
        lowcallpayoff=0
    if KMb-S<0:
        middlecallpayoff=2*(KMb-S)
    else:
        middlecallpayoff=0
    if S-KHb>0:
        highcallpayoff=S-KHb
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+middlecallpayoff+highcallpayoff
    return payoff
callforwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callforwardbutterflyspreadspayoff[i]=callforwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,callforwardbutterflyspreadspayoff)
plt.title('call forward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第17张图片

2.7.1.2put forward butterfly spreads(看跌正向蝶式差价组合)

The portfolio is that buy one put option with low strike price KLb, sell two put options with middle strike price KMb and buy one put option with high strike price KHb, where KHb-KMb=KMb-KLb, and they have same expiration date(买入一份较低交割价格看跌期权,卖出两份中间交割价格看跌期权和买入一份较高交割价格看跌期权,三个价格成等差数列,且到期日相同).

The payoff is max(0,KLb-S_T)+2min(0,S_T-KMb)+max(0,KHb-S_T).

def putforwardbutterflyspreads(KLb,KMb,KHb,S):
    if KLb-S>0:
        lowputpayoff=KLb-S
    else:
        lowputpayoff=0
    if S-KMb<0:
        middleputpayoff=2*(S-KMb)
    else:
        middleputpayoff=0
    if KHb-S>0:
        highputpayoff=KHb-S
    else:
        highputpayoff=0
    payoff=lowputpayoff+middleputpayoff+highputpayoff
    return payoff
putforwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putforwardbutterflyspreadspayoff[i]=putforwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,putforwardbutterflyspreadspayoff)
plt.title('put forward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第18张图片

 

2.7.2backward butterfly spreads(反向蝶式差价组合)(买中间,卖高低)

2.7.2.1call backward butterfly spreads(看涨反向蝶式差价组合)

The portfolio is that sell one call option with low strike price KLb, buy two call options with middle strike price KMb and sell one call option with high strike price KHb, where KHb-KMb=KMb-KLb, and they have same expiration date(卖出一份较低交割价格看涨期权,买入两份中间交割价格看涨期权和卖出一份较高交割价格看涨期权,三个价格成等差数列,且到期日相同).

The payoff is min(0,KLb-S_T)+2max(0,S_T-KMb)+min(0,KHb-S_T).

def callbackwardbutterflyspreads(KLb,KMb,KHb,S):
    if KLb-S<0:
        lowcallpayoff=KLb-S
    else:
        lowcallpayoff=0
    if S-KMb>0:
        middlecallpayoff=2*(S-KMb)
    else:
        middlecallpayoff=0
    if KHb-S<0:
        highcallpayoff=KHb-S
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+middlecallpayoff+highcallpayoff
    return payoff
callbackwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callbackwardbutterflyspreadspayoff[i]=callbackwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,callbackwardbutterflyspreadspayoff)
plt.title('call backward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第19张图片

2.7.2.2put backward butterfly spreads(看跌反向蝶式差价组合)

The portfolio is that sell one put option with low strike price KLb, buy two put options with middle strike price KMb and sell one put option with high strike price KHb, where KHb-KMb=KMb-KLb, and they have same expiration date(卖出一份较低交割价格看跌期权,买入两份中间交割价格看跌期权和卖出一份较高交割价格看跌期权,三个价格成等差数列,且到期日相同).

The payoff is min(0,S_T-KLb)+2max(0,KMb-S_T)+min(0,S_T-KHb).

def putbackwardbutterflyspreads(KLb,KMb,KHb,S):
    if S-KLb<0:
        lowcallpayoff=S-KLb
    else:
        lowcallpayoff=0
    if KMb-S>0:
        middlecallpayoff=2*(KMb-S)
    else:
        middlecallpayoff=0
    if S-KHb<0:
        highcallpayoff=S-KHb
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+middlecallpayoff+highcallpayoff
    return payoff
putbackwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putbackwardbutterflyspreadspayoff[i]=putbackwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,putbackwardbutterflyspreadspayoff)
plt.title('put backward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 绘制相同到期日欧式期权组合收益图(python)_第20张图片

 完整代码:

import matplotlib.pyplot as plt
import numpy as np
K1=40
St=np.linspace(0,80,81)
def buycall(K,S):
    if S-K>0:
        payoff=S-K
    else:
        payoff=0
    return payoff
buycallpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    buycallpayoff[i]=buycall(K1,St[i])
plt.plot(St,buycallpayoff)
plt.title('buy call')
plt.xlabel('spot price'+'($S_{t}$)')
plt.ylabel('payoff')
plt.show()
def sellcall(K,S):
    if K-S<0:
        payoff=K-S
    else:
        payoff=0
    return payoff
sellcallpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    sellcallpayoff[i]=sellcall(K1,St[i])
plt.plot(St,sellcallpayoff)
plt.title('sell call')
plt.xlabel('spot price'+'($S_{t}$)')
plt.ylabel('payoff')
plt.show()
def buyput(K,S):
    if K-S>0:
        payoff=K-S
    else:
        payoff=0
    return payoff
buyputpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    buyputpayoff[i]=buyput(K1,St[i])
plt.plot(St,buyputpayoff)
plt.title('buy put')
plt.xlabel('spot price'+'($S_{t}$)')
plt.ylabel('payoff')
plt.show()
def sellput(K,S):
    if S-K<0:
        payoff=S-K
    else:
        payoff=0
    return payoff
sellputpayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    sellputpayoff[i]=sellput(K1,St[i])
plt.plot(St,sellputpayoff)
plt.title('sell put')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def bottomstraddle(K,S):
    payoff=abs(S-K)
    return payoff
bottomstraddlepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstraddlepayoff[i]=bottomstraddle(K1,St[i])
plt.plot(St,bottomstraddlepayoff)
plt.title('bottom (buy) straddle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def topstraddle(K,S):
    payoff=-abs(S-K)
    return payoff
topstraddlepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    topstraddlepayoff[i]=topstraddle(K1,St[i])
plt.plot(St,topstraddlepayoff)
plt.title('top (sell) straddle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def bottomstrip(K,S):
    if K-S>0:
        payoff=abs(S-K)+K-S
    else:
        payoff=abs(S-K)
    return payoff
bottomstrippayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstrippayoff[i]=bottomstrip(K1,St[i])
plt.plot(St,bottomstrippayoff)
plt.title('bottom (buy) strip')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def topstrip(K,S):
    if S-K<0:
        payoff=-abs(S-K)+S-K
    else:
        payoff=-abs(S-K)
    return payoff
topstrippayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    topstrippayoff[i]=topstrip(K1,St[i])
plt.plot(St,topstrippayoff)
plt.title('top (sell) strip')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def bottomstrap(K,S):
    if S-K>0:
        payoff=abs(S-K)+S-K
    else:
        payoff=abs(S-K)
    return payoff
bottomstrappayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstrappayoff[i]=bottomstrap(K1,St[i])
plt.plot(St,bottomstrappayoff)
plt.title('bottom (buy) strap')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
KC=50
KP=30
def bottomstrangle(KC,KP,S):
    if S-KC>0:
        callpayoff=S-KC
    else:
        callpayoff=0
    if KP-S>0:
        putpayoff=KP-S
    else:
        putpayoff=0
    payoff=callpayoff+putpayoff
    return payoff
bottomstranglepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    bottomstranglepayoff[i]=bottomstrangle(KC,KP,St[i])
plt.plot(St,bottomstranglepayoff)
plt.title('bottom (buy) strangle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def topstrangle(KC,KP,S):
    if KC-S<0:
        callpayoff=KC-S
    else:
        callpayoff=0
    if S-KP<0:
        putpayoff=S-KP
    else:
        putpayoff=0
    payoff=callpayoff+putpayoff
    return payoff
topstranglepayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    topstranglepayoff[i]=topstrangle(KC,KP,St[i])
plt.plot(St,topstranglepayoff)
plt.title('top (sell) strangle')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
KCL=30
KCH=50
def callbullspreads(KCL,KCH,S):
    if S-KCL>0:
        lowcallpayoff=S-KCL
    else:
        lowcallpayoff=0
    if KCH-S<0:
        highcallpayoff=KCH-S
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+highcallpayoff
    return payoff
callbullspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callbullspreadspayoff[i]=callbullspreads(KCL,KCH,St[i])
plt.plot(St,callbullspreadspayoff)
plt.title('call bull spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
KPL=30
KPH=50
def putbullspreads(KPL,KPH,S):
    if KPL-S>0:
        lowputpayoff=KPL-S
    else:
        lowputpayoff=0
    if S-KPH<0:
        highputpayoff=S-KPH
    else:
        highputpayoff=0
    payoff=lowputpayoff+highputpayoff
    return payoff
putbullspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putbullspreadspayoff[i]=putbullspreads(KPL,KPH,St[i])
plt.plot(St,putbullspreadspayoff)
plt.title('put bull spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
KLb=30
KHb=50
def callbearspreads(KLb,KHb,S):
    if KLb-S<0:
        lowcallpayoff=KLb-S
    else:
        lowcallpayoff=0
    if S-KHb>0:
        highcallpayoff=S-KHb
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+highcallpayoff
    return payoff
callbearspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callbearspreadspayoff[i]=callbearspreads(KLb,KHb,St[i])
plt.plot(St,callbearspreadspayoff)
plt.title('call bear spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
KPLB=30
KPHB=50
def putbearspreads(KPLB,KPHB,S):
    if S-KPLB<0:
        lowputpayoff=S-KPLB
    else:
        lowputpayoff=0
    if KPHB-S>0:
        highputpayoff=KPHB-S
    else:
        highputpayoff=0
    payoff=lowputpayoff+highputpayoff
    return payoff
putbearspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putbearspreadspayoff[i]=putbearspreads(KPLB,KPHB,St[i])
plt.plot(St,putbearspreadspayoff)
plt.title('put bear spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
KLb=20
KMb=40
KHb=60
def callforwardbutterflyspreads(KLb,KMb,KHb,S):
    if S-KLb>0:
        lowcallpayoff=S-KLb
    else:
        lowcallpayoff=0
    if KMb-S<0:
        middlecallpayoff=2*(KMb-S)
    else:
        middlecallpayoff=0
    if S-KHb>0:
        highcallpayoff=S-KHb
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+middlecallpayoff+highcallpayoff
    return payoff
callforwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callforwardbutterflyspreadspayoff[i]=callforwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,callforwardbutterflyspreadspayoff)
plt.title('call forward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def putforwardbutterflyspreads(KLb,KMb,KHb,S):
    if KLb-S>0:
        lowputpayoff=KLb-S
    else:
        lowputpayoff=0
    if S-KMb<0:
        middleputpayoff=2*(S-KMb)
    else:
        middleputpayoff=0
    if KHb-S>0:
        highputpayoff=KHb-S
    else:
        highputpayoff=0
    payoff=lowputpayoff+middleputpayoff+highputpayoff
    return payoff
putforwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putforwardbutterflyspreadspayoff[i]=putforwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,putforwardbutterflyspreadspayoff)
plt.title('put forward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def callbackwardbutterflyspreads(KLb,KMb,KHb,S):
    if KLb-S<0:
        lowcallpayoff=KLb-S
    else:
        lowcallpayoff=0
    if S-KMb>0:
        middlecallpayoff=2*(S-KMb)
    else:
        middlecallpayoff=0
    if KHb-S<0:
        highcallpayoff=KHb-S
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+middlecallpayoff+highcallpayoff
    return payoff
callbackwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    callbackwardbutterflyspreadspayoff[i]=callbackwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,callbackwardbutterflyspreadspayoff)
plt.title('call backward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()
def putbackwardbutterflyspreads(KLb,KMb,KHb,S):
    if S-KLb<0:
        lowcallpayoff=S-KLb
    else:
        lowcallpayoff=0
    if KMb-S>0:
        middlecallpayoff=2*(KMb-S)
    else:
        middlecallpayoff=0
    if S-KHb<0:
        highcallpayoff=S-KHb
    else:
        highcallpayoff=0
    payoff=lowcallpayoff+middlecallpayoff+highcallpayoff
    return payoff
putbackwardbutterflyspreadspayoff=np.linspace(0,1,len(St))
for i in range(len(St)):
    putbackwardbutterflyspreadspayoff[i]=putbackwardbutterflyspreads(KLb,KMb,KHb,St[i])
plt.plot(St,putbackwardbutterflyspreadspayoff)
plt.title('put backward butterfly spreads')
plt.xlabel('spot price'+'($S_{T}$)')
plt.ylabel('payoff')
plt.show()

 

你可能感兴趣的:(python)