SIGMasterBase

SIGMasterBase#

class sigtech.framework.instruments.sig_master.SIGMasterBase

Subclasses: SIGMasterPOPO, SIGMaster

SIGMaster single stocks API.

As a rule of thumb, if am obs_timestamp, or market_date is not supplied, the latest available data in both cases will be used. If either value is set to None, then that level of filtering is explicitly disabled.

COMPANY_INTERNAL_ID = 'SIG.COMPANY_INTERNAL_ID'
FUNGIBLE_INTERNAL_ID = 'SIG.FUNGIBLE_INTERNAL_ID'
property print_output

State of the print output flag.

property sig_master_dataframe

Underlying SIGMaster pandas DataFrame.

TRADABLE_INTERNAL_ID = 'SIG.TRADABLE_INTERNAL_ID'
filter(value: Union[str, list[str]], column: str = 'ISSUE_NAME', op: str = '==') SIGMaster

Useful for filtering using specific op codes for a particular column. Use filter_like(…) for text/str like filtering.

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

  • column – Column to filter on (defaults to ISSUE_NAME), use obj.get('SIG MASTER').info() to show valid columns.

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

Returns:

A new filtered SIGMaster FrameworkObject.

filter_as_of(as_of=None) SIGMaster

SIGMaster is a Point in Time (PIT) set of data records e.g. all corporate events for all companies.

Setting the as_of allows you to time travel to see available data records at that point in time. All subsequent records are removed. This allows us to realistically back-test strategies. The use of stable time agnostic SIG IDs supports data integrity e.g. other IDs may move/change.

  • SIG tradable ID column shown using obj.get(‘SIG MASTER’)._tradable_internal_id_column().

  • SIG fungible ID column shown using obj.get(‘SIG MASTER’)._fungible_internal_id_column().

  • SIG company ID column shown using obj.get(‘SIG MASTER’)._company_internal_id_column().

By default, filter_as_of is called on SIGMaster data load, and set to the configured env as_of date.

Parameters:

as_of – str or datetime-like value to time travel to e.g. ‘2015-01-02’.

Returns:

A new filtered SIGMaster FrameworkObject.

Raises:

ValueError: when you try to time travel to a future date from the current SIGMaster as_of date.

filter_company(internal_id: str) SIGMaster

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

Parameters:

internal_id – SIG company internal_id.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_exchange_tickers(exchange_tickers: Sequence = None) SIGMaster

The EXCHANGE_TICKER column indicates the exchange ticker for each stock at a specific venue. Useful to daisy chain to lookup stocks, e.g. obj.get(‘SIG MASTER’).filter_operating_mic(…).filter_exchange_tickers(…)

Parameters:

exchange_tickers – Sequence of exchange tickers to filter on. Use obj.get(‘SIG MASTER’).show_filter_values(column=’EXCHANGE_TICKER’) to see valid values.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_fungible(internal_id: str) SIGMaster

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

Parameters:

internal_id – SIG fungible internal_id.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_isna(column: str = 'ISSUE_NAME') SIGMaster

Useful for filtering rows to where the column value is null/None/NaN or otherwise empty.

Parameters:

column – Column name to filter (defaults to ISSUE_NAME). Use sig.obj.get('SIG MASTER').info() to show valid columns.

Returns:

A new filtered SIGMaster object.

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

Useful for text/str like filtering. Use filter(…) for specific value filtering

Wraps the pandas dataframe filter method: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.filter.html, e.g. df.filter(like=’value’, axis=0).

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

  • column – column to filter on (defaults to ISSUE_NAME), use obj.get('SIG MASTER').info() to show valid columns.

  • negate – boolean not operation if passed as True e.g. value is NOT like.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_notna(column: str = 'ISSUE_NAME') SIGMaster

Useful for filtering rows to where the column value is not null/None/NaN or otherwise empty.

Parameters:

column – Column name to filter (defaults to ISSUE_NAME). Use sig.obj.get('SIG MASTER').info() to show valid columns.

Returns:

A new filtered SIGMaster object.

filter_operating_mic(operating_mics: Sequence = None) SIGMaster

The OPERATING_MIC column indicates the ISO10383 operating mic where the stock is traded. See https://www.iso20022.org/market-identifier-codes.

Parameters:

operating_mics – Sequence of operating mics to filter on. Use obj.get(‘SIG MASTER’).show_filter_values(column=’OPERATING_MIC’) to see valid values.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_primary_fungible() SIGMaster

The PRIMARY_FUNGIBLE column indicates whether stock is the primary fungible for a company.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_primary_tradable(value='Y') SIGMaster

The PRIMARY_TRADABLE column indicates whether 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 SIGMaster FrameworkObject.

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

Useful for filtering the string prefix of a particular column. This method is case-sensitive. Use filter_like(…) for text/str like filtering

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

  • column – column to filter on (defaults to ISSUE_NAME), use obj.get('SIG MASTER').info() to show valid columns.

  • negate – boolean not operation if passed as True e.g. value does NOT start with.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_to_last_pit_record() SIGMaster

SIGMaster is a Point in Time (PIT) set of data records. A new record is created for each tradable stock when a data point changes for it, e.g. ticker.

This filter removes historical records for all stocks, retaining only the current/most recent data points.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_tradable(internal_id: str) SIGMaster

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

Parameters:

internal_id – SIG tradable internal_id.

Returns:

A new filtered SIGMaster FrameworkObject.

filter_tradable_active(value: int = 1) SIGMaster

The TRADABLE_ACTIVE column indicates whether 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 SIGMaster FrameworkObject.

from_pandas(sig_master_dataframe: DataFrame = None) SIGMaster

Load SIGMaster from a pandas DataFrame.

Parameters:

sig_master_dataframe – pandas DataFrame.

Returns:

SIGMaster object.

from_parquet(file_path: str = None)

Load SIGMaster from a Parquet source.

Parameters:

file_path – Path of the Parquet file.

Returns:

SIGMaster object.

get_company_ids(lookup_values: Sequence[str] = None, lookup_column: str = 'EXCHANGE_TICKER') dict

Filter values for issuing companies.

Parameters:
  • lookup_values – Sequence of strings used for lookup (optional).

  • lookup_column – SIGMaster column used for lookup (optional).

Returns:

dict.

get_fungible_ids(lookup_values: Sequence[str] = None, lookup_column: str = 'EXCHANGE_TICKER') dict

Filter values for fungible stocks.

Parameters:
  • lookup_values – Sequence of strings used for lookup (optional).

  • lookup_column – SIGMaster column used for lookup (optional).

Returns:

dict.

get_tradable_ids(lookup_values: Sequence[str] = None, lookup_column: str = 'EXCHANGE_TICKER') dict

Filter values for tradable stocks.

Parameters:
  • lookup_values – Sequence of strings used for lookup (optional).

  • lookup_column – SIGMaster column used for lookup (optional).

Returns:

dict.

get_universe_generator() UniverseGenerator

Return a universe generator from SIGMaster to define universes over a data range. See UniverseGenerator for an example.

help()

See SIG_single_stocks_SIGMaster_API.ipynb for a short introduction to the SIGMaster single stocks API, aimed at new users.

SIGMaster is point in time (PIT) data record:

  • Recording all historical stock events (mergers, name changes etc)

  • This allows time travel when back-testing.

  • Use sig_master.filter_as_of? for more details

Many useful built-in filters and views exist to allow easy SIGMaster browsing, navigation and universe filtering.

Basic filter usage:

  • sig_master.filter_primary_tradable()

  • sig_master.filter_operating_mic(operating_mics=[‘XNAS’, ‘XNYS’])

  • sig_master.filter_like(like=’BERKSHIRE HATHAWAY’, column=’ISSUE_NAME’)

Daisy chaining filters:

  • sig_master

  • .filter_primary_tradable()

  • .filter_operating_mic(operating_mics=[‘XNAS’, ‘XNYS’])

  • .filter_like(like=’BERKSHIRE HATHAWAY’, column=’ISSUE_NAME’)

Help functions:

  • sig_master.filter_operating_mic? : show docstr for a particular filter function

  • sig_master.show_filters() : show all filters with their docstr

  • sig_master.show_filter_values(column=’OPERATING_MIC’, dropna=True) : shows SIGMaster values for a column

  • sig_master.info() : wraps pandas .info()

  • sig_master.info_column_descriptions() : shows basic descriptions for each column

Pre-baked pandas dataframe views:

  • sig_master.to_pandas_trading_view() : useful for trading/exchange considerations

  • sig_master.to_pandas_data_model_view() : useful for viewing company/fungible/tradable relationships

  • sig_master.to_pandas_point_in_time_view() : useful for time travelling

Useful data model filter/views:

  • sig_master.filter_tradable(internal_id=’1002224.SINGLE_STOCK.TRADABLE’).to_pandas_trading_view()

  • sig_master.filter_fungible(internal_id=’1002203.SINGLE_STOCK’).to_pandas_trading_view()

  • sig_master.filter_company(internal_id=’1002011.COMPANY’).to_pandas_trading_view()

SIG building blocks integration:

  • sig_master.to_single_stock()

history() DataFrame

Return SIGMaster time series.

info() None

Prints a concise summary of the SIGMaster’s internal DataFrame.

info_column_descriptions()

Shows description of SIG Master columns.

show_filter_values(column: str, dropna: bool = True) list

Shows SIGMaster values for a column.

Parameters:
  • column – Input column.

  • dropna – Drop NaN values (default is True).

Returns:

List of unique values.

show_filters()

Show all filters with their docstring.

to_pandas() DataFrame

Save SIGMaster to a pandas DataFrame.

Returns:

pandas DataFrame.

to_pandas_data_model_view() DataFrame

Return a DataFrame for viewing company/fungible/tradable relationships.

to_pandas_point_in_time_view()

Return a DataFrame for time travelling considerations.

to_pandas_trading_view() DataFrame

Return a DataFrame for trading/exchange considerations.

to_single_stock(tradable_internal_ids: Optional[Sequence[str]] = None, use_tradable_internal_id_as_result_key: bool = False) dict

Returns a dict of SingleStock instruments.

Parameters:
  • tradable_internal_ids – Optional sequence of str, or the tradable internal ids for the current SIGMaster.

  • use_tradable_internal_id_as_result_key – If set to True, the tradable internal id is used as the result key, otherwise use EXCHANGE_TICKER and OPERATING_MIC.

Returns:

dict of SingleStock objects.