mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-12 12:16:46 +08:00
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:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user