diff --git a/tests/pipeline/test_us_equity_pricing_loader.py b/tests/pipeline/test_us_equity_pricing_loader.py index b75f4799..a10ea0fb 100644 --- a/tests/pipeline/test_us_equity_pricing_loader.py +++ b/tests/pipeline/test_us_equity_pricing_loader.py @@ -175,43 +175,43 @@ DIVIDENDS = DataFrame( [ # Before query range, should be excluded. {'declared_date': Timestamp('2015-05-01', tz='UTC').to_datetime64(), - 'ex_date': Timestamp('2015-06-02', tz='UTC').to_datetime64(), + 'ex_date': Timestamp('2015-06-01', tz='UTC').to_datetime64(), 'record_date': Timestamp('2015-06-03', tz='UTC').to_datetime64(), 'pay_date': Timestamp('2015-06-05', tz='UTC').to_datetime64(), 'amount': 90.0, 'sid': 1}, # First day of query range, should be excluded. {'declared_date': Timestamp('2015-06-01', tz='UTC').to_datetime64(), - 'ex_date': Timestamp('2015-06-11', tz='UTC').to_datetime64(), + 'ex_date': Timestamp('2015-06-10', tz='UTC').to_datetime64(), 'record_date': Timestamp('2015-06-15', tz='UTC').to_datetime64(), 'pay_date': Timestamp('2015-06-17', tz='UTC').to_datetime64(), 'amount': 80.0, 'sid': 3}, # Third day of query range, should have last_row of 2 {'declared_date': Timestamp('2015-06-01', tz='UTC').to_datetime64(), - 'ex_date': Timestamp('2015-06-15', tz='UTC').to_datetime64(), - 'record_date': Timestamp('2015-06-16', tz='UTC').to_datetime64(), + 'ex_date': Timestamp('2015-06-12', tz='UTC').to_datetime64(), + 'record_date': Timestamp('2015-06-15', tz='UTC').to_datetime64(), 'pay_date': Timestamp('2015-06-17', tz='UTC').to_datetime64(), 'amount': 70.0, 'sid': 3}, # After query range, should be excluded. {'declared_date': Timestamp('2015-06-01', tz='UTC').to_datetime64(), - 'ex_date': Timestamp('2015-06-26', tz='UTC').to_datetime64(), + 'ex_date': Timestamp('2015-06-25', tz='UTC').to_datetime64(), 'record_date': Timestamp('2015-06-28', tz='UTC').to_datetime64(), 'pay_date': Timestamp('2015-06-30', tz='UTC').to_datetime64(), 'amount': 60.0, 'sid': 6}, # Another action in query range, should have last_row of 3 {'declared_date': Timestamp('2015-06-01', tz='UTC').to_datetime64(), - 'ex_date': Timestamp('2015-06-16', tz='UTC').to_datetime64(), + 'ex_date': Timestamp('2015-06-15', tz='UTC').to_datetime64(), 'record_date': Timestamp('2015-06-18', tz='UTC').to_datetime64(), 'pay_date': Timestamp('2015-06-20', tz='UTC').to_datetime64(), 'amount': 50.0, 'sid': 3}, # Last day of range. Should have last_row of 7 {'declared_date': Timestamp('2015-06-01', tz='UTC').to_datetime64(), - 'ex_date': Timestamp('2015-06-22', tz='UTC').to_datetime64(), - 'record_date': Timestamp('2015-06-23', tz='UTC').to_datetime64(), + 'ex_date': Timestamp('2015-06-19', tz='UTC').to_datetime64(), + 'record_date': Timestamp('2015-06-22', tz='UTC').to_datetime64(), 'pay_date': Timestamp('2015-06-30', tz='UTC').to_datetime64(), 'amount': 40.0, 'sid': 3}, diff --git a/zipline/data/us_equity_pricing.py b/zipline/data/us_equity_pricing.py index 57718438..0d308c75 100644 --- a/zipline/data/us_equity_pricing.py +++ b/zipline/data/us_equity_pricing.py @@ -654,15 +654,15 @@ class SQLiteAdjustmentWriter(object): sid = sids[i] ex_date = ex_dates[i] day_loc = calendar.get_loc(ex_date) - div_adj_date = calendar[day_loc - 1] + prev_close_date = calendar[day_loc - 1] try: prev_close = daily_bar_reader.spot_price( - sid, div_adj_date, 'close') + sid, prev_close_date, 'close') if prev_close != 0.0: ratio = 1.0 - amount / prev_close ratios[i] = ratio # only assign effective_date when data is found - effective_dates[i] = div_adj_date.value + effective_dates[i] = ex_date except NoDataOnDate: logger.warn("Couldn't compute ratio for dividend %s" % { 'sid': sid,