portfolios.portfolio_sort_options()
Create portfolio sort options.
Usage
portfolios.portfolio_sort_options(
filter_options=None,
breakpoint_options_main=None,
breakpoint_options_secondary=None,
**kwargs
)Creates a dict of options that bundles sample construction filters and breakpoint specifications for use with ‘implement_portfolio_sort’.
Parameters
filter_options: dict = None-
Dict produced by ‘filter_options’, or None (the default, which applies no filters). The accepted entries include:
- ‘exclude_financials’ (bool): Whether to exclude financial firms (SIC codes 6000 to 6799). Defaults to False.
- ‘exclude_utilities’ (bool): Whether to exclude utility firms (SIC codes 4900 to 4999). Defaults to False.
- ‘min_stock_price’ (float, optional): Minimum stock price required to include an observation. None (the default) applies no price filter.
- ‘min_size_quantile’ (float, optional): Minimum cross-sectional size quantile (based on lagged market cap) required to include an observation. None (the default) applies no size quantile filter.
- ‘min_listing_age’ (float, optional): Minimum number of months a stock must have been listed in CRSP. None (the default) applies no listing age filter.
- ‘exclude_negative_book_equity’ (bool): Whether to exclude observations with non-positive book equity. Defaults to False.
- ‘exclude_negative_earnings’ (bool): Whether to exclude observations with non-positive earnings. Defaults to False.
breakpoint_options_main: dict = None-
Dict produced by ‘breakpoint_options’, specifying breakpoints for the primary sorting variable, or None (the default) when no primary breakpoints are required. The accepted entries include:
- ‘n_portfolios’ (int, optional): Number of equally sized portfolios. Mutually exclusive with ‘percentiles’.
- ‘percentiles’ (list of float, optional): Percentiles for defining the breakpoints. Mutually exclusive with ‘n_portfolios’.
- ‘breakpoints_exchanges’ (str or list of str, optional): Exchange names to filter the data before computing breakpoints. If None, no filtering is applied.
- ‘smooth_bunching’ (bool, optional): Whether to attempt smoothing non-extreme portfolios if the sorting variable bunches on the extremes.
- ‘breakpoints_min_size_threshold’ (float, optional): Value between 0 and 1 (exclusive) below which stocks are excluded from breakpoint computation.
breakpoint_options_secondary: dict = None-
Dict produced by ‘breakpoint_options’, specifying breakpoints for the secondary sorting variable, or None (the default) for univariate sorts. The accepted entries are the same as for ‘breakpoint_options_main’.
**kwargs- Additional optional arguments, stored verbatim in the dict.
Returns
dict- Dict containing the specified options.
Examples
from tidyfinance import (
portfolio_sort_options,
filter_options,
breakpoint_options,
)
portfolio_sort_options(
filter_options=filter_options(exclude_financials=True),
breakpoint_options_main=breakpoint_options(n_portfolios=10),
)