``````

In [2]:

import numpy as np

``````
``````

In [3]:

muvec = np.matrix([[.06],[.02],[.04]])
Onevec = np.matrix([[1],[1],[1]])
V = np.matrix([[8, -2, 4], [-2, 2, -2], [4, -2, 8]])/1000
rf = .01

``````
``````

In [4]:

Xeq = np.matrix([[1/3], [1/3], [1/3]])

``````
``````

In [6]:

Xeq_return = muvec.T * Xeq
Xeq_return * 100

``````
``````

Out[6]:

matrix([[ 4.]])

``````
``````

In [7]:

Xeq_vol = np.sqrt(Xeq.T * V * Xeq)
Xeq_vol * 100

``````
``````

Out[7]:

matrix([[ 4.47213595]])

``````
``````

In [22]:

Xmin = 1/np.sum(V.I * Onevec) * V.I * Onevec
Xmin

``````
``````

Out[22]:

matrix([[ 0.16666667],
[ 0.66666667],
[ 0.16666667]])

``````
``````

In [24]:

Xmin_return = 1/np.sum(V.I * Onevec) * muvec.T * V.I * Onevec
Xmin_return * 100

``````
``````

Out[24]:

matrix([[ 3.]])

``````
``````

In [26]:

muhat = muvec - rf
Xsh = 1/np.sum(V.I * muhat) * V.I * muhat
Xsh

``````
``````

Out[26]:

matrix([[ 0.29166667],
[ 0.58333333],
[ 0.125     ]])

``````
``````

In [28]:

Xsh_return = 1/np.sum(V.I * muhat) * muvec.T * V.I * muhat
Xsh_return * 100

``````
``````

Out[28]:

matrix([[ 3.41666667]])

``````
``````

In [34]:

Xsh_var = 1/np.sum(V.I * muhat)**2 * muhat.T * V.I * V * V.I * muhat
Xsh_vol = np.sqrt(Xsh_var)
Xsh_vol *100

``````
``````

Out[34]:

matrix([[ 2.83823106]])

``````
``````

In [35]:

Sharpe_ratio = (Xsh_return - rf)/Xsh_vol
Sharpe_ratio

``````
``````

Out[35]:

matrix([[ 0.85146932]])

``````
``````

In [38]:

opportunity_vol = .05
opportunity_return = rf + Sharpe_ratio * opportunity_vol
opportunity_return * 100

``````
``````

Out[38]:

matrix([[ 5.25734659]])

``````
``````

In [ ]:

``````