Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rc

Return Contribution


Description

Return contribution of portfolio segments.

Usage

rc(R, weights, timestamp, segments = NULL)

Arguments

R

returns: a numeric matrix

weights

the segment weights: a numeric matrix. weights[i,j] must correspond to R[i,j]

timestamp

character or numeric

segments

character. If missing, column names of R or of weights are used (if they are not NULL).

Details

The function computes segment contribution, potentially over time. Returns and weights must be arranged in matrices, with rows corresponding to time periods and columns to portfolio segments

Weights can be missing, in which case R is assumed to already comprise segment returns.

Value

A list of two components

period_contributions

a data.frame

total_contributions

a numeric vector

Author(s)

Enrico Schumann

References

Feibel, Bruce (2003), Investment Performance Measurement, Wiley.

See Also

Examples

weights <- rbind(c( 0.25, 0.75),
                 c( 0.40, 0.60),
                 c( 0.25, 0.75))

R <- rbind(c( 1  ,    0),
           c( 2.5, -1.0),
           c(-2  ,  0.5))/100

rc(R, weights, segment = c("equities", "bonds"))


## contribution for btest:
##   run a portfolio 10% equities, 90% bonds
P <- as.matrix(merge(DAX, REXP, by = "row.names")[, -1])
(bt <- btest(prices = list(P),
            signal = function() c(0.1, 0.9),
            convert.weights = TRUE,
            initial.cash = 100))

W <- bt$position*P/bt$wealth
rc(returns(P)*W[-nrow(W), ])$total_contributions

PMwR

Portfolio Management with R

v0.16-0
GPL-3
Authors
Enrico Schumann [aut, cre] (<https://orcid.org/0000-0001-7601-6576>)
Initial release
2021-01-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.