From 5dd35a47098d9b311e761cdbc190335a715461b4 Mon Sep 17 00:00:00 2001 From: fawce Date: Thu, 19 Jul 2012 23:31:14 -0400 Subject: [PATCH] added default positions for portfolio object. --- zipline/components/tradesimulation.py | 10 ++++++++-- zipline/finance/performance.py | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zipline/components/tradesimulation.py b/zipline/components/tradesimulation.py index 6c761114..a110087c 100644 --- a/zipline/components/tradesimulation.py +++ b/zipline/components/tradesimulation.py @@ -64,6 +64,11 @@ class TradeSimulationClient(Component): # self.algorithm.initialize() self.algorithm.initialize() + # we need to provide the performance tracker with the + # sids referenced in the algorithm, so portfolio can + # initialize with all possible sids. + + self.perf.set_sids(self.algorithm.get_sid_filter()) def open(self): self.result_feed = self.connect_result() @@ -175,11 +180,12 @@ class TradeSimulationClient(Component): - Set the current portfolio for the algorithm as per protocol. - Construct data based on backlog of events, send to algorithm. """ - current_portfolio = self.perf.get_portfolio() - self.algorithm.set_portfolio(current_portfolio) + # current_portfolio = self.perf.get_portfolio() + # self.algorithm.set_portfolio(current_portfolio) data = self.get_data() if len(data) > 0: + data.portfolio = self.perf.get_portfolio() # data injection pipeline for log rerouting # any fields injected here should be added to diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index 7844b706..fdca878d 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -198,6 +198,10 @@ class PerformanceTracker(object): keep_transactions = True ) + def set_sids(self, sid_list): + for sid in sid_list: + self.cumulative_performance.positions[sid] = Position(sid) + def get_portfolio(self): return self.cumulative_performance.as_portfolio()