From a05039c514bed0f9698ce217835da2c7f6b987a2 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Mon, 25 Mar 2013 16:32:41 -0400 Subject: [PATCH] MAINT: Uses Transaction object in tests instead of ndict. So that Transaction object behavior is exercised, uses the Transaction object in performance module tests instead of ndict. Also, adds fields to the __init__ of Transaction, to make the definition of the object more well defined. --- tests/finance/test_slippage.py | 3 ++- tests/test_perf_tracking.py | 4 ++-- zipline/finance/slippage.py | 11 +++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/finance/test_slippage.py b/tests/finance/test_slippage.py index c4feaaec..f6f8d4c0 100644 --- a/tests/finance/test_slippage.py +++ b/tests/finance/test_slippage.py @@ -69,7 +69,8 @@ class SlippageTestCase(TestCase): 'dt': datetime.datetime( 2006, 1, 5, 14, 31, tzinfo=pytz.utc), 'amount': int(50), - 'sid': int(133) + 'sid': int(133), + 'commission': None } self.assertIsNotNone(txn) diff --git a/tests/test_perf_tracking.py b/tests/test_perf_tracking.py index c75646fe..fab97cfe 100644 --- a/tests/test_perf_tracking.py +++ b/tests/test_perf_tracking.py @@ -24,7 +24,7 @@ from operator import attrgetter import zipline.utils.factory as factory import zipline.finance.performance as perf -from zipline.utils.protocol_utils import ndict +from zipline.finance.slippage import Transaction from zipline.gens.composites import date_sorted_sources from zipline.finance.trading import SimulationParameters @@ -1018,7 +1018,7 @@ class TestPerformanceTracker(unittest.TestCase): #create a transaction for all but #first trade in each sid, to simulate None transaction if event.dt != no_txn_dt: - txn = ndict({ + txn = Transaction(**{ 'sid': event.sid, 'amount': -25, 'dt': event.dt, diff --git a/zipline/finance/slippage.py b/zipline/finance/slippage.py index 20653aaa..ef85f645 100644 --- a/zipline/finance/slippage.py +++ b/zipline/finance/slippage.py @@ -50,9 +50,12 @@ def transact_partial(slippage, commission): class Transaction(object): - def __init__(self, initial_values=None): - if initial_values: - self.__dict__ = initial_values + def __init__(self, sid, amount, dt, price, commission=None): + self.sid = sid + self.amount = amount + self.dt = dt + self.price = price + self.commission = commission def __getitem__(self, name): return self.__dict__[name] @@ -67,7 +70,7 @@ def create_transaction(sid, amount, price, dt): 'price': price, } - transaction = Transaction(txn) + transaction = Transaction(**txn) return transaction