BUG: Use dt as a max value in trading get_index.

Instead of sliding to the next trading day because of the behavior
of `searchsorted`, if dt argument is not a trading day use it as a
max value for corresponding date of the index.

Fixes a bug where if the end of the quarter is calculated with
disregard to trading days, get_index would return the first day
of the next quarter, instead of the last trading day of the intended
quarter.
This commit is contained in:
Eddie Hebert
2013-08-23 12:33:09 -04:00
parent 7d5194ec2c
commit 9376556e68
+8 -1
View File
@@ -230,8 +230,15 @@ Last successful date: %s" % self.last_trading_day)
return j - i
def get_index(self, dt):
"""
Return the index of the given @dt, or the index of the preceding
trading day if the given dt is not in the trading calendar.
"""
ndt = self.normalize_date(dt)
return self.trading_days.searchsorted(ndt)
if ndt in self.trading_days:
return self.trading_days.searchsorted(ndt)
else:
return self.trading_days.searchsorted(ndt) - 1
class SimulationParameters(object):