plop: Profit & Loss operator function

View source: R/plop.R

plopR Documentation

Profit & Loss operator function

Description

Calculates portfolio returns or losses by assigning weights

Usage

plop(x, wts = NULL, approxim = c(0, 1))

Arguments

x

a numeric matrix of asset returns or losses

wts

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 wts the portfolio is equally weighted over time

approxim

controls if a first-order approximation for the calculation of returns or losses is used; default is 1 (first-order approximation is employed)

Value

Returns a list with the following elements:

pl

Weighted portfolio returns or losses

wts

Portfolio weights

Examples

# 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))


quarks documentation built on June 22, 2024, 10:03 a.m.