weight {portfolio} | R Documentation |
Compute position weights of various types from an input variable.
weight(x, in.var, type, size, sides, weight.var = NULL, verbose = FALSE)
x |
A data.frame containing the columns in.var and
weight.var (if necessary). |
in.var |
Character vector specifying the column in x
that contains a ranking from which weights can be computed. |
type |
Character vector specifying the method to use for weight
creation. Can be one of c("relative", "equal", "linear",
"sigmoid", "centroid", "complex") . |
size |
Character or numeric vector specifying the number of
desired non-na weights per side in the result. Can either be a
positive number or one of "all", "decile", "quintile",
"tercile", "demile") . |
sides |
Character vector specifying the sides for which to
create weights. May be any nonempty subset of "long",
"short" . |
weight.var |
Numeric vector containing specifying the column in
x that contains weight overrides. Overrides are applied
after weights have been computed. Defaults to NULL. |
verbose |
Be verbose. Defaults to FALSE. |
A numeric vector of weights the same length as x
.
Jeff Enos jeff@kanecap.com
data <- data.frame(in.var = 1:50, weight.var = NA) data$in.var <- as.numeric(data$in.var) weight(data, in.var = "in.var", type = "linear", size = "quintile", sides = c("long", "short")) data$weight.var[25] <- -0.05 weight(data, in.var = "in.var", type = "linear", size = "quintile", sides = c("long", "short"), weight.var = "weight.var")