From 57c56351e990357deb3a1b59d9c89b6a821aa3f0 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Thu, 20 Feb 2014 13:50:03 -0500 Subject: [PATCH] MAINT: Re-enable algorithms which omit initialize method. Though defining the `initialize` method may end up being explicitly required, in the meantime prevent existing algorithms from crashing by providing a noop function when `initialize` is not defined. --- zipline/algorithm.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zipline/algorithm.py b/zipline/algorithm.py index fd9a0c41..eeaedaab 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -160,6 +160,8 @@ class TradingAlgorithm(object): # functions. self.algoscript = kwargs.pop('script', None) + self._initialize = None + if self.algoscript is not None: self.ns = {} exec_(self.algoscript, self.ns) @@ -179,6 +181,9 @@ class TradingAlgorithm(object): self._initialize = kwargs.pop('initialize') self._handle_data = kwargs.pop('handle_data') + if self._initialize is None: + self._initialize = lambda x: None + # an algorithm subclass needs to set initialized to True when # it is fully initialized. self.initialized = False