Skip to content

Commit

Permalink
ENH: Add splits to api
Browse files Browse the repository at this point in the history
  • Loading branch information
David Stephens committed Dec 17, 2019
1 parent 1cc5939 commit bc2134c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions pandas_finance/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ def trading_data(self):
return pdr.get_data_yahoo(self.ticker, session=self._session,
start=START_DATE)

@property
def actions(self):
return pdr.get_data_yahoo_actions(self.ticker, session=self._session,
start=START_DATE)

@property
def dividends(self):
actions = pdr.get_data_yahoo_actions(self.ticker, session=self._session,
start=START_DATE)
actions = self.actions
dividends = actions[actions['action'] == 'DIVIDEND']['value']
dividends.name = 'Dividends'
return dividends

@property
def splits(self):
actions = self.actions
splits = actions[actions['action'] == 'SPLIT']['value']
splits.name = 'Splits'
return splits

@property
def annual_dividend(self):
if 'forwardAnnualDividendRate' in self.quotes.index:
Expand Down
5 changes: 4 additions & 1 deletion pandas_finance/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_equity_price(self):
def test_historical_vol(self):
vol = self.aapl.hist_vol(30, end_date=self.date)
self.assertAlmostEqual(vol, 0.484, 3)

@unittest.skip('Yahoo options api broken')
def test_options(self):
self.assertIsInstance(self.aapl.options, OptionChain)
Expand All @@ -31,6 +31,9 @@ def test_annual_dividend(self):
def test_dividends(self):
self.assertEqual(self.aapl.dividends[datetime.date(2015, 11, 5)], 0.52)

def test_splits(self):
self.assertAlmostEqual(self.aapl.splits[datetime.date(2014, 6, 9)], 0.142857, 5)

def test_dividends_no_data(self):
self.assertEqual(len(self.tsla.dividends), 0)

Expand Down

0 comments on commit bc2134c

Please sign in to comment.