-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathGQF - option_payoffs.py
127 lines (95 loc) · 3.72 KB
/
GQF - option_payoffs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('ggplot')
#### make a funcion that lets you specify a few parameters and calculates the payoff
# S = underlying price
# K = strike price
# Price = premium paid for option
def long_call(S, K, Price):
# Long Call Payoff = max(underlying - Strike Price, 0)
# If we are long a call, we would only elect to call if the current price is greater than the strike price on our option
P = list(map(lambda x: max(x - K, 0) - Price, S))
return P
def long_put(S, K, Price):
# Long Put Payoff = max(Strike Price - underlying, 0)
# If we are long a call, we would only elect to call if the current price is less than the strike price on our option
P = list(map(lambda x: max(K - x, 0) - Price, S))
return P
def short_call(S, K, Price):
# Payoff a shortcall is just the inverse of the payoff of a long call
P = long_call(S, K, Price)
return [-1.0*p for p in P]
def short_put(S,K, Price):
# Payoff a short put is just the inverse of the payoff of a long put
P = long_put(S,K, Price)
return [-1.0*p for p in P]
def bull_spread(S, E1, E2, Price1, Price2):
P_1 = long_call(S, E1, Price1)
P_2 = short_call(S, E2, Price2)
return [x+y for x,y in zip(P_1, P_2)]
def bear_spread(S, E1, E2, Price1, Price2):
P = bull_spread(S,E1, E2, Price1, Price2)
return [-1.0*p + 1.0 for p in P]
def straddle(S, E, Price1, Price2):
P_1 = long_call(S, E, Price1)
P_2 = long_put(S, E, Price2)
return [x+y for x,y in zip(P_1, P_2)]
def strangle(S, E1, E2, Price1, Price2):
P_1 = long_call(S, E1, Price1)
P_2 = long_put(S, E2, Price2)
return [x + y for x, y in zip(P_1, P_2)]
S = [t/5 for t in range(0,1000)] # Define some series of prices
fig, ax = plt.subplots(ncols= 2, nrows=2, sharex=True, sharey=True, figsize = (15,10))
fig.suptitle('Payoff Functions for Long/Short Put/Calls', fontsize=20, fontweight='bold')
fig.text(0.5, 0.04, 'Underlying Price ($)', ha='center', fontsize=14, fontweight='bold')
fig.text(0.08, 0.5, 'Option Payoff ($)', va='center', rotation='vertical', fontsize=14, fontweight='bold')
lc_P = long_call(S,100, 10)
plt.subplot(221)
plt.plot(S, lc_P, 'r')
plt.legend(["Long Call"])
lp_P = long_put(S,100, 10)
plt.subplot(222)
plt.plot(S, lp_P, 'b')
plt.legend(["Long Put"])
sc_P = short_call(S,100, 10)
plt.subplot(223)
plt.plot(S, sc_P, 'r')
plt.legend(["Short Call"])
sp_P = short_put(S,100, 10)
plt.subplot(224)
plt.plot(S, sp_P, 'b')
plt.legend(["Short Put"])
plt.show()
fig, ax = plt.subplots(nrows=3, sharex=True, sharey=True, figsize=(30, 20))
fig.suptitle('Payoff Functions for Long/Short Put/Calls', fontsize=20, fontweight='bold')
fig.text(0.5, 0.08, 'Underlying Price ($)', ha='center', fontsize=18, fontweight='bold')
fig.text(0.08, 0.5, 'Option Payoff ($)', va='center', rotation='vertical', fontsize=18, fontweight='bold')
plt.subplot(321)
P1 = bull_spread(S,50, 100, 15, 10)
long_c = long_call(S, 50, 15)
short_c = short_call(S, 100, 10)
plt.plot(S, P1, 'r')
plt.plot(S, long_c, 'r--')
plt.plot(S, short_c, 'b--')
plt.legend(["Bull Spread", "Long Call", "Short Call"])
plt.title("Bull Spread")
plt.subplot(323)
P = straddle(S,100, 10, 10)
P_longcall = long_call(S, 100, 10)
P_longput = long_put(S, 100, 10)
plt.plot(S, P)
plt.plot(S, P_longcall, 'r--')
plt.plot(S, P_longput, 'b--')
plt.legend(["Straddle", "Long Call", "Long Put"])
plt.title("Straddle")
plt.subplot(325)
P = strangle(S,100, 75, 10, 10)
P_longcall = long_call(S, 100, 10)
P_longput = long_put(S, 75, 10)
plt.plot(S, P, 'g')
plt.plot(S, P_longcall, 'b--')
plt.plot(S, P_longput, 'r--')
plt.legend(["Strangle", "Long Short", "Long Put"])
plt.title("Strangle")
plt.show()