-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement historical finance data from Google Finance #3814
Changes from 4 commits
8196db9
ad89365
ee10caa
f43d245
c052957
0aadb11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import unittest | ||
import nose | ||
from datetime import datetime | ||
|
||
import pandas as pd | ||
import pandas.io.data as web | ||
from pandas.util.testing import (network, assert_series_equal) | ||
from numpy.testing.decorators import slow | ||
|
||
import urllib2 | ||
|
||
|
||
class TestGoogle(unittest.TestCase): | ||
|
||
@slow | ||
@network | ||
def test_google(self): | ||
# asserts that google is minimally working and that it throws | ||
# an excecption when DataReader can't get a 200 response from | ||
start = datetime(2010, 1, 1) | ||
end = datetime(2013, 01, 27) | ||
|
||
try: | ||
self.assertEquals( | ||
web.DataReader("F", 'google', start, end)['Close'][-1], | ||
13.68) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get 12.68 :s There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Erm... I take it back, it seems to now be 13.68. :) |
||
|
||
self.assertRaises( | ||
Exception, | ||
lambda: web.DataReader("NON EXISTENT TICKER", 'google', | ||
start, end)) | ||
except urllib2.URLError: | ||
try: | ||
urllib2.urlopen('http://www.google.com') | ||
except urllib2.URLError: | ||
raise nose.SkipTest | ||
else: | ||
raise | ||
|
||
|
||
@slow | ||
@network | ||
def test_get_quote(self): | ||
self.assertRaises(NotImplementedError, | ||
lambda: web.get_quote_google(pd.Series(['GOOG', 'AAPL', 'GOOG']))) | ||
|
||
@slow | ||
@network | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will these tests even run on travis on any python except 2.6? probably should just mark as network OR slow: if they use the network then network, otherwise slow if they are slow but not both since the tests exclude one or the other so if you both they won't be run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure @cpcloud I changed it to |
||
def test_get_data(self): | ||
import numpy as np | ||
df = web.get_data_google('GOOG') | ||
print(df.Volume.ix['OCT-08-2010']) | ||
assert df.Volume.ix['OCT-08-2010'] == 2863473 | ||
|
||
sl = ['AAPL', 'AMZN', 'GOOG'] | ||
pan = web.get_data_google(sl, '2012') | ||
ts = pan.Close.GOOG.index[pan.Close.AAPL > pan.Close.GOOG] | ||
assert ts[0].dayofyear == 96 | ||
|
||
pan = web.get_data_google(['GE', 'MSFT', 'INTC'], 'JAN-01-12', 'JAN-31-12') | ||
expected = [19.02, 28.23, 25.39] | ||
result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist() | ||
assert result == expected | ||
|
||
# sanity checking | ||
t= np.array(result) | ||
assert np.issubdtype(t.dtype, np.floating) | ||
assert t.shape == (3,) | ||
|
||
expected = [[ 18.99, 28.4 , 25.18], | ||
[ 18.58, 28.31, 25.13], | ||
[ 19.03, 28.16, 25.52], | ||
[ 18.81, 28.82, 25.87]] | ||
result = pan.Open.ix['Jan-15-12':'Jan-20-12'][['GE', 'MSFT', 'INTC']].values | ||
assert (result == expected).all() | ||
|
||
# sanity checking | ||
t= np.array(pan) | ||
assert np.issubdtype(t.dtype, np.floating) | ||
|
||
|
||
if __name__ == '__main__': | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], | ||
exit=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
google? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hayd The evils of copy and paste. Corrected