MCPcopy
hub / github.com/quantopian/zipline / lookup_generic

Method lookup_generic

zipline/assets/assets.py:1350–1417  ·  view source on GitHub ↗

Convert an object into an Asset or sequence of Assets. This method exists primarily as a convenience for implementing user-facing APIs that can handle multiple kinds of input. It should not be used for internal code where we already know the expected types

(self, obj, as_of_date, country_code)

Source from the content-addressed store, hash-verified

1348 raise NotAssetConvertible("Input was %s, not AssetConvertible." % obj)
1349
1350 def lookup_generic(self, obj, as_of_date, country_code):
1351 """
1352 Convert an object into an Asset or sequence of Assets.
1353
1354 This method exists primarily as a convenience for implementing
1355 user-facing APIs that can handle multiple kinds of input. It should
1356 not be used for internal code where we already know the expected types
1357 of our inputs.
1358
1359 Parameters
1360 ----------
1361 obj : int, str, Asset, ContinuousFuture, or iterable
1362 The object to be converted into one or more Assets.
1363 Integers are interpreted as sids. Strings are interpreted as
1364 tickers. Assets and ContinuousFutures are returned unchanged.
1365 as_of_date : pd.Timestamp or None
1366 Timestamp to use to disambiguate ticker lookups. Has the same
1367 semantics as in `lookup_symbol`.
1368 country_code : str or None
1369 ISO-3166 country code to use to disambiguate ticker lookups. Has
1370 the same semantics as in `lookup_symbol`.
1371
1372 Returns
1373 -------
1374 matches, missing : tuple
1375 ``matches`` is the result of the conversion. ``missing`` is a list
1376 containing any values that couldn't be resolved. If ``obj`` is not
1377 an iterable, ``missing`` will be an empty list.
1378 """
1379 matches = []
1380 missing = []
1381
1382 # Interpret input as scalar.
1383 if isinstance(obj, (AssetConvertible, ContinuousFuture)):
1384 self._lookup_generic_scalar(
1385 obj=obj,
1386 as_of_date=as_of_date,
1387 country_code=country_code,
1388 matches=matches,
1389 missing=missing,
1390 )
1391 try:
1392 return matches[0], missing
1393 except IndexError:
1394 if hasattr(obj, '__int__'):
1395 raise SidsNotFound(sids=[obj])
1396 else:
1397 raise SymbolNotFound(symbol=obj)
1398
1399 # Interpret input as iterable.
1400 try:
1401 iterator = iter(obj)
1402 except TypeError:
1403 raise NotAssetConvertible(
1404 "Input was not a AssetConvertible "
1405 "or iterable of AssetConvertible."
1406 )
1407

Calls 4

SidsNotFoundClass · 0.90
SymbolNotFoundClass · 0.90
NotAssetConvertibleClass · 0.85