From 14b57dad07e8b4eff4515c5fa518db809e6df22d Mon Sep 17 00:00:00 2001 From: fawce Date: Wed, 4 Apr 2012 18:44:19 -0400 Subject: [PATCH] patching the filter test because we are now trying to calculate end of test risk --- zipline/finance/risk.py | 13 +++++++++++-- zipline/finance/trading.py | 1 - zipline/sources.py | 8 ++++++-- zipline/test/test_finance.py | 1 - 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index 413383b0..009ec884 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -320,8 +320,12 @@ class RiskReport(): self.algorithm_returns = algorithm_returns self.trading_environment = trading_environment - start_date = self.algorithm_returns[0].date - end_date = self.algorithm_returns[-1].date + if len(self.algorithm_returns) == 0: + start_date = self.trading_environment.period_start + end_date = self.trading_environment.period_end + else: + start_date = self.algorithm_returns[0].date + end_date = self.algorithm_returns[-1].date self.month_periods = self.periodsInRange(1, start_date, end_date) self.three_month_periods = self.periodsInRange(3, start_date, end_date) @@ -355,6 +359,11 @@ class RiskReport(): ends = [] cur_start = start.replace(day=1) + # in edge cases (all sids filtered out, start/end are adjacent) + # a test will not generate any returns data + if len(self.algorithm_returns) == 0: + return ends + #ensure that we have an end at the end of a calendar month, in case #the return series ends mid-month... the_end = advance_by_months(end.replace(day=1),1) - one_day diff --git a/zipline/finance/trading.py b/zipline/finance/trading.py index edae9782..21848086 100644 --- a/zipline/finance/trading.py +++ b/zipline/finance/trading.py @@ -243,7 +243,6 @@ class OrderDataSource(qmsg.DataSource): if(count == 0): self.send(zp.namedict({})) - class TransactionSimulator(qmsg.BaseTransform): diff --git a/zipline/sources.py b/zipline/sources.py index 42ec2367..b1385754 100644 --- a/zipline/sources.py +++ b/zipline/sources.py @@ -23,10 +23,14 @@ class TradeDataSource(zm.DataSource): if event.sid in self.filter['SID']: message = zp.DATASOURCE_FRAME(event) else: - message = zp.DATASOURCE_FRAME(None) + blank = zp.namedict({ + "type" : zp.DATASOURCE_TYPE.TRADE, + "source_id" : self.get_id + }) + message = zp.DATASOURCE_FRAME(blank) self.data_socket.send(message) - + class RandomEquityTrades(TradeDataSource): """ diff --git a/zipline/test/test_finance.py b/zipline/test/test_finance.py index b4538bfd..a4d31ecc 100644 --- a/zipline/test/test_finance.py +++ b/zipline/test/test_finance.py @@ -155,7 +155,6 @@ class FinanceTestCase(TestCase): zipline = SimulatedTrading.create_test_zipline(**self.zipline_test_config) zipline.simulate(blocking=True) - #check that the algorithm received no events self.assertEqual( 0,