# 4  Optimal Portfolios: Practice

The optimal portfolios studied in Chapter 2 and Chapter 3 assumed away a number of frictions that are important in practice. Most investors cannot borrow at the same rate at which they save. Some investors cannot sell securities short or may also have other position limits such as maximum portfolio weights. We show how the analyses in the preceding chapters change when we impose more realistic assumptions on the investing environment.

## 4.1 Different Borrowing & Lending Rates

### Kinked CALs

The capital allocation line is the set of expected returns and standard deviations formed by combining a single risky asset (or portfolio) with weight $$w$$ and a risk-free asset with weight $$1-w$$. In Chapter 3, we assumed a single risk-free rate. Any portfolios with $$w>100\%$$ involve borrowing at the risk-free rate (that is, issuing bonds at the same rate as, say, US Treasuries). This is probably not a reasonable assumption. For most investors, $$r^{\text{borrow}}>r^{\text{saving}}$$. In this case, the capital allocation line is kinked at the risky-asset. For portfolios with some risk-free saving, the capital allocation line is the same as in Equation 3.3:

$E[r_p] = r_f^{\text{saving}} + \bigg[ \frac{E[r_{\text{risky}}]-r_f^{\text{saving}}}{\text{sd}[r_{\text{risky}}] }\bigg]\cdot \text{sd}[r_p]\,.$

For portfolios with borrowing, the capital allocation line has a lower slope: $E[r_p] = r_f^{\text{borrow}} + \bigg[ \frac{E[r_{\text{risky}}]-r_f^{\text{borrow}}}{\text{sd}[r_{\text{risky}}] }\bigg]\cdot \text{sd}[r_p]\,.$ Figure 4.1 shows the set of possible portfolios along the kinked capital allocation line with differential savings and borrowing rates. The black dotted lines extend the blue solid lines, but the points on the black dotted lines are infeasible, because they involve saving at the borrowing rate or borrowing at the savings rate.

### Optimal Portfolios

Under the more realistic assumption that $$r_f^{\text{borrow}}>r_f^{\text{saving}}$$, efficient portfolios fall into three regions, separated by blue dots in Figure 4.2.1 These blue dots indicate an efficient low risk portfolio and an efficient high mean portfolio, both comprised solely of risky assets. The efficient low risk portfolio is the tangency portfolio calculated using the savings rate, and the efficient high mean portfolio is the portfolio maximizing the Sharpe ratio with respect to the borrowing rate.

To the left of the efficient low risk portfolio, the efficient portfolios are scaled-down versions of the efficient low risk portfolio with some savings. To the right of the efficient high mean portfolio, the efficient portfolios are scaled-up versions of the efficient high mean portfolio with some borrowing. Both cases are shown as blue lines in the figure. The third region is the portion of the efficient frontier between the efficient low risk and efficient high mean portfolios. These portfolios do not involve saving or borrowing. Investors with different preferences will choose to invest in different locations across these three regions, as discussed in the next section.

### Optimal Capital Allocation

Where do investors with different risk aversions choose to invest when faced with this investment opportunity set? The answer depends on the investor’s risk aversion and the Sharpe ratios of the efficient low risk and high mean portfolios. First, consider investors risk aversion greater than the Sharpe ratio of the efficient low risk portfolio, calculated with respect to the savings rate.2 These high risk aversion investors invest a fraction $$w^*$$ of their wealth in the efficient low risk portfolio and the remainder is saved as the savings rate. The optimal fraction of wealth in the efficient low risk portfolio as a function of risk aversion is: $w^*_{\text{low}} = \frac{E[r_{\text{low}}-r_f^{\text{saving}}]}{A \cdot \text{var}_{\text{low}}}.$

Second, consider investors with risk aversion less than the Sharpe ratio of the efficient high mean portfolio, calculated with respect to the borrowing rate.3 These low risk aversion investors borrow money and hold a levered position in the efficient high mean portfolio. The optimal weight in the efficient high mean portfolio is: $w^*_{\text{high}} = \frac{E[r_{\text{high}}-r_f^{\text{borrow}}]}{A \cdot \text{var}_{\text{high}}}.$

The third group of investors are those with intermediate risk aversion (i.e., risk aversion falling between the savings rate efficient low risk Sharpe ratio and the borrowing rate efficient high mean Sharpe ratio). These investors hold a portfolio that is a combination of the efficient low risk and high mean portfolios. They do not borrow or save. The optimal weight in the low-risk portfolio is: $a^* = \frac{E[r_{\text{low}} - r_{\text{high}}] - A (\text{cov}[r_{\text{low}}, r_{\text{high}}]-\text{var}[r_{\text{high}}])}{A (\text{var}[r_{\text{low}}]+\text{var}[r_{\text{high}}]-2\text{cov}[r_{\text{low}}, r_{\text{high}}])}\,, \tag{4.1}$ and $$1-a^*$$ is the efficient high mean portfolio weight.4

For intermediate risk aversion levels, the optimal weight in the efficient low-risk portfolio solves $\underset{a}\max E[a\cdot r_{\text{low}} + (1-a)\cdot r_{\text{high}}] - 0.5\cdot A \cdot \text{var}[a\cdot r_{\text{low}} + (1-a)\cdot r_{\text{high}}]\,.$ Equation 4.1 is found by taking the derivative of the mean-variance utility with respect to $$a$$ and solving the first-order condition for $$a$$.

Figure 4.3 shows indifference curves at the highest possible utility level for investors with the indicated risk aversions. The portfolio where each indifference curve intersects the efficient frontier is that investor’s optimal portfolio.

Figure 4.4 plots the allocation to risky assets as a function of risk aversion. Investors with very low levels of risk aversion will hold levered portfolios in the efficient high mean portfolio, and investors with very high levels of risk aversion will hold save some capital at the risk-free rate and the remainder in the efficient low risk portfolio. Investors with intermediate risk aversion will invest 100% of their capital in risky assets, but at different locations along the risky-asset efficient frontier (see hover data in Figure 4.4). These portfolios can be written as a combination of the efficient low risk portfolio and the efficient high mean portfolio (Equation 4.1). A larger fraction is invested in the efficient high mean portfolio with lower risk aversion.

## 4.2 Short-Sales Constraints

### Short-Sales and Hedging

In Chapter 2, we assumed that short-selling is allowed. Short-selling of some assets may sometimes improve mean-variance efficiency. In particular, short-selling a security that is positively correlated with another holding can hedge price movements in the long asset position.

Figure 4.5 shows how the GMV portfolio and frontier changes if short-sales are not allowed for any of the three equity portfolios. Notice that the global minimum variance portfolio with short-selling involves shorting emerging market equity and invests the proceeds and initial capital in a combination of US and developed international equities. Without this possibility, the GMV portfolio without short-sales has a higher standard deviation (and invests nothing in the emerging market portfolio).

The frontier with short-selling coincides with the frontier without short-selling for many expected return values, but shorting allows an investor to reach expected returns values below the minimum expected returns of the assets (the US equity portfolio) and above the maximum expected return of the underlying assets (the emerging market portfolio). These portfolios entail shorting the emerging market fund or the US equity fund, respectively.

Within the set of expected returns possible without shorting, lower risk portfolios are possible with shorting for expected returns close to the US market fund’s expected return and close to the emerging market fund’s expected return. For the former case, the emerging market fund is shorted and serves as a hedge against long positions in the other two funds. For the latter case, the US equity fund serves as a hedge.

The improvement in mean-variance efficiency is sometimes more dramatic than the example above. For instance, Figure 4.6 shows the frontiers for portfolios of 48 industries when shorts sales are or are not allowed. In this case, allowing short sales shifts the frontier leftward for the full range of expected returns obtainable with long-only portfolios of industries.

### GMV and Frontier Portfolios

Short-sale constraints are an set of additional constraints to the optimization problems for the GMV portfolio and frontier portfolios considered in Equation 2.12 and Equation 3.3.

With short-sale constraints, the GMV portfolio is the set of non-negative portfolio weights that minimizes portfolio variance: $\underset{w_1,w_2,\dots,w_N}{\text{min}} \text{var}[r_p]$ subject to the constraints $$\sum_i w_i=1$$ and $$w_i \ge 0$$ for all assets $$i$$.

Minimizing variance is a quadratic programming problem that can be solved numerically using constrained optimization in Python using the CVXOPT package. The CVXOPT user guide is available here .

The function cvxopt.solvers.qp solves problems of the general form: \begin{align} \underset{w}{\text{min }}& \frac{1}{2} w' Q w + p'x \\ \text{subject to } & Gw \le h \\ & Aw = b \\ \end{align}

The optimizer is solving for a $$N \times 1$$ vector of portfolio weights, $$w$$ that minimizes the objective function. To minimize variance, we set $$Q$$ equal to the $$N \times N$$ covariance matrix of returns and $$p$$ equal to a $$N \times 1$$ vector of zeros.

The constraint $$Gw \le h$$ is used to put position limits on the portfolio weights. Short-selling constraints are the most common such constraint. These are accomplished by setting $$G$$ equal to the negative of the $$N \times N$$ identity matrix (that is, a matrix with -1s on the diagonal and zero elsewhere), and $$h$$ equal to a $$N \times 1$$ vector of zeros. Additional position limits could be enforced by adding rows to $$G$$ and $$h$$. For instance, many funds have maximum position limits in addition to short-sale constraints.

The constraint $$Aw=b$$ usually includes the constraint that the portfolio is fulling invested; that is, the portfolio weights sum to 100%. This is accomplished by setting $$A$$ equal to a $$N \times 1$$ vector of ones and setting $$b=1$$. $$A$$ and $$b$$ can include additional rows for other constraints. For instance, setting a target expected return is accomplished by adding a row to $$A$$ with the asset mean vector and adding a row to $$b$$ with the target expected return. This is done when solving for a particular point on the mean-variance frontier.

import numpy as np
from cvxopt import matrix
from cvxopt.solvers import qp as Solver, options as SolverOptions

##### Inputs
# Risk-free rate
r = 0.02
# Expected returns
mns = np.array([0.06, 0.065, 0.08])
# Standard deviations
sds = np.array([0.15, 0.165, 0.21])
# Correlations
corr12 = 0.75
corr13 = 0.75
corr23 = 0.75
# Covariance matrix
C  = np.identity(3)
C[0, 1] = C[1, 0] = corr12
C[0, 2] = C[2, 0] = corr13
C[1, 2] = C[2, 1] = corr23
cov = np.diag(sds) @ C @ np.diag(sds)

##### GMV problem with short-sale constraints
n = len(mns)
Q = matrix(cov, tc="d")
p = matrix(np.zeros(n), (n, 1), tc="d")
# Constraint: short-sales not allowed
G = matrix(-np.identity(n), tc="d")
h = matrix(np.zeros(n), (n, 1), tc="d")
# Constraint: fully-invested portfolio
A = matrix(np.ones(n), (1, n), tc="d")
b = matrix([1], (1, 1), tc="d")
sol = Solver(Q, p, G, h, A, b)
wgts_gmv = np.array(sol["x"]).flatten() if sol["status"] == "optimal" else np.array(n * [np.nan])

Note that the GMV without short-sale constraints can be found using numerical optimization by removing the short-sale constraint:

G = matrix(np.zeros((n,n)), tc="d")

Similarly, a frontier portfolio with expected return $$\mu_{\text{target}}$$ is defined by the non-negative portfolio weights that solve the following constrained optimization problem: $\underset{w_1,w_2,\dots,w_N}{\text{min}} \text{var}[r_p]$ subject to constraints: $$\sum_i w_i E[r_i]=E[r_{\text{target}}]$$, $$\sum_i w_i=1$$ and $$w_i \ge 0$$ for all assets $$i$$.

Relative to the GMV problem, the frontier problem contains an additional constraint of the form $$Aw=b$$ in addition to the usual constraint that the portfolio is fulling invested. Setting a target expected return is accomplished by adding a row to $$A$$ with the asset mean vector and adding a row to $$b$$ with the target expected return.

import numpy as np
from cvxopt import matrix
from cvxopt.solvers import qp as Solver, options as SolverOptions

##### Inputs
# Risk-free rate
r = 0.02
# Expected returns
mns = np.array([0.06, 0.065, 0.08])
# Standard deviations
sds = np.array([0.15, 0.165, 0.21])
# Correlations
corr12 = 0.75
corr13 = 0.75
corr23 = 0.75
# Covariance matrix
C  = np.identity(3)
C[0, 1] = C[1, 0] = corr12
C[0, 2] = C[2, 0] = corr13
C[1, 2] = C[2, 1] = corr23
cov = np.diag(sds) @ C @ np.diag(sds)

##### Frontier problem with short-sale constraints
def frontier(means, cov, target):
n = len(means)
Q = matrix(cov, tc="d")
p = matrix(np.zeros(n), (n, 1), tc="d")
# Constraint: short-sales not allowed
G = matrix(-np.identity(n), tc="d")
h = matrix(np.zeros(n), (n, 1), tc="d")
# Fully-invested constraint
A = matrix(np.vstack((np.ones(n), means)), (2, n), tc="d")
b = matrix([1, target], (2, 1), tc="d")
sol = Solver(Q, p, G, h, A, b)
wgts = np.array(sol["x"]).flatten() if sol["status"] == "optimal" else np.array(n * [np.nan])
return wgts
wgts_frontier = [frontier(mns, cov, m) for m in np.linspace(mns.min(), mns.max(),5)]

Note that the frontier portfolios without short-sale constraints can be found using numerical optimization by removing the short-sale constraint:

G = matrix(np.zeros((n,n)), tc="d")

### Tangency Portfolio

For a single risk-free rate, the tangency portfolio with short-sale constraints is the set of non-negative portfolio weights that maximizes the Sharpe ratio: $\underset{w_1,w_2,\dots,w_N}{\text{max}} \frac{E[r_p] - r_f}{\text{sd}[r_p]}$ subject to the constraints $$\sum_i w_i=1$$ and $$w_i \ge 0$$ for all assets $$i$$.

The optimizer is solving for a $$N \times 1$$ vector of portfolio weights, $$w$$ that minimizes the objective function. The minimize package in scipy.optimize solves multivariate constrained optimization problems. Short-sale constraints are passed to the optimizer as a list of lower and/or upper limits on each portfolio weight.

import numpy as np
from scipy.optimize import minimize

##### Inputs
# Risk-free rate
r = 0.02
# Expected returns
mns = np.array([0.10, 0.05, 0.07])
# Standard deviations
sds = np.array([0.20, 0.12, 0.15])
# Correlations
corr12 = 0.3
corr13 = 0.3
corr23 = 0.3
# Covariance matrix
C  = np.identity(3)
C[0, 1] = C[1, 0] = corr12
C[0, 2] = C[2, 0] = corr13
C[1, 2] = C[2, 1] = corr23
cov = np.diag(sds) @ C @ np.diag(sds)

##### Tangency Portfolio
n = len(mns)
def f(w):
mn = w @ mns
sd = np.sqrt(w @ cov @ w)
return -(mn - r) / sd
# Initial guess (equal-weighted)
w0 = (1/n)*np.ones(n)
# Constraint: fully-invested portfolio
A = np.ones(n)
b = 1
cons = [{"type": "eq", "fun": lambda x: A @ x - b}]
# Short-sale constraint
bnds = [(0, None) for i in range(n)]
# Optimization
wgts_tangency = minimize(f, w0, bounds=bnds, constraints=cons).x

Note that the tangency portfolio without short-sale constraints can be found using numerical optimization by removing the short-sale constraint:

bnds = [(None, None) for i in range(n)] 

1. This is true if the interest rates are lower than expected returns. If interest rates are set higher than expected returns, then the efficient portfolios may not exist.↩︎

2. That is, $$A>\frac{E[r_{\text{low}}-r_f^{\text{saving}}]}{\text{var}_{\text{low}}}$$.↩︎

3. That is, $$A<\frac{E[r_{\text{high}}-r_f^{\text{borrow}}]}{\text{var}_{\text{high}}}$$.↩︎

4. The covariance between the efficient low risk and high mean portfolios ($$\text{cov}[r_{\text{low}}, r_{\text{high}}]$$) can be calculated as $$w_{\text{low}}' V w_{\text{high}}$$, where $$w_{\text{low}}$$ and $$w_{\text{high}}$$ are the weights in the underlying risky assets for the efficient low-risk and high-mean portfolios, respectively.↩︎