View source: R/compute_breakpoints.R
| compute_breakpoints | R Documentation |
Computes breakpoints based on a specified sorting. It can optionally filter the data by exchanges or lagged size quantiles before computing the breakpoints. The function requires either the number of portfolios to be created or specific percentiles for the breakpoints, but not both. The function also optionally handles cases where the sorting variable clusters on the edges, by assigning all extreme values to the edges and attempting to compute equally populated breakpoints with the remaining values.
compute_breakpoints(
data,
sorting_variable,
breakpoint_options,
data_options = NULL
)
data |
A data frame containing the dataset for breakpoint computation. |
sorting_variable |
A character string specifying the column name in
|
breakpoint_options |
A named list of
|
data_options |
A list of class |
A numeric vector of breakpoints of the desired length.
This function will stop and throw an error if both n_portfolios and
percentiles are provided or missing simultaneously.
Other portfolio functions:
assign_portfolio(),
breakpoint_options(),
compute_long_short_returns(),
compute_portfolio_returns(),
data_options(),
filter_options(),
filter_sorting_data(),
implement_portfolio_sort(),
portfolio_sort_options()
set.seed(42)
data <- data.frame(
id = 1:100,
exchange = sample(c("NYSE", "NASDAQ"), 100, replace = TRUE),
market_cap = 1:100
)
compute_breakpoints(data, "market_cap", breakpoint_options(n_portfolios = 5))
compute_breakpoints(
data,
"market_cap",
breakpoint_options(
percentiles = c(0.2, 0.4, 0.6, 0.8),
breakpoints_exchanges = c("NYSE")
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.