-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_buys_through_read_yf.py
57 lines (52 loc) · 1.63 KB
/
find_buys_through_read_yf.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
import csv
import uuid
import algo_yf as algo
import timeit
import pickle
from email_sender import send_email
from tqdm import tqdm
start = timeit.default_timer()
def read_exchange(file):
with open(file) as f:
reader = csv.reader(f)
symbols = []
for line in reader:
symbols.append(line[0])
f.close()
return list(sorted(symbols[1:]))
exchanges = ['./exchanges/nasdaq.csv', './exchanges/nyse.csv']
all_symbols = []
print('Reading Exchange Data')
for exchange in exchanges:
symbols = read_exchange(exchange)
all_symbols += symbols
all_symbols = list(sorted(all_symbols))
print('Using {0} Symbols'.format(len(all_symbols)))
buys = []
print('Reading Stock Data')
with open('yahoo-data.p', 'rb') as f:
data = pickle.load(f)
f.close()
for symbol in tqdm(all_symbols):
try:
if (algo.buy_signal(data[symbol], under_value=10)):
buys.append(symbol)
except Exception as e:
continue
if len(buys) > 0:
print('Getting Fundamental Data for Buy Signal Stocks...')
rows = [['Symbol', 'Business Summary', 'Sector', 'Forward EPS', 'Forward P/E', 'P/B']]
for buy in tqdm(buys):
buy_info = algo.get_stock_info(buy)
row = [buy] + buy_info
rows.append(row)
new_id = uuid.uuid1()
file_name = './runs/{0}.csv'.format(new_id)
with open(file_name, 'w', encoding='utf-8', newline='') as f:
writer = csv.writer(f)
writer.writerows(rows)
f.close()
print('Sending Email to brandonfan1256@gmail.com...')
send_email('brandonfan1256@gmail.com', 'Brandon', buys, file_name)
else:
print('No buys were found today...')