mvFrontier {NMOF} | R 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
is specified, the function ignores the
min.return
constraint and instead solves the model
in which are the weights. If
is a vector of length 2, then the model becomes
which may be more convenient
(e.g. for setting 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 |
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. 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")