Mean Variance Portfolio optimization

Business approach

When one decides to invest, they are attempting to reap a return on their capital that adequately compensates for the risk undertaken. The world of investment can be thought of as a vast marketplace filled with diverse financial assets like stocks and bonds. Each of these assets has its own potential return and inherent level of risk. Assets promising higher returns normally entail greater risks.

Investors’ goal is to determine the combination of assets and allocation of capital that provides the
highest potential return but bear the least possible risk.

To do so, investors normally use algorithmic strategies, being the mean portfolio optimization, also referred to as Markowitz portfolio optimization [1], the one most commonly used.

The “mean” acts like the average price tag on the items in the investor’s basket. It provides an estimate of what they can expect as a return on their investment. This is calculated by looking at the potential returns of each item and considering the proportion of that item in the basket. The “variance” acts like a measure of unpredictability surrounding these price tags. It provides an insight into how much the actual returns could deviate from the expected returns. It considers not just the uncertainty around each item’s return, but also the interrelation of the returns of different items. “Optimization” is about selecting the best combination of items to maximize the expected return for a given level of risk or to minimize the risk for a given level of expected return.

Essentially, investors are trying to find a perfect balance: They aim to maximize their expected returns, but only to a degree of risk that they find acceptable. Alternatively, they seek to minimize their risk while still achieving a specified level of expected returns.

Current limitations

Increasing the number of assets or adding additional business constraints [2], such as setting a maximum / min percentage budget allocation per asset, make the problem harder to compute and unsolvable by state-of-the-art hardware and software.


Being able to optimize larger portfolios with more constraints could become a competitive advantage.

The field of quantum computing is currently being harnessed to tackle a broad range of optimization issues, including the mean variance portfolio optimization. The complexity and time-consuming nature of portfolio optimization in conventional methods make it an ideal candidate for quantum computing.

Input data

The basic input data for the problem of mean variance portfolio optimization is:

  • A set of possible assets / tickers candidates to be part of the portfolio (i.e. a list of selected stock by a trader)
  • The expected return of each asset in the the investment period
  • The ”volatility” or risk of each asset σ
  • The correlation or dependency of the outcome of one asset in respect to another. Represented as the covariance matrix.

Additionally, the problem can take different flavors depending on the objective function (i.e. maximize
sharpe-ratio, maximize portfolio’s return, minimize risk…) as well as the business constraints.

Output Data and representation

The output data includes:

  • Portfolio’s expected return
  • Portfolio’s variance (or risk)
  • A list with all the assets selected for the portfolio, their relative weights in the portfolio and the amount to be invested in each asset.
  • Information of the feasibility of the problem, that is, if some constraints have been violated an by how much
  • The amount of time it took to get to a solution (TTS)

The results of a single portfolio optimization execution are normally represented in a table and a pie
The results of a set of portfolio optimization executions are normally represented by points in a two
axis graph where the x-axis represents the resulting Portfolio’s variance and the y-axis represents the
portfolio’s expected return.

Example of a portfolio optimization representation

Mathematical definition of the problem

The mean variance portfolio optimization problem for N assets can be formulated as follows. We represent by μi the expected return of asset i. Also, σij ≡ Cov(i, j) represents the covariance between the returns for assets i and j while R represents the target return. The decision variables are the weights wi for each asset. Assuming knowledge of the covariance matrix Cov(i, j), the problem to be solved is a linearly constrained quadratic optimization which reads

Here, S denotes the set that the weights take values on, for example R in the simplest case or some subset of Z in the complex case. The latter, can make Prob. (1) intractable (see below). Further constraints can be imposed to the problem. As an example, one can consider a cardinality constraint and a quantity constraint.

  • The cardinality constraint restricts the number of the N assets within the portfolio to be M. This is done by introducing a binary variable zi, for asset i, to denote whether an asset is selected or not, that is
  • The quantity constraint specifies the lower and upper bounds for each asset allocation. Essentially it gives a range for each weight within the set S, that is

where ε, δ are the lower and upper bounds.

Classical Approaches

Some popular approaches for solving mean-variance portfolio optimization classically include the linear complementarity (LCP) algorithm or interior-point methods for quadratic programming problems. Other approaches include the branch-and-bound method, particle swarms, genetic algorithms, and simulated annealing.

Current challenges and opportunities

Solving mean variance portfolio optimization can be a highly-complex task due to fluctuating asset inter-dependencies (correlations), and more often than not it requires advanced models and tools. Specifically, if the covariance matrix is positive definite and weights are assumed to be real numbers the problem can be solved efficiently using classical solvers. However, if the covariance matrix is not positive definite or if the weights are to be discrete the problem is significantly hard to solve at large instances and it has been shown to be a very hard problem. Additionally, real-world business constraints often significantly increase the complexity of the problem which often results in a highly non-convex problem. For example, the inclusion of a cardinality constraint turns the problem into a mixed integer nonlinear programming which is NP-Hard.

JSON schema definition

The inputs of the problem are specfied on the JSON file. Concretely it is
worth noting:

  • yields corresponds to the numbers representing the expected returns of the assets.
  • covariances corresponds to the covariance between the returns of two assets.
  • tickers are the unique identifiers for the assets.
  • budget corresponds to the total investment budget available.
  • prices corresponds to the price of each asset.
  • risk_acceptance_level corresponds to the level of risk the user is willing to accept (optional).
  • adjusted_solution gives the option to adjust the solution based on some specific criteria (optional).
  • show_time indicating whether or not to display the time taken to compute the solution (optional).
  • max_number_of_assets (optional) corresponds to the maximum number of different assets that can be included in the portfolio.
  • max_weight_per_asset (optional) indicates the maximum proportion of the budget that can be invested in any single asset.
  • solvers indicates the different methods or algorithms that can be used to solve the optimization problem.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.