forked from westonplatter/fast_arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistorical_option_data.py
53 lines (46 loc) · 1.14 KB
/
historical_option_data.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
import configparser
from fast_arrow import (
Client,
Stock,
Option,
OptionChain,
OptionMarketdata
)
import math
print("----- running {}".format(__file__))
#
# get the authentication configs
#
config_file = "config.debug.ini"
config = configparser.ConfigParser()
config.read(config_file)
username = config['account']['username']
password = config['account']['password']
#
# instantiate and authetnicate client
#
client = Client(username=username, password=password)
client.authenticate()
#
# get TLT options
#
symbol = "TLT"
stock = Stock.fetch(client, symbol)
stock_id = stock["id"]
oc = OptionChain.fetch(client, stock_id, symbol)
oc_id = oc["id"]
next_2_eds = oc['expiration_dates'][0:1]
ops = Option.in_chain(client, oc_id, expiration_dates=next_2_eds)
#
# get TLT in the middle of the current TLT trading range
#
urls = [op["url"] for op in ops]
middle = math.floor(len(urls)/2)
diff = math.floor(len(urls) * 0.7)
lower_end = middle - diff
higher_end = middle + diff
urls_subset = urls[lower_end:higher_end]
#
# get historical data for TLT options
#
hd = OptionMarketdata.historical_quotes_by_urls(client, urls_subset, span="year")