-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
37 lines (32 loc) · 993 Bytes
/
plot.py
File metadata and controls
37 lines (32 loc) · 993 Bytes
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
import matplotlib.pyplot as plt
import json
filename = 'dict.txt'
sep = '\n'
with open(filename, "r") as f:
out = []
for line in f:
print(f)
values = line.split(sep)
out.append(eval(values[0]))
# Isolate prices and strikes
call_prices = []
put_prices = []
call_strikes = []
put_strikes = []
for i in out:
splt = i['instrument_name'].split('BTC-28FEB20-')[-1]
if splt[-1] == 'C':
call_prices.append(i['price'])
call_strikes.append(int(splt[:-2]))
else:
put_prices.append(i['price'])
put_strikes.append(int(splt[:-2]))
def mkplot(x, y, fname, title):
fig = plt.figure()
plt.scatter(x, y)
plt.title(title)
plt.xlabel('Strike')
plt.ylabel('Price')
fig.savefig(fname + '.png', transparent=True)
mkplot(call_strikes, call_prices, 'Calls-28Feb2020', 'Calls-28Feb2020 Prices vs. Strikes')
mkplot(put_strikes, put_prices, 'Puts-28Feb2020', 'Puts-28Feb2020 Prices vs. Strikes')