mvFrontier: Computing Mean-Variance Efficient Portfolios

View source: R/portfolio.R

mvFrontierR Documentation

Computing Mean–Variance Efficient Portfolios

Description

Compute mean–variance efficient portfolios and efficient frontiers.

Usage

mvFrontier(m, var, wmin = 0, wmax = 1, n = 50, rf = NA,
           groups = NULL, groups.wmin = NULL, groups.wmax = NULL)
mvPortfolio(m, var, min.return, wmin = 0, wmax = 1, lambda = NULL,
            groups = NULL, groups.wmin = NULL, groups.wmax = NULL)

Arguments

m

vector of expected returns

var

expected variance–covariance matrix

wmin

numeric: minimum weights

wmax

numeric: maximum weights

n

number of points on the efficient frontier

min.return

minimal required return

rf

risk-free rate

lambda

risk–reward trade-off

groups

a list of group definitions

groups.wmin

a numeric vector

groups.wmax

a numeric vector

Details

mvPortfolio computes a single mean–variance efficient portfolio, using package quadprog. It does so by minimising portfolio variance, subject to constraints on minimum return and budget (weights need to sum to one), and min/max constraints on the weights.

If \lambda is specified, the function ignores the min.return constraint and instead solves the model

\min_w\ \ -\lambda \mbox{\code{m}}'w + (1-\lambda) w'\mbox{\code{var}\,}w

in which w are the weights. If \lambda is a vector of length 2, then the model becomes

\min_w\ \ -\lambda_1 \mbox{\code{m}\,}'w + \lambda_2 w'\mbox{\code{var}\,}w

which may be more convenient (e.g. for setting \lambda_1 to 1).

mvFrontier computes returns, volatilities and compositions for portfolios along an efficient frontier. If rf is not NA, cash is included as an asset.

Value

For mvPortfolio, a numeric vector of weights.

For mvFrontier, a list of three components:

return

returns of portfolios

volatility

volatilities of portfolios

weights

A matrix of portfolio weights. Each column holds the weights for one portfolio on the frontier. If rf is specified, an additional row is added, providing the cash weight.

The i-th portfolio on the frontier corresponds to the i-th elements of return and volatility, and the i-th column of portfolio.

Author(s)

Enrico Schumann

References

Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/C2017-0-01621-X")}

Schumann, E. (2023) Financial Optimisation with R (NMOF Manual). http://enricoschumann.net/NMOF.htm#NMOFmanual

See Also

minvar for computing the minimum-variance portfolio

Examples

na <- 4
vols <- c(0.10, 0.15, 0.20,0.22)
m <- c(0.06, 0.12, 0.09, 0.07)
const_cor <- function(rho, na) {
    C <- array(rho, dim = c(na, na))
    diag(C) <- 1
    C
}
var <- diag(vols) %*% const_cor(0.5, na) %*% diag(vols)

wmax <- 1          # maximum holding size
wmin <- 0.0          # minimum holding size
rf <- 0.02

if (requireNamespace("quadprog")) {
  p1 <- mvFrontier(m, var, wmin = wmin, wmax = wmax, n = 50)
  p2 <- mvFrontier(m, var, wmin = wmin, wmax = wmax, n = 50, rf = rf)
  plot(p1$volatility, p1$return, pch = 19, cex = 0.5, type = "o",
       xlab = "Expected volatility",
       ylab = "Expected return")
  lines(p2$volatility, p2$return, col = grey(0.5))
  abline(v = 0, h = rf)
} else
  message("Package 'quadprog' is required")

enricoschumann/NMOF documentation built on April 13, 2024, 12:16 p.m.