View source: R/assign_portfolio.R
assign_portfolio | R Documentation |
This function assigns data points to portfolios based on a specified
sorting variable and the selected function to compute breakpoints. Users
can specify a function to compute breakpoints. The function must take
data
and sorting_variable
as the first two arguments. Additional
arguments are passed with a named list breakpoint_options. The
function needs to return an ascending vector of breakpoints. By default,
breakpoints are computed with compute_breakpoints. The default
column names can be modified using data_options.
assign_portfolio(
data,
sorting_variable,
breakpoint_options = NULL,
breakpoint_function = compute_breakpoints,
data_options = NULL
)
data |
A data frame containing the dataset for portfolio assignment. |
sorting_variable |
A string specifying the column name in |
breakpoint_options |
An optional named list of arguments passed to
|
breakpoint_function |
A function to compute breakpoints. The default is set to compute_breakpoints. |
data_options |
A named list of data_options with characters,
indicating the column names required to run this function. The required
column names identify dates. Defaults to |
A vector of portfolio assignments for each row in the input data
.
data <- data.frame(
id = 1:100,
exchange = sample(c("NYSE", "NASDAQ"), 100, replace = TRUE),
market_cap = 1:100
)
assign_portfolio(data, "market_cap", breakpoint_options(n_portfolios = 5))
assign_portfolio(
data, "market_cap",
breakpoint_options(percentiles = c(0.2, 0.4, 0.6, 0.8), breakpoint_exchanges = c("NYSE"))
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.