From 1906052a7a36fdebb0228cd1a8fc399aa57c637c Mon Sep 17 00:00:00 2001 From: Andrew Daniels Date: Tue, 7 Jul 2015 17:15:12 -0400 Subject: [PATCH] BUG: Sets the datetime of TradingAlgorithm initially to the simulation period start The datetime attribute of TradingAlgorithm was initially None, so calling get_datetime in initialize was causing an unhandled exception. This commit addresses that issue by calling on_dt_changed when initializing the TradingAlgorithm, to force all datetimes to be in line with the period_start. --- zipline/algorithm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zipline/algorithm.py b/zipline/algorithm.py index 3b5cb2e4..f6c7ff41 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -156,8 +156,6 @@ class TradingAlgorithm(object): Any asset identifiers that are not provided in the asset_metadata, but will be traded by this TradingAlgorithm """ - self.datetime = None - self.sources = [] # List of trading controls to be used to validate orders. @@ -208,6 +206,9 @@ class TradingAlgorithm(object): if not self.blotter: self.blotter = Blotter() + # Set the dt initally to the period start by forcing it to change + self.on_dt_changed(self.sim_params.period_start) + self.portfolio_needs_update = True self.account_needs_update = True self.performance_needs_update = True