diff --git a/zipline/data/loader.py b/zipline/data/loader.py index 5346499c..12a5521a 100644 --- a/zipline/data/loader.py +++ b/zipline/data/loader.py @@ -217,7 +217,8 @@ Fetching data from data.treasury.gov tr_curves = {} for packed_date, curve in tr_list: tr_dt = tuple_to_date(packed_date) - #tr_dt = tr_dt.replace(hour=0, minute=0, second=0, tzinfo=pytz.utc) + # tr_dt = tr_dt.replace(hour=0, minute=0, second=0, microsecond=0, + # tzinfo=pytz.utc) tr_curves[tr_dt] = curve fp_tr.close() diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index 6d116bea..0679d3c1 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -325,7 +325,8 @@ class PerformanceTracker(object): def handle_market_close(self): # add the return results from today to the list of DailyReturn objects. - todays_date = self.market_close.replace(hour=0, minute=0, second=0) + todays_date = self.market_close.replace(hour=0, minute=0, second=0, + microsecond=0) self.cumulative_performance.update_dividends(todays_date) self.todays_performance.update_dividends(todays_date) @@ -369,7 +370,8 @@ class PerformanceTracker(object): # hour between the close of markets and the next open. To # make sure midnight_between matches identically with # dividend data dates, it is in UTC. - midnight_between = self.market_open.replace(hour=0, minute=0, second=0) + midnight_between = self.market_open.replace(hour=0, minute=0, second=0, + microsecond=0) self.cumulative_performance.update_dividends(midnight_between) self.todays_performance.update_dividends(midnight_between) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index 7059ffd6..e5ae0199 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -228,7 +228,7 @@ def select_treasury_duration(start_date, end_date): def choose_treasury(treasury_curves, start_date, end_date): treasury_duration = select_treasury_duration(start_date, end_date) - end_day = end_date.replace(hour=0, minute=0, second=0) + end_day = end_date.replace(hour=0, minute=0, second=0, microsecond=0) search_day = None if end_day in treasury_curves: diff --git a/zipline/finance/trading.py b/zipline/finance/trading.py index 2743c2d7..25522c00 100644 --- a/zipline/finance/trading.py +++ b/zipline/finance/trading.py @@ -189,6 +189,7 @@ Last successful date: %s" % self.market_open) hour=9, minute=30, second=0, + microsecond=0, tzinfo=None ) # create a new Delorean with the next_open naive date and diff --git a/zipline/protocol.py b/zipline/protocol.py index 38568b39..fc077424 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -125,7 +125,7 @@ class DailyReturn(object): def __init__(self, date, returns): assert isinstance(date, datetime.datetime) - self.date = date.replace(hour=0, minute=0, second=0) + self.date = date.replace(hour=0, minute=0, second=0, microsecond=0) self.returns = returns def to_dict(self): diff --git a/zipline/sources/test_source.py b/zipline/sources/test_source.py index bd619b6c..84b2ef7d 100644 --- a/zipline/sources/test_source.py +++ b/zipline/sources/test_source.py @@ -72,11 +72,12 @@ def date_gen(start=datetime(2006, 6, 6, 12, tzinfo=pytz.utc), yield cur cur = cur + delta - cur_midnight = cur.replace(hour=0, minute=0, second=0) + cur_midnight = cur.replace(hour=0, minute=0, second=0, microsecond=0) # skip over any non-trading days while cur_midnight not in trading_days: cur = cur + one_day - cur_midnight = cur.replace(hour=0, minute=0, second=0) + cur_midnight = cur.replace(hour=0, minute=0, second=0, + microsecond=0) cur = cur.replace(day=cur_midnight.day) diff --git a/zipline/utils/factory.py b/zipline/utils/factory.py index 0873fe80..1a83a793 100644 --- a/zipline/utils/factory.py +++ b/zipline/utils/factory.py @@ -159,9 +159,10 @@ def create_dividend(sid, payment, declared_date, ex_date, pay_date): 'sid': sid, 'gross_amount': payment, 'net_amount': payment, - 'dt': declared_date.replace(hour=0, minute=0, second=0), - 'ex_date': ex_date.replace(hour=0, minute=0, second=0), - 'pay_date': pay_date.replace(hour=0, minute=0, second=0), + 'dt': declared_date.replace(hour=0, minute=0, second=0, microsecond=0), + 'ex_date': ex_date.replace(hour=0, minute=0, second=0, microsecond=0), + 'pay_date': pay_date.replace(hour=0, minute=0, second=0, + microsecond=0), 'type': DATASOURCE_TYPE.DIVIDEND })