Skip to content

Commit

Permalink
BUG: Fix tradesimulation index into perf results when emitting minutely.
Browse files Browse the repository at this point in the history
The indexing into performance results during the simulation loop fails
when emitting minutely since 'daily_perf' only exists on daily performance
results, not the minutely results.

Fix by making the key used to index into performance results depend
on the emission rate.
  • Loading branch information
Eddie Hebert committed Apr 4, 2013
1 parent 564c81f commit eb42d4b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions zipline/gens/tradesimulation.py
Expand Up @@ -137,6 +137,11 @@ def simulate(self, stream_in):

class AlgorithmSimulator(object):

EMISSION_TO_PERF_KEY_MAP = {
'minute': 'intraday_perf',
'daily': 'daily_perf'
}

def __init__(self,
order_book,
perf_tracker,
Expand All @@ -152,6 +157,9 @@ def __init__(self,
self.order_book = order_book
self.perf_tracker = perf_tracker

self.perf_key = self.EMISSION_TO_PERF_KEY_MAP[
perf_tracker.emission_rate]

self.algo = algo
self.algo_start = algo_start.replace(hour=0, minute=0,
second=0,
Expand Down Expand Up @@ -263,7 +271,7 @@ def transform(self, stream_in):
for perf_message in event.perf_messages:
# append current values of recorded vars
# to emitted message
perf_message['daily_perf']['recorded_vars'] =\
perf_message[self.perf_key]['recorded_vars'] =\
self.algo.recorded_vars
yield perf_message
del event['perf_messages']
Expand All @@ -278,7 +286,7 @@ def transform(self, stream_in):
self.perf_tracker.handle_simulation_end()

for message in perf_messages:
message['daily_perf']['recorded_vars'] =\
message[self.perf_key]['recorded_vars'] =\
self.algo.recorded_vars
yield message

Expand Down

0 comments on commit eb42d4b

Please sign in to comment.