From 0d841503a781cbcd83fb0b88e4ba09f6d21d670d Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Sun, 6 Jan 2013 17:31:03 -0500 Subject: [PATCH] Uses dictionary update instead of iterating through keys. update_universe is a bottleneck on large data sets. A large portion of that bottleneck is the call to getitem while looping over the keys, so using update while passing along the internal __dict__ Seeing about a 40% improvement. --- zipline/gens/tradesimulation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zipline/gens/tradesimulation.py b/zipline/gens/tradesimulation.py index 6477d93c..7616ab48 100644 --- a/zipline/gens/tradesimulation.py +++ b/zipline/gens/tradesimulation.py @@ -241,8 +241,7 @@ class AlgorithmSimulator(object): self.algo.set_portfolio(event.portfolio) # Update our knowledge of this event's sid - for field in event.keys(): - self.universe[event.sid][field] = event[field] + self.universe[event.sid].update(event.__dict__) def simulate_snapshot(self, date): """