Learn R Programming

RSDC (version 1.1-2)

rsdc_maxdiv: Maximum-Diversification Portfolio (Rolling Weights)

Description

Computes rolling maximum-diversification (MaxDiv) portfolio weights from a sequence of per-period covariance matrices implied by forecasted volatilities and correlations. Falls back to equal weights if the nonlinear solver fails.

Usage

rsdc_maxdiv(sigma_matrix, value_cols, predicted_corr, y, long_only = TRUE)

Value

weights

\(T \times K\) matrix of weights.

returns

Vector of realized portfolio returns sum(y[t,] * weights[t,]).

diversification_ratios

Vector of realized diversification ratios.

mean_diversification

Average diversification ratio.

K

Number of assets.

assets

Asset names.

volatility

Standard deviation of realized portfolio returns.

Arguments

sigma_matrix

Numeric matrix \(T \times K\) of forecasted standard deviations.

value_cols

Character/integer vector naming columns in sigma_matrix (asset order).

predicted_corr

Numeric matrix \(T \times \binom{K}{2}\) of pairwise correlations in combn(K, 2) column order.

y

Numeric matrix \(T \times K\) of asset returns (for realized stats).

long_only

Logical. If TRUE, impose \(w \ge 0\) and \(\sum_i w_i = 1\); otherwise bounds are \(-1 \le w_i \le 1\) with \(\sum_i w_i = 1\).

Details

  • Covariance build: For each \(t\), reconstruct \(R_t\) from the pairwise vector; set \(D_t=\mathrm{diag}(\sigma_{t,1},\dots,\sigma_{t,K})\) and \(\Sigma_t = D_t R_t D_t\).

  • Objective (MaxDiv): maximize \(\mathrm{DR}(w) = \frac{\sum_i w_i \sigma_{t,i}}{\sqrt{w^\top \Sigma_t w}}\) subject to \(\sum_i w_i = 1\) and bounds on \(w\). Implemented by minimizing the negative ratio.

  • Solver: Rsolnp::solnp with equality \(\sum_i w_i = 1\) and bounds by long_only; on error, weights default to \(1/K\).

See Also

rsdc_minvar, solnp

Examples

Run this code
# Toy example with K = 3
if (requireNamespace("Rsolnp", quietly = TRUE)) {
  T <- 50; K <- 3
  set.seed(42)
  vols <- matrix(0.2 + 0.05*abs(sin(seq_len(T)/7)), T, K)
  colnames(vols) <- paste0("A", 1:K)
  # simple, stationary correlations (order: (2,1), (3,1), (3,2))
  pred_corr <- cbind(rep(0.20, T), rep(0.10, T), rep(0.05, T))
  rets <- matrix(rnorm(T*K, sd = 0.01), T, K); colnames(rets) <- colnames(vols)

  mx <- rsdc_maxdiv(sigma_matrix   = vols,
                    value_cols     = colnames(vols),
                    predicted_corr = pred_corr,
                    y              = rets,
                    long_only      = TRUE)
  head(mx$weights)
  mx$mean_diversification
}

Run the code above in your browser using DataLab