From 8bf4c601694c2645ad26b0649e14b02c7f786007 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 10:42:01 -0400 Subject: [PATCH 1/9] MAINT: Removes unused member from performance tracker class. `last_dict` is not referenced elsewhere. --- zipline/finance/performance.py | 1 - 1 file changed, 1 deletion(-) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index e299d077..83790e39 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -177,7 +177,6 @@ class PerformanceTracker(object): self.returns = [] self.txn_count = 0 self.event_count = 0 - self.last_dict = None self.cumulative_risk_metrics = \ risk.RiskMetricsIterative(self.period_start) From 060b565cdcf67ff40fd6437b78cc9db8b96400e8 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 11:00:38 -0400 Subject: [PATCH 2/9] DEV: Adds stashing to pre-commit hook. So that the code that is linted/tested is only the staged commits. Useful when editing by only staging parts of files via git. --- etc/git-hooks/pre-commit | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/etc/git-hooks/pre-commit b/etc/git-hooks/pre-commit index 83352197..c1d771cb 100755 --- a/etc/git-hooks/pre-commit +++ b/etc/git-hooks/pre-commit @@ -13,7 +13,17 @@ set -e +# stash everything that wasn't just staged +# so that we are only testing the staged code +git stash -q --keep-index + # Run flake8 linting flake8 zipline tests # Run unit tests nosetests -x + +# restore unstaged code +# N.B. this won't run if linting or unit tests fail +# But if either fail, it's probably best to have only the offending +# staged commits 'active', anyway. +git stash pop -q From 95a9b7b3c2858b78d5a27360f45590898e23cd4f Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 11:27:57 -0400 Subject: [PATCH 3/9] MAINT: Updates docstring for performance tracker class. --- zipline/finance/performance.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index 83790e39..acf4a5cf 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -148,14 +148,7 @@ log = logbook.Logger('Performance') class PerformanceTracker(object): """ - Tracks the performance of the zipline as it is running in - the simulator, relays this out to the Deluge broker and then - to the client. Visually: - - +--------------------+ Result Stream +--------+ - | PerformanceTracker | ----------------> | Deluge | - +--------------------+ +--------+ - + Tracks the performance of the algorithm. """ def __init__(self, sim_params): From 3707c7b2257549c87c038cf259e8331fb6191d48 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 12:12:33 -0400 Subject: [PATCH 4/9] MAINT: Changes name of grouping of by dt in generator chain. Changes name to `grouped_by_dt` instead of `grouped_by_date` to clarify that the grouping is by dt, which can be by minute, instead of grouping by calendar date. --- zipline/algorithm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zipline/algorithm.py b/zipline/algorithm.py index 2516df27..03ecbfb4 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -131,13 +131,13 @@ class TradingAlgorithm(object): self.with_alias_dt = alias_dt(self.with_tnfms) # Group together events with the same dt field. This depends on the # events already being sorted. - self.grouped_by_date = groupby(self.with_alias_dt, attrgetter('dt')) + self.grouped_by_dt = groupby(self.with_alias_dt, attrgetter('dt')) self.trading_client = tsc(self, sim_params) transact_method = transact_partial(self.slippage, self.commission) self.set_transact(transact_method) - return self.trading_client.simulate(self.grouped_by_date) + return self.trading_client.simulate(self.grouped_by_dt) def get_generator(self): """ From 75049fdd15d5ee04343c168eedb1c2f4fd054704 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 13:05:38 -0400 Subject: [PATCH 5/9] MAINT: Removes unused started_at member from performance tracker. --- zipline/finance/performance.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index acf4a5cf..b68eb17d 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -133,8 +133,6 @@ omitted). """ import logbook -import datetime -import pytz import math import numpy as np @@ -154,7 +152,6 @@ class PerformanceTracker(object): def __init__(self, sim_params): self.sim_params = sim_params - self.started_at = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) self.period_start = self.sim_params.period_start self.period_end = self.sim_params.period_end @@ -230,7 +227,6 @@ class PerformanceTracker(object): Returns a dict object of the form described in header comments. """ return { - 'started_at': self.started_at, 'period_start': self.period_start, 'period_end': self.period_end, 'progress': self.progress, From 5dc449ba1924e0ce65efd126b94fc174016d738d Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 13:19:39 -0400 Subject: [PATCH 6/9] MAINT: Changes boolean check for snapshot existence in performance. Small tweak to check for existence of elements using built-in boolean of lists, instead of checking for `len`. --- zipline/finance/performance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index b68eb17d..3b2c1cdd 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -215,7 +215,7 @@ class PerformanceTracker(object): new_snapshot.append(event) - if len(new_snapshot) > 0: + if new_snapshot: yield date, new_snapshot def get_portfolio(self): From 08882bc8aa4b53b1534186bdea362b5416ba3712 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 14:30:11 -0400 Subject: [PATCH 7/9] MAINT: Updates copyright on risk module. --- zipline/finance/risk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zipline/finance/risk.py b/zipline/finance/risk.py index b8fb2806..9dcead23 100644 --- a/zipline/finance/risk.py +++ b/zipline/finance/risk.py @@ -1,5 +1,5 @@ # -# Copyright 2012 Quantopian, Inc. +# Copyright 2013 Quantopian, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 279e125ab8e61b8d04cc487e52f17a6e1cadeb6e Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 14:34:12 -0400 Subject: [PATCH 8/9] MAINT: Pull initialization of simulation dt out of event loop. Fakes a 'peek' into the data stream, so that the 'do we have a simulation_dt?' check isn't called on each leoop iteration. --- zipline/gens/tradesimulation.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/zipline/gens/tradesimulation.py b/zipline/gens/tradesimulation.py index 91adef27..59e86013 100644 --- a/zipline/gens/tradesimulation.py +++ b/zipline/gens/tradesimulation.py @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import itertools from logbook import Logger, Processor from collections import defaultdict @@ -234,16 +234,20 @@ class AlgorithmSimulator(object): """ Main generator work loop. """ + # Set the simulation date to be the first event we see. + peek_date, peek_snapshot = next(stream_in) + self.simulation_dt = peek_date + + # Stitch back together the generator by placing the peeked + # event back in front + stream = itertools.chain([(peek_date, peek_snapshot)], + stream_in) + # inject the current algo # snapshot time to any log record generated. with self.processor.threadbound(): - for date, snapshot in stream_in: - # Set the simulation date to be the first event we see. - # This should only occur once, at the start of the test. - if self.simulation_dt is None: - self.simulation_dt = date - + for date, snapshot in stream: # We're still in the warmup period. Use the event to # update our universe, but don't yield any perf messages, # and don't send a snapshot to handle_data. From 832c93134f3d75c5ba695e86252380e02e152dea Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 20 Mar 2013 22:18:30 -0400 Subject: [PATCH 9/9] MAINT: Removes comment referreing to removed started_at member. --- zipline/finance/performance.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index 3b2c1cdd..b11017be 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -33,8 +33,6 @@ Performance Tracking +-----------------+----------------------------------------------------+ | progress | percentage of test completed | +-----------------+----------------------------------------------------+ - | started_at | datetime in utc marking the start of this test | - +-----------------+----------------------------------------------------+ | capital_base | The initial capital assumed for this tracker. | +-----------------+----------------------------------------------------+ | cumulative_perf | A dictionary representing the cumulative |