weight: Calculate Position Weights

Description Usage Arguments Value Author(s) Examples

View source: R/weight.R

Description

Compute position weights of various types from an input variable.

Usage

1
2
weight(x, in.var, type, size, sides,
       weight.var = NULL, verbose = FALSE)

Arguments

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.

Value

A numeric vector of weights the same length as x.

Author(s)

Jeff Enos jeff@kanecap.com

Examples

1
2
3
4
5
6
7
8
9
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")

portfolio documentation built on July 10, 2021, 5:08 p.m.