From 7044040722a6ac623fb34e9a8ba80c1056037d0e Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 18 Jun 2012 19:02:14 -0400 Subject: [PATCH 1/8] removed logging of zero volume orders. --- zipline/finance/trading.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/zipline/finance/trading.py b/zipline/finance/trading.py index 2d378574..b2aacdc1 100644 --- a/zipline/finance/trading.py +++ b/zipline/finance/trading.py @@ -151,20 +151,6 @@ class TransactionSimulator(object): dt.replace(tzinfo = pytz.utc), direction ) - elif len(orders) > 0: - warning = """ -Calculated a zero volume transaction on trade: -{event} -for orders: -{orders} - """ - warning = warning.format( - event=str(event), - orders=str(orders) - ) - LOGGER.warn(warning) - return None - def create_transaction(self, sid, amount, price, dt, direction): self.txn_count += 1 From ba05335b2c0b7ed72e641c873553b4e6f75e5f1d Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 18 Jun 2012 19:11:13 -0400 Subject: [PATCH 2/8] logging every update was spamming the console during unit tests... --- zipline/finance/performance.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index 34dfae89..d0dbb643 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -287,8 +287,6 @@ class PerformanceTracker(object): if self.results_socket: msg = zp.PERF_FRAME(self.to_dict()) self.results_socket.send(msg) - else: - log.debug(self.to_dict()) # if self.trading_environment.max_drawdown: From 5d97469a24e430b8d1a3207952db5c6098d6ded2 Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 19 Jun 2012 15:52:47 -0400 Subject: [PATCH 3/8] added a filter for nan values in risk data relay --- zipline/finance/risk.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index a63cf872..338d14ae 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -126,7 +126,7 @@ class RiskMetrics(): Returns a dict object of the form: """ period_label = self.end_date.strftime("%Y-%m") - return { + rval = { 'trading_days' : self.trading_days, 'benchmark_volatility' : self.benchmark_volatility, 'algo_volatility' : self.algorithm_volatility, @@ -141,6 +141,8 @@ class RiskMetrics(): 'period_label' : period_label } + return {k:None if np.isnan(v) else v for k,v in rval.iteritems()} + def __repr__(self): statements = [] metrics = [ From e1db77fb647b55cb0f46fa3339dadc21d7390103 Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 19 Jun 2012 17:06:40 -0400 Subject: [PATCH 4/8] fixed comprehension --- zipline/finance/risk.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index 338d14ae..a86a96f4 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -141,7 +141,13 @@ class RiskMetrics(): 'period_label' : period_label } - return {k:None if np.isnan(v) else v for k,v in rval.iteritems()} + def check_entry(key, value): + if key in {'algo_volatility', 'benchmark_volatility', 'beta'}: + return np.isnan(value) + else: + return False + + return {k:None if check_entry(k,v) else v for k,v in rval.iteritems()} def __repr__(self): statements = [] From 89e52c675844ca4fa07afc45d01ccfb68be2fd2e Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 19 Jun 2012 20:03:37 -0400 Subject: [PATCH 5/8] better filter for nan check --- zipline/finance/risk.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index a86a96f4..7021c581 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -141,8 +141,10 @@ class RiskMetrics(): 'period_label' : period_label } + # check if a field in rval is nan, and replace it with + # None. def check_entry(key, value): - if key in {'algo_volatility', 'benchmark_volatility', 'beta'}: + if key != 'period_label': return np.isnan(value) else: return False From a82d3852bd09a040d383e55388814f44aac07732 Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 19 Jun 2012 20:43:46 -0400 Subject: [PATCH 6/8] added the is_success property to the SimulatedTrading class --- zipline/lines.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zipline/lines.py b/zipline/lines.py index a229c9f0..a2a4aa8b 100644 --- a/zipline/lines.py +++ b/zipline/lines.py @@ -325,6 +325,10 @@ class SimulatedTrading(object): if blocking: self.sim_context.join() + @property + def is_success(self): + return self.sim.read() and not self.sim.exception + #-------------------------------- # Component property accessors #-------------------------------- From 1e2bcb0ed9a224d83d50abc86818454d744ad800 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 20 Jun 2012 09:30:50 -0400 Subject: [PATCH 7/8] Clean shutdown check is_success check. Conflicts: zipline/lines.py --- zipline/lines.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zipline/lines.py b/zipline/lines.py index a2a4aa8b..d696d97e 100644 --- a/zipline/lines.py +++ b/zipline/lines.py @@ -327,7 +327,11 @@ class SimulatedTrading(object): @property def is_success(self): - return self.sim.read() and not self.sim.exception + # TODO: other assertions? + if self.sim.did_clean_shutdown(): + return True + else: + return False #-------------------------------- # Component property accessors From 2a8e19b22fb6bea46c9927fee4f9667929d4ad15 Mon Sep 17 00:00:00 2001 From: fawce Date: Thu, 21 Jun 2012 22:08:25 -0400 Subject: [PATCH 8/8] name change for positions_value --- zipline/finance/performance.py | 2 +- zipline/lines.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index d0dbb643..9d761eb1 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -553,7 +553,7 @@ class PerformancePeriod(object): # cumulative_capital_used, max_leverage, max_capital_used portfolio['cash'] = portfolio['ending_cash'] portfolio['start_date'] = portfolio['period_open'] - portfolio['position_value'] = portfolio['ending_value'] + portfolio['positions_value'] = portfolio['ending_value'] del(portfolio['ending_cash']) del(portfolio['period_open']) diff --git a/zipline/lines.py b/zipline/lines.py index a2a4aa8b..d346fdb3 100644 --- a/zipline/lines.py +++ b/zipline/lines.py @@ -327,7 +327,7 @@ class SimulatedTrading(object): @property def is_success(self): - return self.sim.read() and not self.sim.exception + return self.sim.ready() and not self.sim.exception #-------------------------------- # Component property accessors