Note from Towards Data Science’s editors:_ While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details._

_Not intended to be investment advice. _You can find my code on my GitHub here.

As fun as it is to optimize a portfolio with just matrix algebra and NumPy, sometimes we need to add constraints. For example, many investors don’t want to or are not allowed to short investments. We can’t guarantee that the optimal portfolio produced using matrix algebra won’t include short positions (negative weights). So instead, we turn to optimization.

In case you didn’t read my previous articles on optimization, optimization refers to the process of solving for the combination of assets that maximizes return for a given amount of risk (or minimizes risk for a specified level of return). The desired output from an optimization is a set of portfolio weights (for each asset) that would produce the optimal portfolio.

Running A Portfolio Optimization

The two key inputs to a portfolio optimization are:

  1. Expected returns for each asset being considered.
  2. The covariance matrix of asset returns. Embedded in this are information on cross-asset correlations and each asset’s volatility (the diagonals).

Expected returns are hard to estimate — some people like to use historical averages (dangerous as the past is often not representative of the future), others have their own methodology for estimating return forecasts. I am planning a whole post on this so I won’t go into the details this time. Today we will focus on the optimization process itself. Thus, we will pretend like we got expected return estimates from a consultant. By the way, these were very roughly estimated by me, so they should definitely not be taken as investment advice.

Image for post

#investing #programming #finance #machine-learning #data-science

Portfolio Optimization With SciPy
9.55 GEEK