portfolios.filter_options()
Create filter options for sample construction.
Usage
portfolios.filter_options(
exclude_financials=False,
exclude_utilities=False,
min_stock_price=None,
min_size_quantile=None,
min_listing_age=None,
exclude_negative_book_equity=False,
exclude_negative_earnings=False,
timing="formation",
**kwargs
)Creates a dict of filter options used for sample construction in tidyfinance-related functions. These options control which observations are retained before portfolio sorting.
Parameters
exclude_financials: bool = False-
Whether to exclude financial firms (SIC codes 6000 to 6799).
exclude_utilities: bool = False-
Whether to exclude utility firms (SIC codes 4900 to 4999).
min_stock_price: float = None-
Minimum stock price required to include an observation. Must be strictly positive when provided. None (the default) applies no price filter.
min_size_quantile: float = None-
Minimum cross-sectional size quantile (based on lagged market cap) required to include an observation. Must be strictly between 0 and 1 when provided. The cutoff is computed from NYSE stocks only; this requires an ‘exchange’ column in the data (as mapped via ‘data_options’). None (the default) applies no size quantile filter.
min_listing_age: float = None-
Minimum number of months a stock must have been listed in CRSP. Must be non-negative when provided. None (the default) applies no listing age filter.
exclude_negative_book_equity: bool = False-
Whether to exclude observations with non-positive book equity.
exclude_negative_earnings: bool = False-
Whether to exclude observations with non-positive earnings.
timing: (formation, every_period) = "formation"-
When the screens apply if portfolios are rebalanced once a year (‘rebalancing_month’ in ‘filter_sorting_data’ or ‘implement_portfolio_sort’). ‘formation’ evaluates the screens in the formation month only and keeps every stock that passes them for the whole holding period (ex-ante screens). ‘every_period’ evaluates them in every month, so a stock that fails a screen in a holding month loses that month’s return (ex-post screens). Ex-post screens use information that is not available when the portfolios are formed, so the resulting factor returns can contain look-ahead bias; a warning is issued when they are used. With monthly rebalancing, every month is a formation month and both options are identical.
**kwargs- Additional optional arguments, stored verbatim in the dict.
Returns
dict- Dict containing the specified filter options.
Examples
from tidyfinance import filter_options
filter_options(
exclude_financials=True,
exclude_utilities=True,
min_stock_price=1,
min_listing_age=12,
)
# Apply the screens in every month (ex-post), not only at formation
filter_options(min_stock_price=5, timing='every_period')