Path: blob/main/notebooks/05/03-markowitz-portfolio.ipynb
663 views
5.3 Markowitz portfolio optimization
Preamble: Install Pyomo and a solver
This cell selects and verifies a global SOLVER for the notebook. If run on Google Colab, the cell installs Pyomo and ipopt, then sets SOLVER to use the ipopt solver. If run elsewhere, it assumes Pyomo and the Mosek solver have been previously installed and sets SOLVER to use the Mosek solver via the Pyomo SolverFactory. In both cases it then verifies that SOLVER is available.
Problem description and model formulation
A canonical stochastic optimization problem is the so-called portfolio selection problem, also known as Markowitz portfolio optimization. Assume that an investor has an initial capital that she wants to invest in possible risky assets, each of them with an unknown return rate , , or in another risk-free asset with a guaranteed return rate . Let be the vector whose -th component describes the amount invested in asset and the amount invested in the risk-free asset. We consider a stochastic model in which the return of the risky assets is then a random vector with known expected values and covariance
The investment return then becomes also a random variable with mean
and variance
The variance of the investment return is a possible way to quantify the risk of the investment .
The investor needs to select a portfolio that achieves a good compromise between risk and expected return. One could try to maximize the expected return subject to an upper bound on the tolerable risk, obtaining the following optimization problem:
The first constraint describes the fact that the total amount invested must be equal to the initial capital. The second constraint ensures that the variance of the chosen portfolio is upper bounded by a parameter , which captures the risk the investor is willing to take. The last non-negativity constraint excludes the possibility of short-selling.
One can easily show that the quadratic constraint is convex in due to the fact that is positive semi-definite, being a covariance matrix. Therefore, the optimization problem is convex. Let us implement it in Pyomo and solve it.
We now calculate the optimal investment strategy for a portfolio with assets, with expected returns and a predefined covariance matrix. We set the risk parameter to and the risk-free return rate to .
The next plot shows how the objective function changes as the risk threshold parameter varies.