adding type as variable to create_test_panel

This commit is contained in:
warren-oneill
2015-06-04 15:50:41 +02:00
parent 44fbdff4ac
commit 77fb100ae6
3 changed files with 11 additions and 3 deletions
+3 -1
View File
@@ -47,14 +47,16 @@ class TestDataFrameSource(TestCase):
"DataFrameSource should only stream selected sid 0, not sid 1."
def test_panel_source(self):
source, panel = factory.create_test_panel_source()
source, panel = factory.create_test_panel_source(source_type=5)
assert isinstance(source.start, pd.lib.Timestamp)
assert isinstance(source.end, pd.lib.Timestamp)
for event in source:
self.assertTrue('sid' in event)
self.assertTrue('arbitrary' in event)
self.assertTrue('type' in event)
self.assertTrue(hasattr(event, 'volume'))
self.assertTrue(hasattr(event, 'price'))
self.assertEquals(event['type'], 5)
self.assertEquals(event['arbitrary'], 1.)
self.assertEquals(event['sid'], 0)
self.assertTrue(isinstance(event['volume'], int))
+2 -1
View File
@@ -339,7 +339,8 @@ class PerformanceTracker(object):
def process_close_position(self, event):
txn = self.position_tracker.create_close_position_transaction(event)
self.process_transaction(txn)
if txn:
self.process_transaction(txn)
def check_upcoming_dividends(self, midnight_of_date_that_just_ended):
"""
+6 -1
View File
@@ -315,7 +315,7 @@ def create_test_df_source(sim_params=None, bars='daily'):
return DataFrameSource(df), df
def create_test_panel_source(sim_params=None):
def create_test_panel_source(sim_params=None, source_type=None):
start = sim_params.first_open \
if sim_params else pd.datetime(1990, 1, 3, 0, 0, 0, 0, pytz.utc)
@@ -329,12 +329,17 @@ def create_test_panel_source(sim_params=None):
price = np.arange(0, len(index))
volume = np.ones(len(index)) * 1000
arbitrary = np.ones(len(index))
df = pd.DataFrame({'price': price,
'volume': volume,
'arbitrary': arbitrary},
index=index)
if source_type:
source_types = np.full(len(index), source_type)
df['type'] = source_types
panel = pd.Panel.from_dict({0: df})
return DataPanelSource(panel), panel