-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPivotPoints
More file actions
executable file
·48 lines (38 loc) · 1.32 KB
/
PivotPoints
File metadata and controls
executable file
·48 lines (38 loc) · 1.32 KB
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
#!/usr/bin/python3
import argparse
import collections
import fetcher
import printing
PivotPoints = collections.namedtuple('PivotPoints', 'ticker s3 s2 s1 pp r1 r2 r3')
def CalculatePivotPoints(ticker, df):
today = df.tail(1)
high = float(today[fetcher.DataSource.HIGH])
low = float(today[fetcher.DataSource.LOW])
close = float(today[fetcher.DataSource.CLOSE])
pp = (high + low + close) / 3
r1 = pp + (pp - low)
s1 = pp - (high - pp)
r2 = pp + (2*(pp - low))
s2 = pp - (2*(high - pp))
r3 = high + (2*(pp - low))
s3 = low - (2*(high - pp))
return PivotPoints(ticker, s3, s2, s1, pp, r1, r2, r3)
def main(args):
rows = []
for ticker in args.tickers:
df = fetcher.DataFetcher().FetchData(ticker)
p = CalculatePivotPoints(ticker, df)
rows.append([p.ticker,
'{:.2f}'.format(p.s3),
'{:.2f}'.format(p.s2),
'{:.2f}'.format(p.s1),
'{:.2f}'.format(p.pp),
'{:.2f}'.format(p.r1),
'{:.2f}'.format(p.r2),
'{:.2f}'.format(p.r3)])
printer = printing.TabularPrinter(['Ticker', 'S3', 'S2', 'S1', 'PP', 'R1', 'R2', 'R3'])
printer.print(rows)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('tickers', nargs='+')
main(parser.parse_args())