import numpy as np
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import matplotlib.pyplot as plt
import pandas_datareader as pdr
% matplotlib inline
goog = pdr.get_data_google('GOOG')
/Users/mjmacarty/anaconda3/lib/python3.6/site-packages/pandas_datareader/google/daily.py:40: UnstableAPIWarning: The Google Finance API has not been stable since late 2017. Requests seem to fail at random. Failure is especially common when bulk downloading. warnings.warn(UNSTABLE_WARNING, UnstableAPIWarning)
--------------------------------------------------------------------------- RemoteDataError Traceback (most recent call last) <ipython-input-4-c80b285b3d5a> in <module>() ----> 1 goog = pdr.get_data_google('GOOG') ~/anaconda3/lib/python3.6/site-packages/pandas_datareader/data.py in get_data_google(*args, **kwargs) 57 58 def get_data_google(*args, **kwargs): ---> 59 return GoogleDailyReader(*args, **kwargs).read() 60 61 ~/anaconda3/lib/python3.6/site-packages/pandas_datareader/base.py in read(self) 204 if isinstance(self.symbols, (compat.string_types, int)): 205 df = self._read_one_data(self.url, --> 206 params=self._get_params(self.symbols)) 207 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT']) 208 elif isinstance(self.symbols, DataFrame): ~/anaconda3/lib/python3.6/site-packages/pandas_datareader/base.py in _read_one_data(self, url, params) 82 """ read one data from specified URL """ 83 if self._format == 'string': ---> 84 out = self._read_url_as_StringIO(url, params=params) 85 elif self._format == 'json': 86 out = self._get_response(url, params=params).json() ~/anaconda3/lib/python3.6/site-packages/pandas_datareader/base.py in _read_url_as_StringIO(self, url, params) 93 Open url (and retry) 94 """ ---> 95 response = self._get_response(url, params=params) 96 text = self._sanitize_response(response) 97 out = StringIO() ~/anaconda3/lib/python3.6/site-packages/pandas_datareader/base.py in _get_response(self, url, params, headers) 153 msg += '\nResponse Text:\n{0}'.format(last_response_text) 154 --> 155 raise RemoteDataError(msg) 156 157 def _get_crumb(self, *args): RemoteDataError: Unable to read URL: https://finance.google.com/finance/historical?q=GOOG&startdate=Jan+01%2C+2010&enddate=Sep+02%2C+2018&output=csv Response Text: b'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>Sorry...</title><style> body { font-family: verdana, arial, sans-serif; background-color: #fff; color: #000; }</style></head><body><div><table><tr><td><b><font face=sans-serif size=10><font color=#4285f4>G</font><font color=#ea4335>o</font><font color=#fbbc05>o</font><font color=#4285f4>g</font><font color=#34a853>l</font><font color=#ea4335>e</font></font></b></td><td style="text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%"><div style="border-bottom: 1px solid #dfdfdf;">Sorry...</div></td></tr></table></div><div style="margin-left: 4em;"><h1>We\'re sorry...</h1><p>... but your computer or network may be sending automated queries. To protect our users, we can\'t process your request right now.</p></div><div style="margin-left: 4em;">See <a href="https://support.google.com/websearch/answer/86640">Google Help</a> for more information.<br/><br/></div><div style="text-align: center; border-top: 1px solid #dfdfdf;"><a href="https://www.google.com">Google Home</a></div></body></html>'
import fix_yahoo_finance as fyf
from pandas_datareader import data as pdr
fyf.pdr_override()
goog = pdr.get_data_yahoo('GOOG', start='2017-01-01')
goog.head()
[*********************100%***********************] 1 of 1 downloaded
Open | High | Low | Close | Adj Close | Volume | |
---|---|---|---|---|---|---|
Date | ||||||
2017-01-03 | 778.809998 | 789.630005 | 775.799988 | 786.140015 | 786.140015 | 1657300 |
2017-01-04 | 788.359985 | 791.340027 | 783.159973 | 786.900024 | 786.900024 | 1073000 |
2017-01-05 | 786.080017 | 794.479980 | 785.020020 | 794.020020 | 794.020020 | 1335200 |
2017-01-06 | 795.260010 | 807.900024 | 792.203979 | 806.150024 | 806.150024 | 1640200 |
2017-01-09 | 806.400024 | 809.966003 | 802.830017 | 806.650024 | 806.650024 | 1272400 |
goog = fyf.download('GOOG', start='2017-01-01')
goog.head()
[*********************100%***********************] 1 of 1 downloaded
Open | High | Low | Close | Adj Close | Volume | |
---|---|---|---|---|---|---|
Date | ||||||
2017-01-03 | 778.809998 | 789.630005 | 775.799988 | 786.140015 | 786.140015 | 1657300 |
2017-01-04 | 788.359985 | 791.340027 | 783.159973 | 786.900024 | 786.900024 | 1073000 |
2017-01-05 | 786.080017 | 794.479980 | 785.020020 | 794.020020 | 794.020020 | 1335200 |
2017-01-06 | 795.260010 | 807.900024 | 792.203979 | 806.150024 | 806.150024 | 1640200 |
2017-01-09 | 806.400024 | 809.966003 | 802.830017 | 806.650024 | 806.650024 | 1272400 |
stocks = ['FB', 'AMZN', 'NFLX', 'GOOG']
data = pdr.get_data_yahoo(stocks, start='2017-01-01')
data.head()
[*********************100%***********************] 4 of 4 downloaded
Open | High | Low | ... | Close | Adj Close | Volume | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AMZN | FB | GOOG | NFLX | AMZN | FB | GOOG | NFLX | AMZN | FB | ... | GOOG | NFLX | AMZN | FB | GOOG | NFLX | AMZN | FB | GOOG | NFLX | |
Date | |||||||||||||||||||||
2017-01-03 | 757.919983 | 116.029999 | 778.809998 | 124.959999 | 758.760010 | 117.839996 | 789.630005 | 128.190002 | 747.700012 | 115.510002 | ... | 786.140015 | 127.489998 | 753.669983 | 116.860001 | 786.140015 | 127.489998 | 3521100 | 20663900 | 1657300 | 9437900 |
2017-01-04 | 758.390015 | 117.550003 | 788.359985 | 127.489998 | 759.679993 | 119.660004 | 791.340027 | 130.169998 | 754.200012 | 117.290001 | ... | 786.900024 | 129.410004 | 757.179993 | 118.690002 | 786.900024 | 129.410004 | 2510500 | 19630900 | 1073000 | 7843600 |
2017-01-05 | 761.549988 | 118.860001 | 786.080017 | 129.220001 | 782.400024 | 120.949997 | 794.479980 | 132.750000 | 760.260010 | 118.320000 | ... | 794.020020 | 131.809998 | 780.450012 | 120.669998 | 794.020020 | 131.809998 | 5830100 | 19492200 | 1335200 | 10185500 |
2017-01-06 | 782.359985 | 120.980003 | 795.260010 | 132.080002 | 799.440002 | 123.879997 | 807.900024 | 133.880005 | 778.479980 | 120.029999 | ... | 806.150024 | 131.070007 | 795.989990 | 123.410004 | 806.150024 | 131.070007 | 5986200 | 28545300 | 1640200 | 10657900 |
2017-01-09 | 798.000000 | 123.550003 | 806.400024 | 131.479996 | 801.770020 | 125.430000 | 809.966003 | 131.990005 | 791.770020 | 123.040001 | ... | 806.650024 | 130.949997 | 796.919983 | 124.900002 | 806.650024 | 130.949997 | 3440100 | 22861600 | 1272400 | 5766900 |
5 rows × 24 columns
data = fyf.download(stocks, start='2017-01-01')
data.head()
[*********************100%***********************] 4 of 4 downloaded
Open | High | Low | ... | Close | Adj Close | Volume | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AMZN | FB | GOOG | NFLX | AMZN | FB | GOOG | NFLX | AMZN | FB | ... | GOOG | NFLX | AMZN | FB | GOOG | NFLX | AMZN | FB | GOOG | NFLX | |
Date | |||||||||||||||||||||
2017-01-03 | 757.919983 | 116.029999 | 778.809998 | 124.959999 | 758.760010 | 117.839996 | 789.630005 | 128.190002 | 747.700012 | 115.510002 | ... | 786.140015 | 127.489998 | 753.669983 | 116.860001 | 786.140015 | 127.489998 | 3521100 | 20663900 | 1657300 | 9437900 |
2017-01-04 | 758.390015 | 117.550003 | 788.359985 | 127.489998 | 759.679993 | 119.660004 | 791.340027 | 130.169998 | 754.200012 | 117.290001 | ... | 786.900024 | 129.410004 | 757.179993 | 118.690002 | 786.900024 | 129.410004 | 2510500 | 19630900 | 1073000 | 7843600 |
2017-01-05 | 761.549988 | 118.860001 | 786.080017 | 129.220001 | 782.400024 | 120.949997 | 794.479980 | 132.750000 | 760.260010 | 118.320000 | ... | 794.020020 | 131.809998 | 780.450012 | 120.669998 | 794.020020 | 131.809998 | 5830100 | 19492200 | 1335200 | 10185500 |
2017-01-06 | 782.359985 | 120.980003 | 795.260010 | 132.080002 | 799.440002 | 123.879997 | 807.900024 | 133.880005 | 778.479980 | 120.029999 | ... | 806.150024 | 131.070007 | 795.989990 | 123.410004 | 806.150024 | 131.070007 | 5986200 | 28545300 | 1640200 | 10657900 |
2017-01-09 | 798.000000 | 123.550003 | 806.400024 | 131.479996 | 801.770020 | 125.430000 | 809.966003 | 131.990005 | 791.770020 | 123.040001 | ... | 806.650024 | 130.949997 | 796.919983 | 124.900002 | 806.650024 | 130.949997 | 3440100 | 22861600 | 1272400 | 5766900 |
5 rows × 24 columns
data['Close'].head()
AMZN | FB | GOOG | NFLX | |
---|---|---|---|---|
Date | ||||
2017-01-03 | 753.669983 | 116.860001 | 786.140015 | 127.489998 |
2017-01-04 | 757.179993 | 118.690002 | 786.900024 | 129.410004 |
2017-01-05 | 780.450012 | 120.669998 | 794.020020 | 131.809998 |
2017-01-06 | 795.989990 | 123.410004 | 806.150024 | 131.070007 |
2017-01-09 | 796.919983 | 124.900002 | 806.650024 | 130.949997 |
data['Close']['AMZN']
Date 2017-01-03 753.669983 2017-01-04 757.179993 2017-01-05 780.450012 2017-01-06 795.989990 2017-01-09 796.919983 2017-01-10 795.900024 2017-01-11 799.020020 2017-01-12 813.640015 2017-01-13 817.140015 2017-01-17 809.719971 2017-01-18 807.479980 2017-01-19 809.039978 2017-01-20 808.330017 2017-01-23 817.880005 2017-01-24 822.440002 2017-01-25 836.520020 2017-01-26 839.150024 2017-01-27 835.770020 2017-01-30 830.380005 2017-01-31 823.479980 2017-02-01 832.349976 2017-02-02 839.950012 2017-02-03 810.200012 2017-02-06 807.640015 2017-02-07 812.500000 2017-02-08 819.710022 2017-02-09 821.359985 2017-02-10 827.460022 2017-02-13 836.530029 2017-02-14 836.390015 ... 2018-07-23 1802.000000 2018-07-24 1829.239990 2018-07-25 1863.609985 2018-07-26 1808.000000 2018-07-27 1817.270020 2018-07-30 1779.219971 2018-07-31 1777.439941 2018-08-01 1797.170044 2018-08-02 1834.329956 2018-08-03 1823.290039 2018-08-06 1847.750000 2018-08-07 1862.479980 2018-08-08 1886.520020 2018-08-09 1898.520020 2018-08-10 1886.300049 2018-08-13 1896.199951 2018-08-14 1919.650024 2018-08-15 1882.619995 2018-08-16 1886.520020 2018-08-17 1882.219971 2018-08-20 1876.709961 2018-08-21 1883.420044 2018-08-22 1904.900024 2018-08-23 1902.900024 2018-08-24 1905.390015 2018-08-27 1927.680054 2018-08-28 1932.819946 2018-08-29 1998.099976 2018-08-30 2002.380005 2018-08-31 2012.709961 Name: AMZN, Length: 420, dtype: float64