mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-06 03:07:09 +08:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user