Skip to content
All library documents

Using Custom Expected Returns and Covariance in Mean-Variance Optimization

Article Quant Q&A · Author: HasnainMamdani

Summary

The document discusses how to perform Markowitz mean-variance portfolio optimization in R when expected returns and risk estimates are supplied by the researcher rather than computed directly from a return history. It notes that the `portfolio.optim` function accepts a covariance matrix and a target portfolio return, but its target-return argument does not appear to provide a vector of individual asset expected returns.

A proposed alternative is to formulate the quadratic program directly with `quadprog`, supplying a covariance matrix, an expected-return vector, and constraint matrices. The post also suggests passing custom inputs into `portfolio.optim`, but presents that as an unconfirmed idea rather than a demonstrated solution. It gives no worked results or comparison of implementations, and readers should verify function conventions and constraint signs against the package documentation before relying on a setup. The discussion is useful as a distinction between asset-level forecasts and a desired portfolio return.

Key ideas

  • Mean-variance optimization needs expected returns, a covariance matrix, and portfolio constraints.
  • The target return parameter in `portfolio.optim` is described as a portfolio-level target rather than an asset-return vector.
  • A quadratic programming solver can be configured with researcher-supplied inputs and constraints.
  • The post’s suggestion about supplying custom data to `portfolio.optim` is tentative and not validated.

Tags

Full text
# How to perform portfolio optimization with user-defined expected return and variances using R?


# How to perform portfolio optimization with user-defined expected return and variances using R?












I found some functions for Markowitz mean variance portfolio optimization in R such as `portfolio.optim` in `tseries` package.

However, I was not able to figure out how to use this function if I want to use my own calculated expected mean/return and variance.

Any ideas on how to achieve that with this or any other function?

And does `portfolio.optim` simply calculate the expected return as the mean of return series and expected volatility/risk as the standard-deviation of the return series? I cannot find it's detailed implementation in the documentation.

## Answer by Richi Wa (score 4)

https://quant.stackexchange.com/a/21465

You can use the package `quadprog` and define everything yourself.

Code can look like this:

```
library(quadprog)
Sigma = cov(data)
mu = mean(data)
Amat_in # define constraints here
bvec_in # define rhs of constraints here
solve.QP( Dmat = 2*Sigma, dvec = mu, meq=0,Amat=Amat_in,bvec=bvec_in)
```

EDIT: Yes, and reading the documentation we see that

```
portfolio.optim(x, pm = mean(x), riskless = FALSE,
shorts = FALSE, rf = 0.0, reslow = NULL, reshigh = NULL,
covmat = cov(x), ...)
```

the argument `covmat` can be set. As it seems the single assets' expected return can not be set as `pm` is the desired portfolio return. The documentation says that `solve.QP` is used.

## Answer by HasnainMamdani (score 0)

https://quant.stackexchange.com/a/21490

Just came up with the thought that if I supply my expected return vector instead of entire return series matrix to `portfolio.optim`, and also provide my own covariance matrix using argument covmat=.., then this might work.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.