mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-04 06:59:07 +08:00
ENH: made exchange a required parameter to Asset and its subclasses
This required updating a lot of tests.
This commit is contained in:
@@ -165,7 +165,7 @@ class SliceTestCase(WithSeededRandomPipelineEngine, ZiplineTestCase):
|
||||
Test that indexing into a term with a non-existent asset raises the
|
||||
proper exception.
|
||||
"""
|
||||
my_asset = Asset(0)
|
||||
my_asset = Asset(0, exchange="TEST")
|
||||
returns = Returns(window_length=2, inputs=[self.col])
|
||||
returns_slice = returns[my_asset]
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ class StatisticalBuiltInsTestCase(WithTradingEnvironment, ZiplineTestCase):
|
||||
`RollingLinearRegressionOfReturns` raise the proper exception when
|
||||
given a nonexistent target asset.
|
||||
"""
|
||||
my_asset = Equity(0)
|
||||
my_asset = Equity(0, exchange="TEST")
|
||||
start_date = self.pipeline_start_date
|
||||
end_date = self.pipeline_end_date
|
||||
run_pipeline = self.run_pipeline
|
||||
|
||||
@@ -290,7 +290,7 @@ class ObjectIdentityTestCase(TestCase):
|
||||
self.assertIs(beta, multiple_outputs.beta)
|
||||
|
||||
def test_instance_caching_of_slices(self):
|
||||
my_asset = Asset(1)
|
||||
my_asset = Asset(1, exchange="TEST")
|
||||
|
||||
f = GenericCustomFactor()
|
||||
f_slice = f[my_asset]
|
||||
|
||||
+39
-16
@@ -210,10 +210,12 @@ class TestMiscellaneousAPI(WithLogger,
|
||||
pd.DataFrame.from_dict(
|
||||
{3: {'symbol': 'PLAY',
|
||||
'start_date': '2002-01-01',
|
||||
'end_date': '2004-01-01'},
|
||||
'end_date': '2004-01-01',
|
||||
'exchange': 'TEST'},
|
||||
4: {'symbol': 'PLAY',
|
||||
'start_date': '2005-01-01',
|
||||
'end_date': '2006-01-01'}},
|
||||
'end_date': '2006-01-01',
|
||||
'exchange': 'TEST'}},
|
||||
orient='index',
|
||||
),
|
||||
))
|
||||
@@ -227,25 +229,33 @@ class TestMiscellaneousAPI(WithLogger,
|
||||
'root_symbol': 'CL',
|
||||
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2005-12-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-01-20', tz='UTC')},
|
||||
'expiration_date': pd.Timestamp('2006-01-20', tz='UTC'),
|
||||
'exchange': 'TEST'
|
||||
},
|
||||
6: {
|
||||
'root_symbol': 'CL',
|
||||
'symbol': 'CLK06',
|
||||
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2006-03-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-04-20', tz='UTC')},
|
||||
'expiration_date': pd.Timestamp('2006-04-20', tz='UTC'),
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
7: {
|
||||
'symbol': 'CLQ06',
|
||||
'root_symbol': 'CL',
|
||||
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2006-06-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-07-20', tz='UTC')},
|
||||
'expiration_date': pd.Timestamp('2006-07-20', tz='UTC'),
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
8: {
|
||||
'symbol': 'CLX06',
|
||||
'root_symbol': 'CL',
|
||||
'start_date': pd.Timestamp('2006-02-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2006-09-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-10-20', tz='UTC')}
|
||||
'expiration_date': pd.Timestamp('2006-10-20', tz='UTC'),
|
||||
'exchange': 'TEST',
|
||||
}
|
||||
},
|
||||
orient='index',
|
||||
)
|
||||
@@ -737,6 +747,7 @@ def handle_data(context, data):
|
||||
'symbol': 'DUP',
|
||||
'start_date': date.value,
|
||||
'end_date': (date + timedelta(days=1)).value,
|
||||
'exchange': 'TEST',
|
||||
}
|
||||
for i, date in enumerate(dates)
|
||||
]
|
||||
@@ -780,10 +791,13 @@ class TestTransformAlgorithm(WithLogger,
|
||||
|
||||
@classmethod
|
||||
def make_futures_info(cls):
|
||||
return pd.DataFrame.from_dict(
|
||||
{3: {'multiplier': 10, 'symbol': 'F'}},
|
||||
orient='index',
|
||||
)
|
||||
return pd.DataFrame.from_dict({
|
||||
3: {
|
||||
'multiplier': 10,
|
||||
'symbol': 'F',
|
||||
'exchange': 'TEST'
|
||||
}
|
||||
}, orient='index')
|
||||
|
||||
@classmethod
|
||||
def make_equity_daily_bar_data(cls):
|
||||
@@ -989,7 +1003,8 @@ def before_trading_start(context, data):
|
||||
period_end = pd.Timestamp('2002-1-4', tz='UTC')
|
||||
equities = pd.DataFrame([{
|
||||
'start_date': start_session,
|
||||
'end_date': period_end + timedelta(days=1)
|
||||
'end_date': period_end + timedelta(days=1),
|
||||
'exchange': "TEST",
|
||||
}] * 2)
|
||||
equities['symbol'] = ['A', 'B']
|
||||
with TempDirectory() as tempdir, \
|
||||
@@ -2857,7 +2872,8 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
1: {
|
||||
'symbol': 'SYM',
|
||||
'start_date': start,
|
||||
'end_date': start + timedelta(days=6)
|
||||
'end_date': start + timedelta(days=6),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
},
|
||||
orient='index',
|
||||
@@ -2986,6 +3002,8 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
'symbol': 'SYM',
|
||||
'start_date': self.sim_params.start_session,
|
||||
'end_date': '2020-01-01',
|
||||
'exchange': "TEST",
|
||||
'sid': 999,
|
||||
}])
|
||||
with TempDirectory() as tempdir, \
|
||||
tmp_trading_env(equities=metadata) as env:
|
||||
@@ -2997,7 +3015,7 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
env.asset_finder,
|
||||
tempdir,
|
||||
self.sim_params,
|
||||
[0],
|
||||
[999],
|
||||
self.trading_calendar,
|
||||
)
|
||||
algo.run(data_portal)
|
||||
@@ -3006,6 +3024,8 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
'symbol': 'SYM',
|
||||
'start_date': '1989-01-01',
|
||||
'end_date': '1990-01-01',
|
||||
'exchange': "TEST",
|
||||
'sid': 999,
|
||||
}])
|
||||
with TempDirectory() as tempdir, \
|
||||
tmp_trading_env(equities=metadata) as env:
|
||||
@@ -3013,7 +3033,7 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
env.asset_finder,
|
||||
tempdir,
|
||||
self.sim_params,
|
||||
[0],
|
||||
[999],
|
||||
self.trading_calendar,
|
||||
)
|
||||
algo = SetAssetDateBoundsAlgorithm(
|
||||
@@ -3027,6 +3047,8 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
'symbol': 'SYM',
|
||||
'start_date': '2020-01-01',
|
||||
'end_date': '2021-01-01',
|
||||
'exchange': "TEST",
|
||||
'sid': 999,
|
||||
}])
|
||||
with TempDirectory() as tempdir, \
|
||||
tmp_trading_env(equities=metadata) as env:
|
||||
@@ -3034,7 +3056,7 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
env.asset_finder,
|
||||
tempdir,
|
||||
self.sim_params,
|
||||
[0],
|
||||
[999],
|
||||
self.trading_calendar,
|
||||
)
|
||||
algo = SetAssetDateBoundsAlgorithm(
|
||||
@@ -4056,7 +4078,8 @@ class TestOrderAfterDelist(WithTradingEnvironment, ZiplineTestCase):
|
||||
'start_date': cls.start,
|
||||
'end_date': cls.day_1,
|
||||
'auto_close_date': cls.day_4,
|
||||
'symbol': "ASSET1"
|
||||
'symbol': "ASSET1",
|
||||
'exchange': "TEST",
|
||||
},
|
||||
},
|
||||
orient='index',
|
||||
|
||||
+66
-47
@@ -110,21 +110,21 @@ def build_lookup_generic_cases(asset_finder_type):
|
||||
'symbol': 'duplicated',
|
||||
'start_date': dupe_0_start.value,
|
||||
'end_date': dupe_0_end.value,
|
||||
'exchange': '',
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
{
|
||||
'sid': 1,
|
||||
'symbol': 'duplicated',
|
||||
'start_date': dupe_1_start.value,
|
||||
'end_date': dupe_1_end.value,
|
||||
'exchange': '',
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
{
|
||||
'sid': 2,
|
||||
'symbol': 'unique',
|
||||
'start_date': unique_start.value,
|
||||
'end_date': unique_end.value,
|
||||
'exchange': '',
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
],
|
||||
index='sid')
|
||||
@@ -194,15 +194,21 @@ class AssetTestCase(TestCase):
|
||||
exchange='THE MOON',
|
||||
)
|
||||
|
||||
asset3 = Asset(3, exchange="test")
|
||||
asset4 = Asset(4, exchange="test")
|
||||
asset5 = Asset(5, exchange="still testing")
|
||||
|
||||
def test_asset_object(self):
|
||||
self.assertEquals({5061: 'foo'}[Asset(5061)], 'foo')
|
||||
self.assertEquals(Asset(5061), 5061)
|
||||
self.assertEquals(5061, Asset(5061))
|
||||
the_asset = Asset(5061, exchange="bar")
|
||||
|
||||
self.assertEquals(Asset(5061), Asset(5061))
|
||||
self.assertEquals(int(Asset(5061)), 5061)
|
||||
self.assertEquals({5061: 'foo'}[the_asset], 'foo')
|
||||
self.assertEquals(the_asset, 5061)
|
||||
self.assertEquals(5061, the_asset)
|
||||
|
||||
self.assertEquals(str(Asset(5061)), 'Asset(5061)')
|
||||
self.assertEquals(the_asset, the_asset)
|
||||
self.assertEquals(int(the_asset), 5061)
|
||||
|
||||
self.assertEquals(str(the_asset), 'Asset(5061)')
|
||||
|
||||
def test_to_and_from_dict(self):
|
||||
asset_from_dict = Asset.from_dict(self.asset.to_dict())
|
||||
@@ -220,8 +226,8 @@ class AssetTestCase(TestCase):
|
||||
|
||||
def test_asset_comparisons(self):
|
||||
|
||||
s_23 = Asset(23)
|
||||
s_24 = Asset(24)
|
||||
s_23 = Asset(23, exchange="test")
|
||||
s_24 = Asset(24, exchange="test")
|
||||
|
||||
self.assertEqual(s_23, s_23)
|
||||
self.assertEqual(s_23, 23)
|
||||
@@ -250,39 +256,39 @@ class AssetTestCase(TestCase):
|
||||
self.assertGreater(s_24, s_23)
|
||||
|
||||
def test_lt(self):
|
||||
self.assertTrue(Asset(3) < Asset(4))
|
||||
self.assertFalse(Asset(4) < Asset(4))
|
||||
self.assertFalse(Asset(5) < Asset(4))
|
||||
self.assertTrue(self.asset3 < self.asset4)
|
||||
self.assertFalse(self.asset4 < self.asset4)
|
||||
self.assertFalse(self.asset5 < self.asset4)
|
||||
|
||||
def test_le(self):
|
||||
self.assertTrue(Asset(3) <= Asset(4))
|
||||
self.assertTrue(Asset(4) <= Asset(4))
|
||||
self.assertFalse(Asset(5) <= Asset(4))
|
||||
self.assertTrue(self.asset3 <= self.asset4)
|
||||
self.assertTrue(self.asset4 <= self.asset4)
|
||||
self.assertFalse(self.asset5 <= self.asset4)
|
||||
|
||||
def test_eq(self):
|
||||
self.assertFalse(Asset(3) == Asset(4))
|
||||
self.assertTrue(Asset(4) == Asset(4))
|
||||
self.assertFalse(Asset(5) == Asset(4))
|
||||
self.assertFalse(self.asset3 == self.asset4)
|
||||
self.assertTrue(self.asset4 == self.asset4)
|
||||
self.assertFalse(self.asset5 == self.asset4)
|
||||
|
||||
def test_ge(self):
|
||||
self.assertFalse(Asset(3) >= Asset(4))
|
||||
self.assertTrue(Asset(4) >= Asset(4))
|
||||
self.assertTrue(Asset(5) >= Asset(4))
|
||||
self.assertFalse(self.asset3 >= self.asset4)
|
||||
self.assertTrue(self.asset4 >= self.asset4)
|
||||
self.assertTrue(self.asset5 >= self.asset4)
|
||||
|
||||
def test_gt(self):
|
||||
self.assertFalse(Asset(3) > Asset(4))
|
||||
self.assertFalse(Asset(4) > Asset(4))
|
||||
self.assertTrue(Asset(5) > Asset(4))
|
||||
self.assertFalse(self.asset3 > self.asset4)
|
||||
self.assertFalse(self.asset4 > self.asset4)
|
||||
self.assertTrue(self.asset5 > self.asset4)
|
||||
|
||||
def test_type_mismatch(self):
|
||||
if sys.version_info.major < 3:
|
||||
self.assertIsNotNone(Asset(3) < 'a')
|
||||
self.assertIsNotNone('a' < Asset(3))
|
||||
self.assertIsNotNone(self.asset3 < 'a')
|
||||
self.assertIsNotNone('a' < self.asset3)
|
||||
else:
|
||||
with self.assertRaises(TypeError):
|
||||
Asset(3) < 'a'
|
||||
self.asset3 < 'a'
|
||||
with self.assertRaises(TypeError):
|
||||
'a' < Asset(3)
|
||||
'a' < self.asset3
|
||||
|
||||
|
||||
class TestFuture(WithAssetFinder, ZiplineTestCase):
|
||||
@@ -298,6 +304,7 @@ class TestFuture(WithAssetFinder, ZiplineTestCase):
|
||||
'auto_close_date': pd.Timestamp('2014-01-18', tz='UTC'),
|
||||
'tick_size': .01,
|
||||
'multiplier': 500.0,
|
||||
'exchange': "TEST",
|
||||
},
|
||||
0: {
|
||||
'symbol': 'CLG06',
|
||||
@@ -306,6 +313,7 @@ class TestFuture(WithAssetFinder, ZiplineTestCase):
|
||||
'notice_date': pd.Timestamp('2005-12-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-01-20', tz='UTC'),
|
||||
'multiplier': 1.0,
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
},
|
||||
orient='index',
|
||||
@@ -471,9 +479,9 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
|
||||
def test_lookup_symbol_fuzzy(self):
|
||||
metadata = pd.DataFrame.from_records([
|
||||
{'symbol': 'PRTY_HRD'},
|
||||
{'symbol': 'BRKA'},
|
||||
{'symbol': 'BRK_A'},
|
||||
{'symbol': 'PRTY_HRD', 'exchange': "TEST"},
|
||||
{'symbol': 'BRKA', 'exchange': "TEST",},
|
||||
{'symbol': 'BRK_A', 'exchange': "TEST",},
|
||||
])
|
||||
self.write_assets(equities=metadata)
|
||||
finder = self.asset_finder
|
||||
@@ -697,14 +705,14 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
'symbol': 'real',
|
||||
'start_date': pd.Timestamp('2013-1-1', tz='UTC'),
|
||||
'end_date': pd.Timestamp('2014-1-1', tz='UTC'),
|
||||
'exchange': '',
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
{
|
||||
'sid': 1,
|
||||
'symbol': 'also_real',
|
||||
'start_date': pd.Timestamp('2013-1-1', tz='UTC'),
|
||||
'end_date': pd.Timestamp('2014-1-1', tz='UTC'),
|
||||
'exchange': '',
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
# Sid whose end date is before our query date. We should
|
||||
# still correctly find it.
|
||||
@@ -713,7 +721,7 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
'symbol': 'real_but_old',
|
||||
'start_date': pd.Timestamp('2002-1-1', tz='UTC'),
|
||||
'end_date': pd.Timestamp('2003-1-1', tz='UTC'),
|
||||
'exchange': '',
|
||||
'exchange': 'TEST',
|
||||
},
|
||||
# Sid whose start_date is **after** our query date. We should
|
||||
# **not** find it.
|
||||
@@ -749,7 +757,8 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
|
||||
# Build an asset with an end_date
|
||||
eq_end = pd.Timestamp('2012-01-01', tz='UTC')
|
||||
equity_asset = Equity(1, symbol="TESTEQ", end_date=eq_end)
|
||||
equity_asset = Equity(1, symbol="TESTEQ", end_date=eq_end,
|
||||
exchange="TEST")
|
||||
|
||||
# Catch all warnings
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
@@ -772,14 +781,16 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
'root_symbol': 'AD',
|
||||
'notice_date': pd.Timestamp('2015-06-14', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2015-08-14', tz='UTC'),
|
||||
'start_date': pd.Timestamp('2015-01-01', tz='UTC')
|
||||
'start_date': pd.Timestamp('2015-01-01', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
{
|
||||
'symbol': 'ADV15',
|
||||
'root_symbol': 'AD',
|
||||
'notice_date': pd.Timestamp('2015-05-14', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2015-09-14', tz='UTC'),
|
||||
'start_date': pd.Timestamp('2015-01-01', tz='UTC')
|
||||
'start_date': pd.Timestamp('2015-01-01', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
# Starts trading today, so should be valid.
|
||||
{
|
||||
@@ -787,7 +798,8 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
'root_symbol': 'AD',
|
||||
'notice_date': pd.Timestamp('2015-11-16', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2015-12-16', tz='UTC'),
|
||||
'start_date': pd.Timestamp('2015-05-14', tz='UTC')
|
||||
'start_date': pd.Timestamp('2015-05-14', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
# Starts trading in August, so not valid.
|
||||
{
|
||||
@@ -795,7 +807,8 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
'root_symbol': 'AD',
|
||||
'notice_date': pd.Timestamp('2015-11-16', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2015-12-16', tz='UTC'),
|
||||
'start_date': pd.Timestamp('2015-08-01', tz='UTC')
|
||||
'start_date': pd.Timestamp('2015-08-01', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
# Notice date comes after expiration
|
||||
{
|
||||
@@ -803,7 +816,8 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
'root_symbol': 'AD',
|
||||
'notice_date': pd.Timestamp('2016-11-25', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2016-11-16', tz='UTC'),
|
||||
'start_date': pd.Timestamp('2015-08-01', tz='UTC')
|
||||
'start_date': pd.Timestamp('2015-08-01', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
# This contract has no start date and also this contract should be
|
||||
# last in all chains
|
||||
@@ -811,7 +825,8 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
'symbol': 'ADZ20',
|
||||
'root_symbol': 'AD',
|
||||
'notice_date': pd.Timestamp('2020-11-25', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2020-11-16', tz='UTC')
|
||||
'expiration_date': pd.Timestamp('2020-11-16', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
])
|
||||
self.write_assets(futures=metadata)
|
||||
@@ -850,10 +865,10 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
|
||||
# Build an empty finder and some Assets
|
||||
dt = pd.Timestamp('2014-01-01', tz='UTC')
|
||||
finder = self.asset_finder
|
||||
asset1 = Equity(1, symbol="AAPL")
|
||||
asset2 = Equity(2, symbol="GOOG")
|
||||
asset200 = Future(200, symbol="CLK15")
|
||||
asset201 = Future(201, symbol="CLM15")
|
||||
asset1 = Equity(1, symbol="AAPL", exchange="TEST")
|
||||
asset2 = Equity(2, symbol="GOOG", exchange="TEST")
|
||||
asset200 = Future(200, symbol="CLK15", exchange="TEST")
|
||||
asset201 = Future(201, symbol="CLM15", exchange="TEST")
|
||||
|
||||
# Check for correct mapping and types
|
||||
pre_map = [asset1, asset2, asset200, asset201]
|
||||
@@ -1103,6 +1118,7 @@ class TestFutureChain(WithAssetFinder, ZiplineTestCase):
|
||||
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2005-12-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-01-20', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
{
|
||||
'root_symbol': 'CL',
|
||||
@@ -1110,6 +1126,7 @@ class TestFutureChain(WithAssetFinder, ZiplineTestCase):
|
||||
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2006-03-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-04-20', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
{
|
||||
'symbol': 'CLQ06',
|
||||
@@ -1117,6 +1134,7 @@ class TestFutureChain(WithAssetFinder, ZiplineTestCase):
|
||||
'start_date': pd.Timestamp('2005-12-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2006-06-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-07-20', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
},
|
||||
{
|
||||
'symbol': 'CLX06',
|
||||
@@ -1124,6 +1142,7 @@ class TestFutureChain(WithAssetFinder, ZiplineTestCase):
|
||||
'start_date': pd.Timestamp('2006-02-01', tz='UTC'),
|
||||
'notice_date': pd.Timestamp('2006-09-20', tz='UTC'),
|
||||
'expiration_date': pd.Timestamp('2006-10-20', tz='UTC'),
|
||||
'exchange': "TEST",
|
||||
}
|
||||
])
|
||||
|
||||
|
||||
@@ -47,22 +47,26 @@ class TestBenchmark(WithDataPortal, WithSimParams, WithTradingCalendar,
|
||||
1: {
|
||||
'symbol': 'A',
|
||||
'start_date': cls.START_DATE,
|
||||
'end_date': cls.END_DATE + pd.Timedelta(days=1)
|
||||
'end_date': cls.END_DATE + pd.Timedelta(days=1),
|
||||
"exchange": "TEST",
|
||||
},
|
||||
2: {
|
||||
'symbol': 'B',
|
||||
'start_date': cls.START_DATE,
|
||||
'end_date': cls.END_DATE + pd.Timedelta(days=1)
|
||||
'end_date': cls.END_DATE + pd.Timedelta(days=1),
|
||||
"exchange": "TEST",
|
||||
},
|
||||
3: {
|
||||
'symbol': 'C',
|
||||
'start_date': pd.Timestamp('2006-05-26', tz='utc'),
|
||||
'end_date': pd.Timestamp('2006-08-09', tz='utc')
|
||||
'end_date': pd.Timestamp('2006-08-09', tz='utc'),
|
||||
"exchange": "TEST",
|
||||
},
|
||||
4: {
|
||||
'symbol': 'D',
|
||||
'start_date': cls.START_DATE,
|
||||
'end_date': cls.END_DATE + pd.Timedelta(days=1)
|
||||
'end_date': cls.END_DATE + pd.Timedelta(days=1),
|
||||
"exchange": "TEST",
|
||||
},
|
||||
},
|
||||
orient='index',
|
||||
|
||||
+16
-8
@@ -121,42 +121,50 @@ class WithHistory(WithDataPortal):
|
||||
1: {
|
||||
'start_date': pd.Timestamp('2014-01-03', tz='UTC'),
|
||||
'end_date': cls.TRADING_END_DT,
|
||||
'symbol': 'ASSET1'
|
||||
'symbol': 'ASSET1',
|
||||
'exchange': "TEST",
|
||||
},
|
||||
2: {
|
||||
'start_date': jan_5_2015,
|
||||
'end_date': day_after_12312015,
|
||||
'symbol': 'ASSET2'
|
||||
'symbol': 'ASSET2',
|
||||
'exchange': "TEST",
|
||||
},
|
||||
3: {
|
||||
'start_date': jan_5_2015,
|
||||
'end_date': day_after_12312015,
|
||||
'symbol': 'ASSET3'
|
||||
'symbol': 'ASSET3',
|
||||
'exchange': "TEST",
|
||||
},
|
||||
cls.SPLIT_ASSET_SID: {
|
||||
'start_date': jan_5_2015,
|
||||
'end_date': day_after_12312015,
|
||||
'symbol': 'SPLIT_ASSET'
|
||||
'symbol': 'SPLIT_ASSET',
|
||||
'exchange': "TEST",
|
||||
},
|
||||
cls.DIVIDEND_ASSET_SID: {
|
||||
'start_date': jan_5_2015,
|
||||
'end_date': day_after_12312015,
|
||||
'symbol': 'DIVIDEND_ASSET'
|
||||
'symbol': 'DIVIDEND_ASSET',
|
||||
'exchange': "TEST",
|
||||
},
|
||||
cls.MERGER_ASSET_SID: {
|
||||
'start_date': jan_5_2015,
|
||||
'end_date': day_after_12312015,
|
||||
'symbol': 'MERGER_ASSET'
|
||||
'symbol': 'MERGER_ASSET',
|
||||
'exchange': "TEST",
|
||||
},
|
||||
cls.HALF_DAY_TEST_ASSET_SID: {
|
||||
'start_date': pd.Timestamp('2014-07-02', tz='UTC'),
|
||||
'end_date': day_after_12312015,
|
||||
'symbol': 'HALF_DAY_TEST_ASSET'
|
||||
'symbol': 'HALF_DAY_TEST_ASSET',
|
||||
'exchange': "TEST",
|
||||
},
|
||||
cls.SHORT_ASSET_SID: {
|
||||
'start_date': pd.Timestamp('2015-01-05', tz='UTC'),
|
||||
'end_date': pd.Timestamp('2015-01-06', tz='UTC'),
|
||||
'symbol': 'SHORT_ASSET'
|
||||
'symbol': 'SHORT_ASSET',
|
||||
'exchange': "TEST",
|
||||
}
|
||||
},
|
||||
orient='index',
|
||||
|
||||
@@ -1046,6 +1046,7 @@ class TestPositionPerformance(WithInstanceTmpDir, WithTradingCalendar,
|
||||
'start_date': start,
|
||||
'end_date': end,
|
||||
'multiplier': 100,
|
||||
'exchange': "TEST",
|
||||
}
|
||||
for sid in futures_sids
|
||||
},
|
||||
@@ -2345,9 +2346,9 @@ class TestPositionTracker(WithTradingEnvironment,
|
||||
def make_futures_info(cls):
|
||||
return pd.DataFrame.from_dict(
|
||||
{
|
||||
3: {'multiplier': 1000},
|
||||
4: {'multiplier': 1000},
|
||||
1032201401: {'multiplier': 50},
|
||||
3: {'multiplier': 1000, 'exchange': 'TEST'},
|
||||
4: {'multiplier': 1000, 'exchange': 'TEST'},
|
||||
1032201401: {'multiplier': 50, 'exchange': 'TEST'},
|
||||
},
|
||||
orient='index',
|
||||
)
|
||||
|
||||
@@ -85,7 +85,8 @@ class SecurityListTestCase(WithLogger, WithTradingCalendar, ZiplineTestCase):
|
||||
equities=pd.DataFrame.from_records([{
|
||||
'start_date': cls.start,
|
||||
'end_date': end,
|
||||
'symbol': symbol
|
||||
'symbol': symbol,
|
||||
'exchange': "TEST",
|
||||
} for symbol in symbols]),
|
||||
))
|
||||
|
||||
@@ -103,7 +104,8 @@ class SecurityListTestCase(WithLogger, WithTradingCalendar, ZiplineTestCase):
|
||||
equities=pd.DataFrame.from_records([{
|
||||
'start_date': sp2.start_session,
|
||||
'end_date': sp2.end_session,
|
||||
'symbol': symbol
|
||||
'symbol': symbol,
|
||||
'exchange': "TEST",
|
||||
} for symbol in symbols]),
|
||||
))
|
||||
|
||||
@@ -267,6 +269,7 @@ class SecurityListTestCase(WithLogger, WithTradingCalendar, ZiplineTestCase):
|
||||
'symbol': 'BZQ',
|
||||
'start_date': sim_params.start_session,
|
||||
'end_date': sim_params.end_session,
|
||||
'exchange': "TEST",
|
||||
}])
|
||||
with TempDirectory() as new_tempdir, \
|
||||
security_list_copy(), \
|
||||
|
||||
@@ -72,13 +72,13 @@ cdef class Asset:
|
||||
|
||||
def __init__(self,
|
||||
int sid, # sid is required
|
||||
object exchange, # exchange is required
|
||||
object symbol="",
|
||||
object asset_name="",
|
||||
object start_date=None,
|
||||
object end_date=None,
|
||||
object first_traded=None,
|
||||
object auto_close_date=None,
|
||||
object exchange=""):
|
||||
object auto_close_date=None):
|
||||
|
||||
self.sid = sid
|
||||
self.sid_hash = hash(sid)
|
||||
@@ -158,13 +158,13 @@ cdef class Asset:
|
||||
be serialized/deserialized during pickling.
|
||||
"""
|
||||
return (self.__class__, (self.sid,
|
||||
self.exchange,
|
||||
self.symbol,
|
||||
self.asset_name,
|
||||
self.start_date,
|
||||
self.end_date,
|
||||
self.first_traded,
|
||||
self.auto_close_date,
|
||||
self.exchange,))
|
||||
self.auto_close_date,))
|
||||
|
||||
cpdef to_dict(self):
|
||||
"""
|
||||
@@ -295,6 +295,7 @@ cdef class Future(Asset):
|
||||
|
||||
def __init__(self,
|
||||
int sid, # sid is required
|
||||
object exchange, # exchange is required
|
||||
object symbol="",
|
||||
object root_symbol="",
|
||||
object asset_name="",
|
||||
@@ -304,19 +305,18 @@ cdef class Future(Asset):
|
||||
object expiration_date=None,
|
||||
object auto_close_date=None,
|
||||
object first_traded=None,
|
||||
object exchange="",
|
||||
object tick_size="",
|
||||
float multiplier=1.0):
|
||||
|
||||
super().__init__(
|
||||
sid,
|
||||
exchange,
|
||||
symbol=symbol,
|
||||
asset_name=asset_name,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
first_traded=first_traded,
|
||||
auto_close_date=auto_close_date,
|
||||
exchange=exchange,
|
||||
)
|
||||
self.root_symbol = root_symbol
|
||||
self.notice_date = notice_date
|
||||
@@ -351,6 +351,7 @@ cdef class Future(Asset):
|
||||
be serialized/deserialized during pickling.
|
||||
"""
|
||||
return (self.__class__, (self.sid,
|
||||
self.exchange,
|
||||
self.symbol,
|
||||
self.root_symbol,
|
||||
self.asset_name,
|
||||
@@ -360,7 +361,6 @@ cdef class Future(Asset):
|
||||
self.expiration_date,
|
||||
self.auto_close_date,
|
||||
self.first_traded,
|
||||
self.exchange,
|
||||
self.tick_size,
|
||||
self.multiplier,))
|
||||
|
||||
|
||||
@@ -217,6 +217,7 @@ def make_future_info(first_sid,
|
||||
'notice_date': notice_date_func(month_begin),
|
||||
'expiration_date': notice_date_func(month_begin),
|
||||
'multiplier': 500,
|
||||
'exchange': "TEST",
|
||||
})
|
||||
return pd.DataFrame.from_records(contracts, index='sid').convert_objects()
|
||||
|
||||
|
||||
@@ -525,14 +525,14 @@ class SetLongOnlyAlgorithm(TradingAlgorithm):
|
||||
|
||||
class SetAssetDateBoundsAlgorithm(TradingAlgorithm):
|
||||
"""
|
||||
Algorithm that tries to order 1 share of sid 0 on every bar and has an
|
||||
Algorithm that tries to order 1 share of sid 999 on every bar and has an
|
||||
AssetDateBounds() trading control in place.
|
||||
"""
|
||||
def initialize(self):
|
||||
self.register_trading_control(AssetDateBounds())
|
||||
|
||||
def handle_data(algo, data):
|
||||
algo.order(algo.sid(0), 1)
|
||||
algo.order(algo.sid(999), 1)
|
||||
|
||||
|
||||
class TestRegisterTransformAlgorithm(TradingAlgorithm):
|
||||
|
||||
Reference in New Issue
Block a user