mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-28 11:35:44 +08:00
adding type as variable to create_test_panel
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user