This page introduces Single Stock instruments and shows how you can define an equity universe through the EquityUniverseFilter or SigMaster classes.
Both classes are powerful tools for filtering an equity universe:
The starting point for EquityUniverseFilter is defined as a stock index, which then can be filtered by a number of different metrics, such as fundamental data.
The starting point for SigMaster is all securities available at a given point in time.
Set up your environment using the following three steps:
Import the relevant internal and external libraries
Configure the environment parameters
Initialise the environment
import sigtech.framework as sigimport datetime as dtmimport pandas as pdimport numpy as npimport seaborn as snssns.set(rc={'figure.figsize': (18, 6)})env = sig.config.init()
TRBC (The Refinitiv Business Classification) filtering
Note: TRBC stands for The Refinitiv Business Classification
SigMaster is filtered according to the five-level TRBC classification scheme:
Economic sectors
Business sectors
Industry groups
Industries
Activities
levels = ['TRBC_ECONOMIC_SECTOR','TRBC_BUSINESS_SECTOR','TRBC_INDUSTRY_GROUP','TRBC_INDUSTRY','TRBC_ACTIVITY' ]all_classifications ={c: sig_master.show_filter_values(c).tolist()for c in levels}all_classifications
The apply method can be called with a list of dates to evaluate the universe. By default, the apply method will filter each point in time for primary fungibles, primary tradable, and single stock securities. The resulting dictionary can be passed to the EquityUniverseFilter for additional filtering:
The add() method takes a fundamental or history field, such as:
An operator
A value/threshold
The frequency of the field.
Fields, operators and frequencies are case-insensitive. To see the available fundamental and history fields we can use the available_fields() method on a stock object.
equity_filter.add('market cap USD', '>', 1e4, 'Quarterly')# Denominated in millions.equity_filter.add('Price/Earnings Ratio', '<', 50, 'annual')equity_filter.add('Dividend yield', 'TOP', 5, 'quarterly')equity_filter.add('Healthcare', 'in', 'TRBC_ECONOMIC_SECTOR')equity_filter.list()
The available filter operators available are listed below. When the 'Body, 5' operator is applied to a field it filters out the top 5 and bottom 5 stock IDs.
Method apply_filter() takes a date or a list of dates and applies the filters defined using add() in the following order:
All comparison operators (<, <=, ==, !=, >=, >) are first applied in the order defined by the user.
All ranking operators (top, bottom, body) are subsequently applied in the order defined by the user.
Parameter ignore_asofdate controls how the underlying time series is loaded by the filter engine:
If set to True, which is the default, the time series loaded will use the as of date set in the environment.
If set to False, the as of date of the time series coincides with the date in which the filter is applied. When applied to multiple dates, this setting may be more computationally expensive.
Only the time series for the fields specified in the filters are loaded. In the following example, filters are applied to multiple points in time. This returns a list of filtered stock identifiers for each point in time:
This section contains examples of additional features, useful for debugging purposes or to analyse the results of a stock universe filter.
Filtered output
Method display_fields_data() returns a DataFrame containing time series data defined by a date and a list of stock ids, fields and frequencies:
# Select first 10 unique stocks that were eligible at any point in time in our universe
ids = universe.explode().unique()[:10]
# The corresponding data was not loaded during filtering, it will load now
display_fields = ['TOTAL ASSETS', 'Net Sales or Revenues', 'VWAP']
display_frequencies = ['Quarterly', 'Quarterly', 'Annual', 'Daily']
equity_filter.display_fields_data(date=pd.Timestamp(2019, 1, 15),
ids=ids,
fields=display_fields,
frequencies=display_frequencies)
Multiple stock tradables may be issued by a listed company. The following code block returns the companies associated with the filtered stock IDs:
['RAYMOND JAMES FINL.INCO.',
'T ROWE PRICE GROUP INCO.',
'WELLCARE HLTH.PLANS INCO',
'MASTERCARD INCO.',
'CHARLES SCHWAB CORP.']
Generic constructor
The EquityUniverseFilter constructor also supports a dict, such as date or list of stock IDs, for stock universe customisations.
You can populate a data structure representing a stock universe with dates and lists of stock identifiers available on those dates. In the following example, the sm_universe dictionary generated from SigMaster is passed: