Calculates portfolio returns or losses by assigning weights
plop(x, wts = NULL, approxim = c(0, 1))
a numeric matrix of asset returns or losses
a numeric vector or matrix containing the portfolio
weights; portfolio value is standardized to 1 on any observation unit;
sum of weights should not exceed 1 (row-wise for matrices); by default
the portfolio is equally weighted over time and across all assets; if a
vector is passed to
controls if a first-order approximation for the calculation
of returns or losses is used; default is
Returns a list with the following elements:
Weighted portfolio returns or losses
# creating portfolio portfol <- cbind(SP500$price.close, DJI$price.close) returns <- apply(portfol, 2, function(x) diff(log(x))) # defining weights and applying the P&L operator function wts <- c(0.4, 0.6) portret <- plop(returns, wts = wts, approxim = 1) portloss <- plop(-returns, wts = wts, approxim = 1) plot.ts(cbind(portret$pl, portloss$pl))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.