-
Notifications
You must be signed in to change notification settings - Fork 5
/
market_data.py
83 lines (72 loc) · 2.11 KB
/
market_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import util
class MarketData:
"""
Class to represent S&P 500 stock market data.
"""
def __init__(self, vol, op, lo, hi, cl, stocks):
# Store prices in both raw and relative formats
self.raw = {
'vol': vol,
'op': op,
'lo': lo,
'hi': hi,
'cl': cl,
}
self.relative = {
'vol': util.get_price_relatives(vol),
'op': util.get_price_relatives(op),
'lo': util.get_price_relatives(lo),
'hi': util.get_price_relatives(hi),
'cl': util.get_price_relatives(cl)
}
self.standardized = {
'cl': util.get_standardized_prices(cl)
}
self.stock_names = stocks
def get_std_cl(self):
return self.standardized['cl']
def get_vol(self, relative=True):
"""
:param relative: If True, get the relative values. Otherwise
get the raw values.
"""
if relative:
return self.relative['vol']
else:
return self.raw['vol']
def get_op(self, relative=True):
"""
:param relative: If True, get the relative values. Otherwise
get the raw values.
"""
if relative:
return self.relative['op']
else:
return self.raw['op']
def get_lo(self, relative=True):
"""
:param relative: If True, get the relative values. Otherwise
get the raw values.
"""
if relative:
return self.relative['lo']
else:
return self.raw['lo']
def get_hi(self, relative=True):
"""
:param relative: If True, get the relative values. Otherwise
get the raw values.
"""
if relative:
return self.relative['hi']
else:
return self.raw['hi']
def get_cl(self, relative=True):
"""
:param relative: If True, get the relative values. Otherwise
get the raw values.
"""
if relative:
return self.relative['cl']
else:
return self.raw['cl']