Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/whatsnew/v0.7.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ Bug Fixes
- Added support for passing the API KEY to QuandlReader either directly or by
setting the environmental variable QUANDL_API_KEY (:issue:`485`).
- Handle Morningstar index volume data properly (:issue:`486`).
- Added back support for Yahoo! price, dividends, and splits data for stocks
and currency pairs (:issue:`487`).
17 changes: 0 additions & 17 deletions pandas_datareader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
RobinhoodQuoteReader
from pandas_datareader.stooq import StooqDailyReader
from pandas_datareader.tiingo import TiingoDailyReader, TiingoQuoteReader
from pandas_datareader.yahoo.actions import (YahooActionReader, YahooDivReader)
from pandas_datareader.yahoo.components import _get_data as \
get_components_yahoo
from pandas_datareader.yahoo.daily import YahooDailyReader
Expand Down Expand Up @@ -60,7 +59,6 @@ def get_data_google(*args, **kwargs):


def get_data_yahoo(*args, **kwargs):
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions'))
return YahooDailyReader(*args, **kwargs).read()


Expand All @@ -70,7 +68,6 @@ def get_data_enigma(*args, **kwargs):

def get_data_yahoo_actions(*args, **kwargs):
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions'))
return YahooActionReader(*args, **kwargs).read()


def get_quote_yahoo(*args, **kwargs):
Expand Down Expand Up @@ -294,20 +291,6 @@ def DataReader(name, data_source=None, start=None, end=None,
retry_count=retry_count, pause=pause,
session=session).read()

elif data_source == "yahoo-actions":
raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions'))
return YahooActionReader(symbols=name, start=start, end=end,
retry_count=retry_count, pause=pause,
session=session).read()

elif data_source == "yahoo-dividends":
comp = 'Yahoo Dividends'
raise ImmediateDeprecationError(DEP_ERROR_MSG.format(comp))
return YahooDivReader(symbols=name, start=start, end=end,
adjust_price=False, chunksize=25,
retry_count=retry_count, pause=pause,
session=session, interval='d').read()

elif data_source == "google":
return GoogleDailyReader(symbols=name, start=start, end=end,
chunksize=25,
Expand Down
113 changes: 113 additions & 0 deletions pandas_datareader/yahoo/FX.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import time
import json
import warnings
from pandas import (DataFrame, Series, to_datetime, concat)
from pandas_datareader.yahoo.daily import YahooDailyReader
import pandas.compat as compat
from pandas_datareader._utils import (RemoteDataError, SymbolWarning)
from pandas.core.indexes.numeric import Int64Index


class YahooFXReader(YahooDailyReader):
"""
Returns DataFrame of historical prices for currencies

Parameters
----------
symbols : string, array-like object (list, tuple, Series), or DataFrame
Single stock symbol (ticker), array-like object of symbols or
DataFrame with index containing stock symbols.
start : string, (defaults to '1/1/2010')
Starting date, timestamp. Parses many different kind of date
representations (e.g., 'JAN-01-2010', '1/1/10', 'Jan, 1, 1980')
end : string, (defaults to today)
Ending date, timestamp. Same format as starting date.
retry_count : int, default 3
Number of times to retry query request.
pause : int, default 0
Time, in seconds, to pause between consecutive queries of chunks. If
single value given for symbol, represents the pause between retries.
session : Session, default None
requests.sessions.Session instance to be used
chunksize : int, default 25 (NOT IMPLEMENTED)
Number of symbols to download consecutively before intiating pause.
interval : string, default '1d'
Valid values are '1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y',
'10y', 'ytd', 'max'
"""

def _get_params(self, symbol):
unix_start = int(time.mktime(self.start.timetuple()))
day_end = self.end.replace(hour=23, minute=59, second=59)
unix_end = int(time.mktime(day_end.timetuple()))

params = {
'symbol': symbol + '=X',
'period1': unix_start,
'period2': unix_end,
'interval': self.interval, # deal with this
'includePrePost': 'true',
'events': 'div|split|earn',
'corsDomain': 'finance.yahoo.com'
}
return params

def read(self):
"""Read data"""
try:
# If a single symbol, (e.g., 'GOOG')
if isinstance(self.symbols, (compat.string_types, int)):
df = self._read_one_data(self.symbols)

# Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
elif isinstance(self.symbols, DataFrame):
df = self._dl_mult_symbols(self.symbols.index)
else:
df = self._dl_mult_symbols(self.symbols)

if isinstance(df.index, Int64Index):
df = df.set_index('Date')

if 'Volume' in df:
df = df.drop('Volume', axis=1)

return df.sort_index().dropna(how='all')
finally:
self.close()

def _read_one_data(self, symbol):
""" read one data from specified URL """
url = 'https://query1.finance.yahoo.com/v8/finance/chart/{}=X'\
.format(symbol)
params = self._get_params(symbol)

resp = self._get_response(url, params=params)
jsn = json.loads(resp.text)

data = jsn['chart']['result'][0]
df = DataFrame(data['indicators']['quote'][0])
df.insert(0, 'date', to_datetime(Series(data['timestamp']),
unit='s').dt.date)
df.columns = map(str.capitalize, df.columns)
return df

def _dl_mult_symbols(self, symbols):
stocks = {}
failed = []
passed = []
for sym in symbols:
try:
df = self._read_one_data(sym)
df['PairCode'] = sym
stocks[sym] = df
passed.append(sym)
except IOError:
msg = 'Failed to read symbol: {0!r}, replacing with NaN.'
warnings.warn(msg.format(sym), SymbolWarning)
failed.append(sym)

if len(passed) == 0:
msg = "No data fetched using {0!r}"
raise RemoteDataError(msg.format(self.__class__.__name__))
else:
return concat(stocks).set_index(['PairCode', 'Date'])
53 changes: 0 additions & 53 deletions pandas_datareader/yahoo/actions.py

This file was deleted.

Loading