From e4a0c7af7fb45b1051dcc53db5e2c340a4830700 Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 1 May 2012 15:25:04 -0400 Subject: [PATCH] added initialize method to the algorithm protocol. --- zipline/finance/trading.py | 4 +++- zipline/test/algorithms.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/zipline/finance/trading.py b/zipline/finance/trading.py index 03e45fa8..6e3d92a9 100644 --- a/zipline/finance/trading.py +++ b/zipline/finance/trading.py @@ -59,8 +59,10 @@ class TradeSimulationClient(qmsg.Component): :py:mod:`zipline.test.algorithm` """ self.algorithm = algorithm - #register the trading_client's order method with the algorithm + # register the trading_client's order method with the algorithm self.algorithm.set_order(self.order) + # ask the algorithm to initialize + self.algorithm.initialize() def open(self): self.result_feed = self.connect_result() diff --git a/zipline/test/algorithms.py b/zipline/test/algorithms.py index 17873d27..b3743709 100644 --- a/zipline/test/algorithms.py +++ b/zipline/test/algorithms.py @@ -9,6 +9,9 @@ are provided below. The algorithm must expose methods: + - initialize: method that takes no args, no returns. Simply called to + enable the algorithm to set any internal state needed. + - get_sid_filter: method that takes no args, and returns a list of valid sids. List must have a length between 1 and 10. If None is returned the filter will block all events. @@ -18,7 +21,7 @@ The algorithm must expose methods: +-----------------+--------------+----------------+--------------------+ | | SID(133) | SID(134) | SID(135) | - +=================+==============+=====================================+ + +=================+==============+================+====================+ | price | $10.10 | $22.50 | $13.37 | +-----------------+--------------+----------------+--------------------+ | volume | 10,000 | 5,000 | 50,000 | @@ -61,6 +64,9 @@ class TestAlgorithm(): self.order = None self.frame_count = 0 self.portfolio = None + + def initialize(self): + pass def set_order(self, order_callable): self.order = order_callable @@ -94,7 +100,10 @@ class HeavyBuyAlgorithm(): self.order = None self.frame_count = 0 self.portfolio = None - + + def initialize(self): + pass + def set_order(self, order_callable): self.order = order_callable @@ -114,6 +123,9 @@ class NoopAlgorithm(object): """ Dolce fa niente. """ + + def initialize(self): + pass def set_order(self, order_callable): pass