quantlab.dataset.base.TickerLookup#

class quantlab.dataset.base.TickerLookup[source]#

Bases: ABC

Names a dataset’s symbol ids as of a day: the ticker and company in use.

A panel’s symbol axis can hold an id meant for code (a CRSP PERMNO, a Sharadar permaticker) rather than the ticker a person reads. A dataset names the lookup that applies to its symbols with BaseDataset.ticker_lookup(), and display code (a backtest’s settlement and rejected-order records, its benchmark name, a membership report) labels symbols through this interface without knowing the vendor. A ticker can change while the id stays (FB, then META), so every answer is as of one day.

A subclass implements names; label is the ticker alone.

Examples

>>> from datetime import date
>>> class Fixed(TickerLookup):
...     def names(self, symbols, day):
...         known = {13407: SymbolName("META", "Meta Platforms")}
...         return [known.get(s, SymbolName(str(s))) for s in symbols]
>>> Fixed().label([13407, 99999], date(2024, 1, 2))
['META', '99999']
label(symbols, day)[source]#

Return the ticker of each of symbols on day, in order.

The ticker of names, so it never raises and an unknown symbol reads as its own id.

Parameters:
symbolsSequence

Symbol ids as on the panel’s symbol axis.

daydatetime.date

The date whose tickers to use.

Returns:
list of str

One label per input, in the input’s order.

Examples

>>> Fixed().label([13407, 99999], date(2024, 1, 2))
['META', '99999']
abstractmethod names(symbols, day)[source]#

Return the name of each of symbols on day, in order.

Never raises for a symbol it cannot name or a source it cannot read: such a symbol gets SymbolName(str(symbol), None), because the callers are display code that must not fail for lack of a name.

Parameters:
symbolsSequence

Symbol ids as on the panel’s symbol axis.

daydatetime.date

The date whose names to use.

Returns:
list of SymbolName

One name per input, in the input’s order.

Examples

>>> Fixed().names([13407, 99999], date(2024, 1, 2))
[SymbolName(ticker='META', company='Meta Platforms'), SymbolName(ticker='99999', company=None)]