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