mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-15 12:15:22 +08:00
ENH: Add ContinuousFuture to lookup_generic
This commit is contained in:
+20
-1
@@ -136,6 +136,7 @@ def build_lookup_generic_cases(asset_finder_type):
|
|||||||
{
|
{
|
||||||
'sid': fof14_sid,
|
'sid': fof14_sid,
|
||||||
'symbol': 'FOF14',
|
'symbol': 'FOF14',
|
||||||
|
'root_symbol': 'FO',
|
||||||
'start_date': unique_start.value,
|
'start_date': unique_start.value,
|
||||||
'end_date': unique_end.value,
|
'end_date': unique_end.value,
|
||||||
'exchange': 'FUT',
|
'exchange': 'FUT',
|
||||||
@@ -143,13 +144,25 @@ def build_lookup_generic_cases(asset_finder_type):
|
|||||||
],
|
],
|
||||||
index='sid'
|
index='sid'
|
||||||
)
|
)
|
||||||
with tmp_assets_db(equities=equities, futures=futures) as assets_db:
|
|
||||||
|
root_symbols = pd.DataFrame({
|
||||||
|
'root_symbol': ['FO'],
|
||||||
|
'root_symbol_id': [1],
|
||||||
|
'exchange': ['CME'],
|
||||||
|
})
|
||||||
|
|
||||||
|
with tmp_assets_db(
|
||||||
|
equities=equities, futures=futures, root_symbols=root_symbols) \
|
||||||
|
as assets_db:
|
||||||
finder = asset_finder_type(assets_db)
|
finder = asset_finder_type(assets_db)
|
||||||
dupe_0, dupe_1, unique = assets = [
|
dupe_0, dupe_1, unique = assets = [
|
||||||
finder.retrieve_asset(i)
|
finder.retrieve_asset(i)
|
||||||
for i in range(3)
|
for i in range(3)
|
||||||
]
|
]
|
||||||
fof14 = finder.retrieve_asset(fof14_sid)
|
fof14 = finder.retrieve_asset(fof14_sid)
|
||||||
|
cf = finder.create_continuous_future(
|
||||||
|
root_symbol=fof14.root_symbol, offset=0, roll_style='volume',
|
||||||
|
)
|
||||||
|
|
||||||
dupe_0_start = dupe_0.start_date
|
dupe_0_start = dupe_0.start_date
|
||||||
dupe_1_start = dupe_1.start_date
|
dupe_1_start = dupe_1.start_date
|
||||||
@@ -184,6 +197,9 @@ def build_lookup_generic_cases(asset_finder_type):
|
|||||||
# make sure that code path is exercised.
|
# make sure that code path is exercised.
|
||||||
(finder, fof14_sid, unique_start, fof14),
|
(finder, fof14_sid, unique_start, fof14),
|
||||||
|
|
||||||
|
# ContinuousFuture
|
||||||
|
(finder, cf, None, cf),
|
||||||
|
|
||||||
##
|
##
|
||||||
# Iterables
|
# Iterables
|
||||||
|
|
||||||
@@ -204,6 +220,9 @@ def build_lookup_generic_cases(asset_finder_type):
|
|||||||
|
|
||||||
# Futures and Equities
|
# Futures and Equities
|
||||||
(finder, ['FOF14', 0], None, [fof14, assets[0]]),
|
(finder, ['FOF14', 0], None, [fof14, assets[0]]),
|
||||||
|
|
||||||
|
# ContinuousFuture and Equity
|
||||||
|
(finder, [cf, 0], None, [cf, assets[0]]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1177,6 +1177,10 @@ class AssetFinder(object):
|
|||||||
else:
|
else:
|
||||||
raise SymbolNotFound(symbol=asset_convertible_or_iterable)
|
raise SymbolNotFound(symbol=asset_convertible_or_iterable)
|
||||||
|
|
||||||
|
# If the input is a ContinuousFuture just return it as-is.
|
||||||
|
elif isinstance(asset_convertible_or_iterable, ContinuousFuture):
|
||||||
|
return asset_convertible_or_iterable, missing
|
||||||
|
|
||||||
# Interpret input as iterable.
|
# Interpret input as iterable.
|
||||||
try:
|
try:
|
||||||
iterator = iter(asset_convertible_or_iterable)
|
iterator = iter(asset_convertible_or_iterable)
|
||||||
@@ -1187,7 +1191,10 @@ class AssetFinder(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for obj in iterator:
|
for obj in iterator:
|
||||||
self._lookup_generic_scalar(obj, as_of_date, matches, missing)
|
if isinstance(obj, ContinuousFuture):
|
||||||
|
matches.append(obj)
|
||||||
|
else:
|
||||||
|
self._lookup_generic_scalar(obj, as_of_date, matches, missing)
|
||||||
return matches, missing
|
return matches, missing
|
||||||
|
|
||||||
def map_identifier_index_to_sids(self, index, as_of_date):
|
def map_identifier_index_to_sids(self, index, as_of_date):
|
||||||
|
|||||||
Reference in New Issue
Block a user