Learn R Programming

RSDC (version 1.1-2)

rsdc_minvar: Minimum-Variance Portfolio (Rolling Weights)

Description

Computes rolling minimum-variance (MV) portfolio weights from a sequence of per-period covariance matrices implied by forecasted volatilities and pairwise correlations. Supports long-only or unconstrained MV. If the QP solver fails at a time step, the routine falls back to equal weights.

Usage

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

Value

An object of class "minvar_portfolio":

weights

\(T \times K\) matrix of MV weights (one row per time).

cov_matrices

List of length \(T\) with the per-period \(K \times K\) covariance matrices.

volatility

Realized standard deviation of portfolio returns (see Note on units).

y

The input y matrix (coerced to \(T \times K\)).

K

Number of assets.

Arguments

sigma_matrix

Numeric matrix \(T \times K\) of forecasted volatilities (standard deviations), one column per asset.

value_cols

Character or integer vector giving the columns in sigma_matrix to use as assets (order defines the asset order).

predicted_corr

Numeric matrix \(T \times P\) of pairwise correlations, where \(P = \binom{K}{2}\) and the columns correspond to combn(K, 2) order.

y

Numeric matrix \(T \times K\) of asset returns aligned with sigma_matrix. Used only to compute the realized portfolio volatility.

long_only

Logical. If TRUE (default), imposes long-only MV with the full-investment constraint \(\sum_i w_i = 1\) and \(w_i \ge 0\). If FALSE, solves unconstrained MV with only \(\sum_i w_i = 1\).

Note on units

The realized portfolio return at time \(t\) is computed as sum(y[t, ] * weights[t, ]) / 100. This assumes y is expressed in \ remove the / 100 in the implementation or convert inputs accordingly.

Details

  • Covariance build: For each \(t\), a correlation matrix \(R_t\) is reconstructed ... Let \(D_t = \mathrm{diag}(\sigma_{t,1},\dots,\sigma_{t,K})\) and \(\Sigma_t = D_t R_t D_t\).

  • Optimization: Minimize \(\tfrac{1}{2} w^\top \Sigma_t w\) subject to \(\mathbf{1}^\top w = 1\) and, if long_only, \(w \ge 0\) (solved with quadprog::solve.QP).

  • Failure handling: If the QP fails at time \(t\), weights default to equal allocation \(w_i = 1/K\).

See Also

rsdc_maxdiv (maximum diversification), solve.QP

Examples

Run this code
# Toy example with K = 3
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
pred_corr <- cbind(rep(0.20, T), rep(0.10, T), rep(0.05, T))  # order: (2,1), (3,1), (3,2)
rets <- matrix(rnorm(T*K, sd = 0.01), T, K); colnames(rets) <- colnames(vols)

mv <- rsdc_minvar(sigma_matrix  = vols,
                  value_cols    = colnames(vols),
                  predicted_corr= pred_corr,
                  y             = rets,
                  long_only     = TRUE)
head(mv$weights)
mv$volatility

Run the code above in your browser using DataLab