Learn R Programming

PortfolioTesteR (version 0.1.4)

portfolio_returns: Portfolio returns from weights and prices (CASH-aware)

Description

Computes the portfolio simple return series by applying (lagged) portfolio weights to next-period asset returns, optionally net of proportional costs.

Usage

portfolio_returns(weights, prices, cost_bps = 0)

Value

A data.table with columns Date and ret (portfolio simple return).

Arguments

weights

A data.frame/data.table of portfolio weights on rebalance dates: first column Date, remaining columns one per symbol (numeric weights). Weights decided at \(t-1\) are applied to returns over \(t\).

prices

A data.frame/data.table of adjusted prices at the same cadence: first column Date, remaining columns one per symbol.

cost_bps

One-way proportional cost per side in basis points (e.g., 10 for 10 bps). Default 0. If > 0 and your package exposes a turnover helper, it will be used; otherwise costs are ignored with a warning.

Details

CASH support: if weights contains a column named "CASH" (case-insensitive) but prices has no matching column, a synthetic flat price series is added internally (price = 1 \(\Rightarrow\) return = 0). In that case the function does not re-normalise the non-CASH weights; the row is treated as a complete budget (symbols + CASH = 1).

The function carries forward the latest available weights to each return row via the usual one-period decision lag. Transaction cost handling is conservative: if a turnover helper is not available, costs are skipped.

See Also

PortfolioTesteR::panel_returns_simple

Examples

Run this code
# \donttest{
  data(sample_prices_weekly)
  mom12 <- PortfolioTesteR::calc_momentum(sample_prices_weekly, 12)
  sel10 <- PortfolioTesteR::filter_top_n(mom12, 10)
  w_eq  <- PortfolioTesteR::weight_equally(sel10)

  pr <- portfolio_returns(w_eq, sample_prices_weekly, cost_bps = 0)
  head(pr)
# }

Run the code above in your browser using DataLab