-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_to_occ.py
More file actions
27 lines (21 loc) · 809 Bytes
/
text_to_occ.py
File metadata and controls
27 lines (21 loc) · 809 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
#!/usr/bin/env python
import datetime
def text_to_occ(option):
"""Takes an option in text format, returns option in OCC format."""
# https://web.archive.org/web/20200622191119/https://help.yahoo.com/kb/SLN13884.html
ticker, month, day, year, strike, option_type = option.split(" ")
datetime_object = datetime.datetime.strptime(month, "%b")
numerical_month = datetime_object.month
strike = int(float(strike) * 1000)
normalized_strike = f"{strike:08}"
output = (
f"{ticker}{year[2:]}{numerical_month}{day}{option_type[0]}{normalized_strike}"
)
print(output)
return output
if __name__ == "__main__":
import sys
if len(sys.argv) == 2:
text_to_occ(sys.argv[1])
else:
print(f"\tUsage: {sys.argv[0]} 'SPY Jun 26 2020 300.0 Put'")