Skip to content

Commit

Permalink
BUG: Yahoo actions adjustment is incorrect
Browse files Browse the repository at this point in the history
Fix Yahoo actions dividend adjustment
  • Loading branch information
bashtage committed Sep 11, 2018
1 parent 38ef0c7 commit 02f1fdf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions docs/source/whatsnew/v0.7.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ Bug Fixes
- Added support for passing the API KEY to QuandlReader either directly or by
setting the environmental variable QUANDL_API_KEY (:issue:`485`).
- Added support for optionally passing a custom base_url to the EnigmaReader (:issue:`499`).
- Fix Yahoo! price data (:issue:`498`)
- Fix Yahoo! price data (:issue:`498`).
- Added back support for Yahoo! price, dividends, and splits data for stocks
and currency pairs (:issue:`487`).
- Add `is_list_like` to compatibility layer to avoid failure on pandas >= 0.23 (:issue:`520`)
- Add `is_list_like` to compatibility layer to avoid failure on pandas >= 0.23 (:issue:`520`).
- Fixed Yahoo! time offset (:issue:`487`).
- Fix Yahoo! quote reader (:issue: `540`)
- Fix Yahoo! quote reader (:issue: `540`).
- Remove import of deprecated `tm.get_data_path` (:issue: `566`)
- Allow full usage of stooq url parameters
- Removed unused requests-file and requests-ftp dependencies
- Allow full usage of stooq url parameters.
- Removed unused requests-file and requests-ftp dependencies.
- Fix Yahoo! actions issue where the default reporting adjusts dividends. The unadjusted
dividends may lack precision due to accumulated numerical error when converting adjusted
to the original dividend amount. (:issue: `495`)
5 changes: 3 additions & 2 deletions pandas_datareader/tests/yahoo/test_yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def test_get_data_yahoo_actions(self):
start = datetime(1990, 1, 1)
end = datetime(2000, 4, 5)

actions = web.get_data_yahoo_actions('BHP.AX', start, end)
actions = web.get_data_yahoo_actions('BHP.AX', start, end,
adjust_dividends=True)

assert sum(actions['action'] == 'DIVIDEND') == 21
assert sum(actions['action'] == 'SPLIT') == 1
Expand Down Expand Up @@ -254,7 +255,7 @@ def test_yahoo_DataReader(self):
3.05, 2.65, 2.65, 2.65]},
index=exp_idx)
exp.index.name = 'Date'
tm.assert_frame_equal(result.reindex_like(exp).round(5), exp.round(5))
tm.assert_frame_equal(result.reindex_like(exp).round(2), exp.round(2))

result = web.get_data_yahoo_actions('AAPL', start, end,
adjust_dividends=True)
Expand Down
3 changes: 2 additions & 1 deletion pandas_datareader/yahoo/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ def _read_one_data(self, url, params):
splits['Splits'] = 1.0 / splits['SplitRatio']
prices = prices.join(splits['Splits'], how='outer')

if 'DIVIDEND' in types and self.adjust_dividends:
if 'DIVIDEND' in types and not self.adjust_dividends:
# Adjust dividends to deal with splits
adj = prices['Splits'].sort_index(ascending=False).fillna(
1).cumprod()
adj = 1.0 / adj
prices['Dividends'] = prices['Dividends'] * adj

return prices
Expand Down

0 comments on commit 02f1fdf

Please sign in to comment.