weight {portfolio} | R Documentation |
Calculate Position Weights
Description
Compute position weights of various types from an input variable.
Usage
weight(x, in.var, type, size, sides,
weight.var = NULL, verbose = FALSE)
Arguments
x |
A data.frame containing the columns |
in.var |
Character vector specifying the column in |
type |
Character vector specifying the method to use for weight
creation. Can be one of |
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 |
sides |
Character vector specifying the sides for which to
create weights. May be any nonempty subset of |
weight.var |
Numeric vector containing specifying the column in
|
verbose |
Be verbose. Defaults to FALSE. |
Value
A numeric vector of weights the same length as x
.
Author(s)
Jeff Enos jeff@kanecap.com
Examples
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")