-
Notifications
You must be signed in to change notification settings - Fork 2
/
equity price.py
32 lines (27 loc) · 1.06 KB
/
equity price.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
import datetime
import pandas as pd
import pandas_datareader.data as web
import urllib2
def readDataFromWeb(assets, startDate, endDate, source = 'yahoo'):
PROXIES = {'https': "https://proxy.companyname.net:8080"}
Proxy = urllib2.ProxyHandler(PROXIES)
Opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
prices = {}
volumes = {}
for asset in assets:
try:
df = web.DataReader(assets, source, start=startDate, end=endDate)
prices[assets] = df['Adj Close']
volumes[assets] = df['Volume']
except:
print "Error: skipping", asset
prices = pd.DataFrame(prices)
volumes = pd.DataFrame(volumes)
return pd.Panel({'Price' : prices, 'Return' : prices.pct_chang(), 'Volume':volumes})
def main():
start = datetime.date(2016,12,20)
end = datetime.date.today() - datetime.timedelta(1)
Assetlist = ['YHOO', 'AAPL', 'IBM','F']
Data = readDataFromWeb(Assetlist,start,end)
Data.Price