-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_chains.py
76 lines (67 loc) · 2.2 KB
/
test_chains.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
import logging
import sys
import opchain
loglevel = logging.INFO
symbol = 'TSLA'
logging.basicConfig(format='%(asctime)s %(message)s', level=loglevel)
logging.info(f" loglevel: {loglevel}")
"""
#data = opchain.get_chains(symbol)
#print(f"got {len(data.keys())} keys")
df = opchain.get_dataframe(symbol, putCall="PUT")
if df is None:
print("no dataframe returned!")
sys.exit(1)
print(f"got df with: {len(df)} rows")
for k in df.attrs:
v = df.attrs[k]
print(f"df attr {k}: {v}")
days = df['daysToExpiration']
unique_days = list(set(list(days.values)))
unique_days.sort()
print(f"unique days: {unique_days}")
daysToExpiration=45
df = opchain.get_dataframe(symbol, putCall="PUT", daysToExpiration=daysToExpiration)
if df is None:
print("no dataframe returned!")
sys.exit(1)
print(f"got df with: {len(df)} rows for daysToExpiration={daysToExpiration}")
candidates = opchain.get_candidates(df)
print(f"got {len(candidates)} candidates")
for row in candidates.itertuples():
row_dict = row._asdict()
for k in row_dict:
v = row_dict[k]
print(f"{k}: {v}")
print("e_u's..")
for row in candidates.itertuples():
print(f"row {row.Index}: {row.e_u:.3f}")
"""
"""
symbol = 'TSLA'
df = opchain.get_dataframe(symbol, putCall="PUT", daysToExpiration=18)
df = df.sort_values(by='strikePrice')
print(f"got {len(df)} contracts")
candidates = opchain.get_candidates(df, buy_range=(.09, .38), sell_range=(.2, .45))
print(f"got {len(candidates)} candidates")
"""
symbol = "$NDX.X"
logging.debug(f"symbol: {symbol}")
#df = opchain.get_dataframe(symbol, putCall="CALL", run_date="2021-04-08", daysToExpiration=45)
df = opchain.get_dataframe(symbol, putCall="CALL") #, run_date="2021-04-08") #, daysToExpiration=45)
print(f"got {len(df)} option rows")
print("mmm:", df.attrs["mmm"])
days = df['daysToExpiration']
days = list(set(list(days.values)))
days.sort()
print(days)
candidates = opchain.get_candidates(df, daysToExpiration=24)
print(f"got {len(candidates)} candidate rows")
width = candidates['width']
print(f"min width: {width.min()}")
print(f"max width: {width.max()}")
print(candidates.columns)
print("candidate attributes")
for k in candidates.attrs:
v = candidates.attrs[k]
print(f"{k}: {v}")