BUG: Zero out the microsecond attribute of datetimes

wherever we zero out the second attribute.  Otherwise, we can be
off by some microseconds from midnight, etc.
This commit is contained in:
Richard Frank
2013-04-14 16:41:38 -04:00
parent cc322af498
commit 2dbafd5162
7 changed files with 16 additions and 10 deletions
+2 -1
View File
@@ -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()
+4 -2
View File
@@ -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)
+1 -1
View File
@@ -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:
+1
View File
@@ -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
+1 -1
View File
@@ -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):
+3 -2
View File
@@ -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)
+4 -3
View File
@@ -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
})