fix bug where trading environment enters infinite loop on invalid dates

This commit is contained in:
scottsanderson
2012-08-23 10:47:35 -04:00
parent 0f86fe4a93
commit 55ffa2b391
3 changed files with 11 additions and 7 deletions
+9 -1
View File
@@ -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):
-3
View File
@@ -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
View File
@@ -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.")