Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mvFrontier

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 \code{lambda} is specified, the function ignores the min.return constraint and instead solves the model

min -lambda m'w - (1 - lambda) w'var w

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

min -lambda_1 m'w - lambda_2 w'var w

which may be more convenient (e.g. for setting \code{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. https://www.elsevier.com/books/numerical-methods-and-optimization-in-finance/gilli/978-0-12-815065-8

Schumann, E. (2019) 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

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)

NMOF

Numerical Methods and Optimization in Finance

v2.4-1
GPL-3
Authors
Enrico Schumann [aut, cre] (<https://orcid.org/0000-0001-7601-6576>)
Initial release
2021-04-09

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.