The concept of *efficient frontier* arises naturally when asking the *portfolio selection* question (i.e. What combination of stocks and bonds should I buy?)

The Efficient Frontier is the set of all portfolios which give a minimum risk for a given expected return (ergo, you should always seek to invest in the Efficient Frontier).

The derivation of the Efficient Frontier equation was first published in…. by…

I haven’t found many resources explaining the subject in-depth, beyond the original paper; so here is a derivation of the Efficient Frontier equation, modernized to soothe your vector-notation cravings.

### Prerequisite: Lagrange multipliers

We often find the problem of *constrained optimization*, which can be stated as:

Subject to

Lagrange multipliers reduce this problem to an *unconstrained optimization* problem. The previous problem is reduced to:

(* A generalization of Lagrange multipliers is given by KKT conditions, in which constraints can be a mix of equalities and inequalities. We will revisit these when we analyze de case of portfolio selection when you can’t hold short positions.)

### Derivation

#### Statement of the problem

We have the option to invest in several assets. Our *portfolio* is vector , the ratios of our total capital that we invest in each asset. Since they are ratios and we are supposed to invest all our money, they add up to 1:

The *return* of an asset on a given time interval is a *random variable*. As there are usually many assets in which we could invest, we are dealing with a vector of random variables . The return of our portfolio will also be a random variable, given by:

The *expected return* of an asset, on the other hand, is just a number. Therefore, for a vector of expected returns , the *expected return* of our portfolio will be:

The risk of a single asset is statistically described by its *variance* . But since we are dealing with a *vector* of assets, the quantity of interest is its *covariance matrix* . By the definition of covariance, C will be a *symmetric matrix*. The risk of our portfolio will be:

We want to minimize this risk (or minimize half this risk, which is the same), for a given expected return . We are now ready to formalize our problem:

Subject to:

#### Solution

By Lagrange multipliers, an equivalent formulation of the above problem is

Taking the derivative of this expression with respect to will yield an equation system that determines the solution of the problem. We get:

To simplify define this, let’s define:

With this definitions, the above equations turn into :

Solving these equations yields:

where

Note that we finally got our *risk minimizing portfolios* , as a function of portfolio return . By the definition of in the previous section, the risk of such portfolios is:

Note that this gives us the minimum possible risk for a given return , and it turns out to be a quadratic function.

#### With Risk-Free Asset

Besides investing in risky assets (stocks), we can also invest in a risk-free asset (bonds). This particular case is usually given a separate treatment. Instead, we will just say that for this particular case, matrix becomes singular, and we shall therefore replace inverses by pseudo-inverses when apropiate in the equations above. That’s all.

### No short-position

#### Statement

It may happen that we are not allowed to hold short-positions in some assets. That means all components of should be positive. The resulting problem is:

Subject to:

#### Solution

### Implementation

for I in range(10)