applyWeights: Apply a set of weights to the columns of an xts object.

Description Usage Arguments Value Examples

View source: R/applyWeights.R

Description

This function is just a wrapper to the 'sweep' function because the arguments to sweep are too hard to remember.

Usage

1

Arguments

w

the weight vector. Must have same number of elements as columns in R.

R

the xts object of returns or assets.

Value

an xts object with the weights, w, applied to R.

Examples

1
2
3
4
5
6
7
8
library(xts)
dts <- seq(Sys.Date()-4, Sys.Date(), 1)
returns <- matrix(rnorm(10),ncol = 2) / 100
ret.xts <- xts(returns, dts)
wts <- c(.50, .50)
returns.wtd <- applyWeights(wts, ret.xts)
# check...
returns/returns.wtd

gtog/dMisc documentation built on May 17, 2019, 8:57 a.m.