-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptf.py
More file actions
90 lines (75 loc) · 3.42 KB
/
Copy pathptf.py
File metadata and controls
90 lines (75 loc) · 3.42 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
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
83
84
85
86
87
88
89
90
from argparse import ArgumentParser
from yahoo_finance import Share
import pyperclip
import urllib2
from bs4 import BeautifulSoup
currentrelease = 'Pattern Target Finder 1.2'
#v1.2 - Added get earnings date function
#v1.1 - Get's current delayed price from Yahoo_Finance
# Allowed you to override price -p 123
# Copies output to the clipboard
#v1.0 - calculates the pattern's target
#feature - get earning date? -e ? Screen scrape; woudl be nice to have.
def getArgs():
parser = ArgumentParser(description = currentrelease)
parser.add_argument("-t", "--ticker", required=False, dest="ticker", help="ticker for lookup", metavar="ticker")
parser.add_argument("-p", "--price", required=False, dest="price", help="specify price", metavar="price")
parser.add_argument("-rh", "--high", required=True, dest="high", help="recent high", metavar="high")
parser.add_argument("-rl", "--low", required=True, dest="low", help="recent low", metavar="low")
parser.add_argument("-e", "--earnings", required=False, dest="earnings", help="get earnings date", action="store_true")
#parser.add_argument("-perf", "--perfcheck", required=False, dest="perfcheck", help="use with init file to check performance", action="store_true")
args = parser.parse_args()
return args
def patternmove(high, low):
move = float(high) - float(low)
return move
def patterntarget(high, move):
target = float(high) + float(move)
return target
def priceWork(stock):
"""
Returns delayed price for ticker and reporting for ticker from Yahoo_Finance module (Yahoo_finance module delayed price can be VERY delayed, hence realtime module)
"""
subpricequote = stock.get_price()
#output.append(subpricequote)
return subpricequote
#def clipboard1(ticker, price, move, target):
def earningsdate(ticker):
baseurl = 'https://www.zacks.com/stock/quote/'
endurl = ticker
url = baseurl + ticker
page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read(), "lxml")
earnings = soup.find_all("td")
return earnings[58].text #item 58 gives you *AMC8/4/16 or 10/20/2016 or BMO8/4/16
#----------------------------------------------------------------------
if __name__ == "__main__":
myargs = getArgs()
if myargs.ticker is not "" and myargs.price is None: #if you don't specify -p price then it get's the current delayed price
stock = Share(myargs.ticker)
price = priceWork(stock)
elif myargs.ticker is not "" and myargs.price > 0: #if you specify price, then it uses that as the starting price.
#print myargs.ticker, myargs.price
stock = myargs.ticker
price = myargs.price
move = patternmove(myargs.high, myargs.low)
target = patterntarget(myargs.high, move)
if myargs.earnings is True:
earnings = earningsdate(myargs.ticker)
else:
earnings = None
#print target
if myargs.ticker is not "" and price is not None and earnings is not None:
print myargs.ticker + ", " + str(price) + ", " + str(target) + ", " + str(earningsdate(myargs.ticker))
newpasteitem = myargs.ticker + ", " + str(price) + ", " + str(target) + ", " + str(earningsdate(myargs.ticker))
pyperclip.copy(newpasteitem)
elif myargs.ticker is not "" and price is not None:
print myargs.ticker + ", " + str(price) + ", " + str(target)
newpasteitem = myargs.ticker + ", " + str(price) + ", " + str(target)
pyperclip.copy(newpasteitem)
else:
print target
newpasteitem = str(target)
pyperclip.copy(newpasteitem)
# if myargs.earnings is True:
# print earningsdate(myargs.ticker)