From 2b5b670493c029b284947162ab8ab293d993cc80 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Mon, 10 Jun 2013 17:10:48 -0400 Subject: [PATCH] MAINT: Change signature of create_transaction. - Change the expected type for order information from the string of the order id to an `Order` object, so that it matches the same abstraction level as passing in an event. - Change the order (not to be confused with the parameter named `order`) of the parameters so that they go from left to right in order of static -> dynamic, i.e. the parameters most likely to change within each invoration are the amount and price, with amount more likely to change than price. --- tests/test_perf_tracking.py | 3 ++- zipline/finance/slippage.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test_perf_tracking.py b/tests/test_perf_tracking.py index 659e9677..bc043f67 100644 --- a/tests/test_perf_tracking.py +++ b/tests/test_perf_tracking.py @@ -42,7 +42,8 @@ tradingday = datetime.timedelta(hours=6, minutes=30) def create_txn(event, price, amount): - return create_transaction(event, amount, price, "fakeuid") + mock_order = Order(None, None, event.sid, id=None) + return create_transaction(event, mock_order, price, amount) def benchmark_events_in_range(sim_params): diff --git a/zipline/finance/slippage.py b/zipline/finance/slippage.py index f8ed0f13..82fdb46a 100644 --- a/zipline/finance/slippage.py +++ b/zipline/finance/slippage.py @@ -99,14 +99,14 @@ class Transaction(object): return py -def create_transaction(event, amount, price, order_id): +def create_transaction(event, order, price, amount): txn = { 'sid': event.sid, 'amount': int(amount), 'dt': event.dt, 'price': price, - 'order_id': order_id + 'order_id': order.id } transaction = Transaction(**txn) @@ -189,11 +189,11 @@ class VolumeShareSlippage(SlippageModel): if order.direction * cur_amount > 0: txn = create_transaction( event, - cur_amount, + order, # In the future, we may want to change the next line # for limit pricing event.price + simulated_impact, - order.id + cur_amount ) txns.append(txn) @@ -228,9 +228,9 @@ class FixedSlippage(SlippageModel): txn = create_transaction( event, - order.amount, + order, event.price + (self.spread / 2.0 * order.direction), - order.id + order.amount, ) # mark the date of the order to match the transaction