Merge pull request #819 from quantopian/pass_analyze

Pass analyze
This commit is contained in:
Richard Frank
2015-11-05 11:30:14 -05:00
2 changed files with 32 additions and 0 deletions
+31
View File
@@ -1891,3 +1891,34 @@ class TestFutureFlip(TestCase):
actual_position, expected_positions[i],
"position for day={0} not equal, actual={1}, expected={2}".
format(i, actual_position, expected_positions[i]))
class TestTradingAlgorithm(TestCase):
def setUp(self):
self.env = TradingEnvironment()
self.days = self.env.trading_days[:4]
self.panel = pd.Panel({1: pd.DataFrame({
'price': [1, 1, 2, 4], 'volume': [1e9, 1e9, 1e9, 0],
'type': [DATASOURCE_TYPE.TRADE,
DATASOURCE_TYPE.TRADE,
DATASOURCE_TYPE.TRADE,
DATASOURCE_TYPE.CLOSE_POSITION]},
index=self.days)
})
def test_analyze_called(self):
self.perf_ref = None
def initialize(context):
pass
def handle_data(context, data):
pass
def analyze(context, perf):
self.perf_ref = perf
algo = TradingAlgorithm(initialize=initialize, handle_data=handle_data,
analyze=analyze)
results = algo.run(self.panel)
self.assertIs(results, self.perf_ref)
+1
View File
@@ -297,6 +297,7 @@ class TradingAlgorithm(object):
self._handle_data = kwargs.pop('handle_data')
self._before_trading_start = kwargs.pop('before_trading_start',
None)
self._analyze = kwargs.pop('analyze', None)
self.event_manager.add_event(
zipline.utils.events.Event(