UniverseGenerator

UniverseGenerator#

class sigtech.framework.instruments.sig_master.UniverseGenerator

Universe generator from SIGMaster to define universes over a data range.

Example usage:

env = sig.init()
sm = env.sig_master()

ug = sm.get_universe_generator()
ug = ug.filter(value='US', column='EXCHANGE_COUNTRY_ISO2', op='==')

dates = [dtm.date(2022, 2, 2), dtm.date(2022, 3, 2)]
universes = ug.apply(dates)
euf = sig.EquityUniverseFilter(universes)
apply(dates: Union[list[datetime.date], list[datetime.datetime], DatetimeIndex], primary_fungible_only: bool = True, primary_tradable_only: bool = True, single_stocks_only: bool = True) dict

Execute the SIGMaster filters defined and return a dict containing a list of dates as keys and universes (i.e. lists of single stocks) as values. The dict can be an input of EquityUniverseFilter.

Parameters:
  • dates – A list of datetimes, a list of dates or pandas DatetimeIndex.

  • primary_fungible_only – Include only the primary fungible for every company (default is True).

  • primary_tradable_only – Include only the primary tradable for every fungible (default is True).

  • single_stocks_only – Include only single stock securities (e.g. ETFs are filtered out, default is True).

Returns:

dict (date: list of single stocks).

cleanup() None

Remove all filters set by the user.

filter(value: Union[str, list[str]], column: str = 'ISSUE_NAME', op: str = '==') UniverseGenerator

Security master filter using specific operating codes for a particular column. Use filter_like for string-like filtering.

Parameters:
  • value – Value or list or values to filter.

  • column – Column to filter on (defaults to 'ISSUE_NAME'), use SIGMaster info() to show valid columns.

  • op – Operator used during filtering, valid values are ‘<’, ‘<=’, ‘==’, ‘!=’, ‘>=’, ‘>’, ‘in’, ‘not in’.

Returns:

A new filtered UniverseGenerator object.

filter_company(internal_id: str) UniverseGenerator

Return all records matching the time invariant 'SIG.COMPANY_INTERNAL_ID' column value.

Parameters:

internal_id – SIG company internal identifier.

Returns:

A new filtered UniverseGenerator object.

filter_exchange_tickers(exchange_tickers: Sequence = None) UniverseGenerator

Return all records matching 'EXCHANGE_TICKER' column value, indicating the exchange ticker for each stock at a specific venue.

Parameters:

exchange_tickers – Sequence of exchange tickers to filter on. Use SIGMaster show_filter_values() with column='EXCHANGE_TICKER' to see valid values.

Returns:

A new filtered UniverseGenerator object.

filter_fungible(internal_id: str) UniverseGenerator

Return all records matching the time invariant 'SIG.FUNGIBLE_INTERNAL_ID' column value.

Parameters:

internal_id – SIG fungible internal identifier.

Returns:

A new filtered UniverseGenerator object.

filter_isna(column: str = 'ISSUE_NAME') UniverseGenerator

Security master filter for removing rows with column value null/None/NaN or otherwise empty.

Parameters:

column – Column name to filter (defaults to 'ISSUE_NAME'). Use SIGMaster info() to show valid columns.

Returns:

A new filtered UniverseGenerator object.

filter_like(like: str, column: str = 'ISSUE_NAME', negate: bool = False) UniverseGenerator

Security master string-like filter using specific operating codes for a particular column. It wraps the pandas DataFrame filter method, e.g. df.filter(like='value', axis=0).

Parameters:
  • like – value to filter on (case-sensitive) e.g. 'BERKSHIRE HATHAWAY'.

  • column – Column name to filter (defaults to 'ISSUE_NAME'). Use SIGMaster info() to show valid columns.

  • negate – Negate the condition if set to True, e.g. value is not like.

Returns:

A new filtered UniverseGenerator object.

filter_notna(column: str = 'ISSUE_NAME') UniverseGenerator

Security master filter for keeping rows with column value null/None/NaN or otherwise empty.

Parameters:

column – Column name to filter (defaults to 'ISSUE_NAME'). Use SIGMaster info() to show valid columns.

Returns:

A new filtered UniverseGenerator object.

filter_operating_mic(operating_mics: Sequence = None) UniverseGenerator

Return all records matching 'OPERATING_MIC' column value, indicating the ISO10383 operating mic where the stock is traded.

Parameters:

operating_mics – Sequence of operating mics to filter on. Use SIGMaster show_filter_values() with column='OPERATING_MIC' to see valid values.

Returns:

A new filtered UniverseGenerator object.

filter_primary_fungible() UniverseGenerator

Return all records matching 'PRIMARY_FUNGIBLE' column value, indicating whether the stock is the primary fungible for a company.

Returns:

A new filtered UniverseGenerator object.

filter_primary_tradable(value='Y') UniverseGenerator

Return all records matching 'PRIMARY_TRADABLE' column value, indicating whether the stock is the primary tradable for a particular fungible.

Parameters:

value – Set to 'Y' for primary tradable, 'N' for not primary tradable.

Returns:

A new filtered UniverseGenerator object.

filter_startswith(startswith: str, column: str = 'ISSUE_NAME', negate: bool = False) UniverseGenerator

Security master string-like filter using string prefix on a particular column. This method is case-sensitive.

Parameters:
  • startswith – value to filter on (case-sensitive) e.g. 'BERKSHIRE'.

  • column – Column name to filter (defaults to 'ISSUE_NAME'). Use SIGMaster info() to show valid columns.

  • negate – Negate the condition if set to True, e.g. value does not start with.

Returns:

A new filtered UniverseGenerator object.

filter_tradable(internal_id: str) UniverseGenerator

Return all records matching the time invariant 'SIG.TRADABLE_INTERNAL_ID' column value.

Parameters:

internal_id – SIG tradable internal identifier.

Returns:

A new filtered UniverseGenerator object.

filter_tradable_active(value: int = 1) UniverseGenerator

Return all records matching 'TRADABLE_ACTIVE' column value, indicating whether the stock is active/inactive, e.g. stocks may be deactivated due to de-listings.

Parameters:

value – Set to 1` for active, ``0 for inactive.

Returns:

A new filtered UniverseGenerator object.