mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-08 02:23:14 +08:00
fix bug where trading environment enters infinite loop on invalid dates
This commit is contained in:
@@ -183,13 +183,21 @@ class TradingEnvironment(object):
|
||||
self.period_trading_days = None
|
||||
self.max_drawdown = max_drawdown
|
||||
|
||||
assert self.period_start <= self.period_end, \
|
||||
"Period start falls after period end."
|
||||
|
||||
for bm in benchmark_returns:
|
||||
self.trading_days.append(bm.date)
|
||||
self.trading_day_map[bm.date] = bm
|
||||
|
||||
assert self.period_start <= self.trading_days[-1], \
|
||||
"Period start falls after the last known trading day."
|
||||
assert self.period_end >= self.trading_days[0], \
|
||||
"Period end falls before the first known trading day."
|
||||
|
||||
self.first_open = self.calculate_first_open()
|
||||
self.last_close = self.calculate_last_close()
|
||||
|
||||
|
||||
self.prior_day_open = self.calculate_prior_day_open()
|
||||
|
||||
def calculate_first_open(self):
|
||||
|
||||
@@ -161,9 +161,6 @@ class EventWindow:
|
||||
"Market-aware mode only works with full-day windows."
|
||||
self.all_holidays = deque(non_trading_days)
|
||||
self.cur_holidays = deque()
|
||||
# Keeping a copy of days as a timedelta makes it easier
|
||||
# to track holidays.
|
||||
self.delta = timedelta(days=self.days)
|
||||
|
||||
# Non-market-aware mode requires a timedelta.
|
||||
else:
|
||||
|
||||
+2
-3
@@ -181,7 +181,7 @@ class SimulatedTrading(object):
|
||||
else:
|
||||
log.warning("Sending SIGINT")
|
||||
os.kill(ppid, SIGINT)
|
||||
|
||||
|
||||
def handle_exception(self, exc):
|
||||
if isinstance(exc, CancelSignal):
|
||||
# signal from monitor of an orderly shutdown,
|
||||
@@ -208,9 +208,8 @@ class SimulatedTrading(object):
|
||||
exc_type.__name__,
|
||||
exc_value.message
|
||||
)
|
||||
|
||||
|
||||
self.results_socket.send(msg)
|
||||
|
||||
except:
|
||||
log.exception("Exception while reporting simulation exception.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user