-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYahoo.py
More file actions
61 lines (36 loc) · 1.12 KB
/
Yahoo.py
File metadata and controls
61 lines (36 loc) · 1.12 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
import pandas as pd
import yahoo_finance as yahoo
from yahoo_finance import Share
from pandas import ExcelWriter
import time
import finsymbols as f
from pandas import ExcelWriter
import numpy as np
writer = ExcelWriter('c:\\temp\\heyo.xlsx')
print ('Script Start Time =' +time.ctime())
sp=[]
sp.append(f.get_sp500_symbols())
df =pd.DataFrame(sp[0])
stocks = df['symbol']
list1=[]
list2=[]
list3=[]
#list4=[]
list5=[]
list6=[]
for stock in stocks:
yahoo = Share(stock)
list1.append((yahoo.get_price()))
list2.append((yahoo.get_open()))
list3.append((str(stock)))
#list4.append((yahoo.get_market_cap()))
list5.append((yahoo.get_price_earnings_ratio()))
list6.append((yahoo.get_price_earnings_growth_ratio()))
Last = zip(list3,list1,list2,list5,list6)
df2=pd.DataFrame(Last)
dff=pd.concat([df,df2],axis=1)
dff.rename(columns = {0:'Symbol',1:'Current_Price',2:'Open_Price',3:'P/E Ratio',4:'P/E/G Ratio'},inplace=True)
dff.sort_values(['symbol'], ascending =True)
dff.to_excel(writer,'Data',index=None)
writer.save()
print ('Script End Time =' +time.ctime())