From d5c4526e93f8a55fb347b75f57898a2325ffb6b7 Mon Sep 17 00:00:00 2001 From: fawce Date: Wed, 14 Mar 2012 00:23:51 -0400 Subject: [PATCH] sorted out conversion to dataframe, fixed logic bug with callbacks. still need to allow for dot notation to frame. --- zipline/finance/trading.py | 15 ++++++++++----- zipline/protocol.py | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/zipline/finance/trading.py b/zipline/finance/trading.py index 9f0abab5..4319be6e 100644 --- a/zipline/finance/trading.py +++ b/zipline/finance/trading.py @@ -48,6 +48,7 @@ class TradeSimulationClient(qmsg.Component): if msg == str(zp.CONTROL_PROTOCOL.DONE): qutil.LOGGER.info("Client is DONE!") + self.run_callbacks() self.signal_done() return @@ -61,9 +62,9 @@ class TradeSimulationClient(qmsg.Component): #mark the start time for client's processing of this event. event_start = datetime.datetime.utcnow() self.queue_event(event) - for cb in self.event_callbacks: - if(event.dt >= self.current_dt): - cb(self.get_frame()) + + if event.dt >= self.current_dt: + self.run_callbacks() #update time based on receipt of the order self.last_iteration_duration = datetime.datetime.utcnow() - event_start @@ -72,6 +73,11 @@ class TradeSimulationClient(qmsg.Component): #signal done to order source. self.order_socket.send(str(zp.ORDER_PROTOCOL.BREAK)) + + def run_callbacks(self): + frame = self.get_frame() + for cb in self.event_callbacks: + cb(frame) def connect_order(self): return self.connect_push_socket(self.addresses['order_address']) @@ -94,8 +100,7 @@ class TradeSimulationClient(qmsg.Component): self.event_queue[event.dt] = event.as_series() def get_frame(self): - sorted_dates = sorted(self.event_queue.keys()) - frame = pandas.DataFrame(self.event_queue, index=sorted_dates) + frame = pandas.DataFrame(self.event_queue) self.event_queue = None return frame diff --git a/zipline/protocol.py b/zipline/protocol.py index fba7018a..4d13a0b0 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -208,9 +208,9 @@ class namedict(object): return self.__dict__.has_key(name) def as_series(self): - s = pandas.Series(self.__dict__.values(), self.__dict__.keys()) + s = pandas.Series(self.__dict__, self.__dict__.keys()) return s - + # ================ # Control Protocol # ================