% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/filter_sorting_data.R
\name{filter_sorting_data}
\alias{filter_sorting_data}
\title{Filter Sorting Data}
\usage{
filter_sorting_data(
  data,
  filter_options = NULL,
  data_options = NULL,
  quiet = FALSE
)
}
\arguments{
\item{data}{A data frame containing the stock-level panel data to be
filtered.}

\item{filter_options}{A list of class \code{tidyfinance_filter_options} created
by \code{\link[=filter_options]{filter_options()}}. If \code{NULL} (the default), the defaults from
\code{\link[=filter_options]{filter_options()}} are used (i.e., no filters are applied). The arguments
accepted by \code{\link[=filter_options]{filter_options()}} include
\itemize{
\item \code{exclude_financials} A logical indicating whether to exclude
financial firms (SIC codes 6000–6799). Defaults to \code{FALSE}.
\item \code{exclude_utilities} A logical indicating whether to exclude
utility firms (SIC codes 4900–4999). Defaults to \code{FALSE}.
\item \code{min_stock_price} A single positive numeric specifying the
minimum stock price required to include an observation. \code{NULL} (the
default) applies no price filter.
\item \code{min_size_quantile} A single numeric strictly between 0 and 1
specifying the minimum cross-sectional size quantile (based on lagged
market cap) required to include an observation. \code{NULL} (the default)
applies no size quantile filter. The cutoff is computed from NYSE
stocks only; the \code{exchange} column (mapped via \code{\link[=data_options]{data_options()}})
must be present in the data or an error is raised.
\item \code{min_listing_age} A single non-negative integer or numeric
specifying the minimum number of months a stock must have been listed
in CRSP. \code{NULL} (the default) applies no listing age filter.
\item \code{exclude_negative_book_equity} A logical indicating whether to
exclude observations with non-positive book equity. Defaults to
\code{FALSE}.
\item \code{exclude_negative_earnings} A logical indicating whether to
exclude observations with non-positive earnings. Defaults to \code{FALSE}.
}}

\item{data_options}{A list of class \code{tidyfinance_data_options} (created via
\code{\link[=data_options]{data_options()}}) specifying column name mappings. The \code{siccd} element is
used to specify the SIC code column, \code{price} is used to specify the
(adjusted) price column, \code{mktcap_lag} is used to specify the market
capitalization column, \code{date} is used to specify the date column,
\code{listing_age} is used to specify the listing age column, \code{be} is used to
specify the book equity column, and \code{earnings} is used to specify the
earnings column. Uses \code{\link[=data_options]{data_options()}} default if \code{NULL}:
\code{"siccd" = "siccd"}, \code{"price" = "prc_adj"}, \code{"exchange" = "exchange"}
\code{"mktcap_lag" = "mktcap_lag"}, \code{"date" = "date"},
\code{"listing_age" = "listing_age"}, \code{"be" = "be"}, and \code{"earnings" = "ib"}.}

\item{quiet}{A logical indicating whether informational messages should be
suppressed. Defaults to \code{FALSE}.}
}
\value{
The filtered data frame, preserving the class and structure of the
input.
}
\description{
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.
}
\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
    )
  )

}
\seealso{
Other portfolio functions: 
\code{\link{assign_portfolio}()},
\code{\link{breakpoint_options}()},
\code{\link{compute_breakpoints}()},
\code{\link{compute_long_short_returns}()},
\code{\link{compute_portfolio_returns}()},
\code{\link{data_options}()},
\code{\link{filter_options}()},
\code{\link{implement_portfolio_sort}()},
\code{\link{portfolio_sort_options}()}
}
\concept{portfolio functions}
