Applies sample construction filters to a data frame before portfolio sorting. Filters are applied in a fixed order: financials exclusion, utilities exclusion, minimum stock price, minimum size quantile, minimum listing age, positive book equity, and positive earnings. An informational message is emitted for each filter that actually removes at least one observation.
Arguments
- data
A data frame containing the stock-level panel data to be filtered.
- filter_options
A list of class
tidyfinance_filter_optionscreated byfilter_options(). IfNULL(the default), the defaults fromfilter_options()are used (i.e., no filters are applied). The arguments accepted byfilter_options()includeexclude_financialsA logical indicating whether to exclude financial firms (SIC codes 6000–6799). Defaults toFALSE.exclude_utilitiesA logical indicating whether to exclude utility firms (SIC codes 4900–4999). Defaults toFALSE.min_stock_priceA single positive numeric specifying the minimum stock price required to include an observation.NULL(the default) applies no price filter.min_size_quantileA single numeric strictly between 0 and 1 specifying the minimum cross-sectional size quantile (based on lagged market cap) required to include an observation.NULL(the default) applies no size quantile filter. The cutoff is computed from NYSE stocks only; theexchangecolumn (mapped viadata_options()) must be present in the data or an error is raised.min_listing_ageA single non-negative integer or numeric specifying the minimum number of months a stock must have been listed in CRSP.NULL(the default) applies no listing age filter.exclude_negative_book_equityA logical indicating whether to exclude observations with non-positive book equity. Defaults toFALSE.exclude_negative_earningsA logical indicating whether to exclude observations with non-positive earnings. Defaults toFALSE.
- data_options
A list of class
tidyfinance_data_options(created viadata_options()) specifying column name mappings. Thesiccdelement is used to specify the SIC code column,priceis used to specify the (adjusted) price column,mktcap_lagis used to specify the market capitalization column,dateis used to specify the date column,listing_ageis used to specify the listing age column,beis used to specify the book equity column, andearningsis used to specify the earnings column. Usesdata_options()default ifNULL:"siccd" = "siccd","price" = "prc_adj","exchange" = "exchange""mktcap_lag" = "mktcap_lag","date" = "date","listing_age" = "listing_age","be" = "be", and"earnings" = "ib".- quiet
A logical indicating whether informational messages should be suppressed. Defaults to
FALSE.
Examples
data <- data.frame(
permno = 1:5,
date = as.Date("2020-01-01"),
siccd = c(6100, 2000, 4950, 3000, 6500),
prc_adj = c(5, 0.5, 15, 20, 10)
)
data |>
filter_sorting_data(
filter_options = filter_options(
exclude_financials = TRUE,
min_stock_price = 1
)
)
#> Filter 'exclude_financials': removed 2 observations.
#> Filter 'min_stock_price': removed 1 observation.
#> permno date siccd prc_adj
#> 1 3 2020-01-01 4950 15
#> 2 4 2020-01-01 3000 20