-
Notifications
You must be signed in to change notification settings - Fork 0
/
iron_butterfly.py
38 lines (36 loc) · 1.54 KB
/
iron_butterfly.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
import numpy as np
import matplotlib.pyplot as plt
import seaborn
import random
spot = 222.50 #dummy price
long_put = 200 #dummy price
short_put = 222.50 #dummy price
long_call = 250 #dummy price
short_call = 222.50 #dummy price
long_put_prem = 7.30 #round(random.uniform(0.0, 5.0), 2)
short_put_prem = 10.50 #round(random.uniform(5.0, 10.0), 2)
long_call_prem = 7.10 #round(random.uniform(0.0, 5.0), 2)
short_call_prem = 10.90 #round(random.uniform(5.0, 10.0), 2)
sRange = np.arange(spot*0.8, spot*1.2, 1)
def calls(sR, price, prem):
return np.where(sR > price, sR - price, 0) - prem
def puts(sR, price, prem):
return np.where(sR < price, price - sR, 0) - prem
payoff_long_call = calls(sRange, long_call, long_call_prem)
payoff_short_call = calls(sRange, short_call, short_call_prem) * -1.0
payoff_long_put = puts(sRange, long_put, long_put_prem)
payoff_short_put = puts(sRange, short_put, short_put_prem) * -1.0
payoff_bf = payoff_long_call + payoff_short_call + payoff_long_put + payoff_short_put
fig, ax = plt.subplots()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible('zero')
ax.plot(sRange, payoff_long_call, '--', label='Long Call', color='r')
ax.plot(sRange, payoff_short_call, '--', label='Short Call', color='y')
ax.plot(sRange, payoff_long_put, '--', label='Long Put', color='g')
ax.plot(sRange, payoff_short_put, '--', label='Short Put', color='m')
ax.plot(sRange, payoff_bf, label='Iron Butterfly', color='b')
plt.xlabel('Price', ha = 'left')
plt.ylabel('Profit/Loss')
plt.legend()
plt.show()