-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpl.py
75 lines (52 loc) · 2.08 KB
/
pl.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
from sp import get_all_settlements, PRODUCT_SYMBOLS
from wi import get_average_option
from matplotlib import pyplot
def get_points(settlements, symbol, month, greek, call_or_put):
xs = []
for x in settlements['options'][month][call_or_put]:
xs.append(x)
xs.sort()
ys = []
for x in xs:
ys.append(settlements['options'][month][call_or_put][x][greek])
return (xs, ys)
def get_xmin(avg_put, und_settlement):
if (und_settlement * 0.9 < avg_put):
return und_settlement * 0.9
else:
return avg_put
def get_xmax(avg_call, und_settlement):
if (und_settlement * 1.1 > avg_call):
return und_settlement * 1.1
else:
return avg_call
def main(settlements, symbol, month, greek, puts):
settlements = get_all_settlements(symbol)
(call_xs, call_ys) = get_points(settlements, symbol, month, greek, 'CALL')
pyplot.plot(call_xs, call_ys, marker='x')
if puts:
(put_xs, put_ys) = get_points(settlements, symbol, month, greek, 'PUT')
pyplot.plot(put_xs, put_ys, marker='o')
pyplot.legend(['Calls', 'Puts'])
commodity = PRODUCT_SYMBOLS[symbol]['name']
pyplot.title('{0} {1} {2}'.format(month, commodity, greek))
pyplot.xlabel('strikes')
pyplot.ylabel(greek)
averages = get_average_option(settlements['options'][month])
und_settlement = settlements['options'][month]['underlying']['price']
xmin = get_xmin(averages['PUT'], und_settlement)
xmax = get_xmax(averages['CALL'], und_settlement)
pyplot.axis(xmin=xmin)
pyplot.axis(xmax=xmax)
pyplot.savefig("./pollen/{0}/{1}_{2}.png".format(commodity, month, greek))
pyplot.clf()
if __name__ == "__main__":
settlements = get_all_settlements("S")
symbol = "S"
for month in settlements['options'].keys():
for greek in ['delta', 'gamma', 'vega', 'volatility']:
if greek == 'delta':
puts = True
else:
puts = False
main(settlements, symbol, month, greek, puts)