Skip to content

Commit

Permalink
BUG: Prevents payout of dividend on final trading close
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkirk committed Jun 24, 2015
1 parent 1c7aaf8 commit 1109607
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions zipline/finance/performance/tracker.py
Expand Up @@ -346,7 +346,7 @@ def process_close_position(self, event):
if txn:
self.process_transaction(txn)

def check_upcoming_dividends(self, next_trading_day):
def check_upcoming_dividends(self, completed_date):
"""
Check if we currently own any stocks with dividends whose ex_date is
the next trading day. Track how much we should be payed on those
Expand All @@ -361,6 +361,13 @@ def check_upcoming_dividends(self, next_trading_day):
# period, so bail.
return

# Get the next trading day and, if it is outside the bounds of the
# simulation, bail.
next_trading_day = TradingEnvironment.instance().\
next_trading_day(completed_date)
if (next_trading_day is None) or (next_trading_day >= self.last_close):
return

# Dividends whose ex_date is the next trading day. We need to check if
# we own any of these stocks so we know to pay them out when the pay
# date comes.
Expand Down Expand Up @@ -402,13 +409,9 @@ def handle_minute_close(self, dt):
bench_since_open,
account)

# if this is the close, save the returns objects for cumulative risk
# calculations and update dividends for the next day.
# if this is the close, update dividends for the next day.
if dt == self.market_close:
next_trading_day = TradingEnvironment.instance().\
next_trading_day(todays_date)
if next_trading_day:
self.check_upcoming_dividends(next_trading_day)
self.check_upcoming_dividends(todays_date)

def handle_intraday_market_close(self, new_mkt_open, new_mkt_close):
"""
Expand Down Expand Up @@ -460,9 +463,8 @@ def handle_market_close_daily(self):
self.todays_performance.period_open = self.market_open
self.todays_performance.period_close = self.market_close

next_trading_day = env.next_trading_day(completed_date)
if next_trading_day:
self.check_upcoming_dividends(next_trading_day)
# Check for any dividends
self.check_upcoming_dividends(completed_date)

return daily_update

Expand Down

0 comments on commit 1109607

Please sign in to comment.