Notebook

Finding the Capital Market Line

This notebook shows how to compute the capital market line, and hence finding portfolios with maximal sharpe ratio that matches the risk free rate (rf). First, we load stocks data by using get_pricing function. Secondly, we find the efficient frontier by using cvxopt library, as shown in the quantopian blog on portfolio optimizations <br></br> Then, we find the efficient frontier function by using spline interpolation, and finding the tangent line that passes throw rf, as shown in the tutorial about market line from Python for Finance book <br></br>

Importing important modules

In [75]:
import numpy as np
import pandas as pd
import pytz
from datetime import datetime
import matplotlib.pyplot as plt
Getting stocks data
In [76]:
start = datetime(2011, 1, 1, 0, 0, 0, 0, pytz.utc)
end = datetime(2013, 1, 1, 0, 0, 0, 0, pytz.utc)

data = get_pricing(['IBM', 'GLD', 'XOM', 'AAPL', 
                                    'MSFT', 'TLT', 'SHY', 'AA'],
                            start, end)
Show normalized time series data
In [77]:
data.price.plot(figsize=(8,5))
plt.ylabel('price in $')
Out[77]:
<matplotlib.text.Text at 0x7f6db24fcd50>
In [78]:
prices = data.price
returnsOfStocks = prices.pct_change().dropna()
print(returnsOfStocks);
                           Equity(3766 [IBM])  Equity(26807 [GLD])  \
2011-01-04 00:00:00+00:00            0.001628            -0.023696   
2011-01-05 00:00:00+00:00           -0.004334            -0.002524   
2011-01-06 00:00:00+00:00            0.010338            -0.003944   
2011-01-07 00:00:00+00:00           -0.004174            -0.001942   
2011-01-10 00:00:00+00:00           -0.001758             0.004117   
2011-01-11 00:00:00+00:00           -0.002573             0.005665   
2011-01-12 00:00:00+00:00            0.012357             0.003854   
2011-01-13 00:00:00+00:00           -0.002012            -0.010707   
2011-01-14 00:00:00+00:00            0.007930            -0.009628   
2011-01-18 00:00:00+00:00            0.004600             0.005351   
2011-01-19 00:00:00+00:00            0.033780             0.002399   
2011-01-20 00:00:00+00:00            0.000514            -0.019070   
2011-01-21 00:00:00+00:00           -0.001989            -0.001067   
2011-01-24 00:00:00+00:00            0.026553            -0.005419   
2011-01-25 00:00:00+00:00            0.011524            -0.001765   
2011-01-26 00:00:00+00:00           -0.002786             0.008225   
2011-01-27 00:00:00+00:00            0.000248            -0.024474   
2011-01-28 00:00:00+00:00           -0.011856             0.018601   
2011-01-31 00:00:00+00:00            0.015956            -0.003530   
2011-02-01 00:00:00+00:00            0.010635             0.006853   
2011-02-02 00:00:00+00:00           -0.001591            -0.002371   
2011-02-03 00:00:00+00:00            0.002145             0.013292   
2011-02-04 00:00:00+00:00            0.002324            -0.003964   
2011-02-07 00:00:00+00:00            0.005307             0.000000   
2011-02-08 00:00:00+00:00            0.008192             0.011241   
2011-02-09 00:00:00+00:00           -0.009029            -0.000300   
2011-02-10 00:00:00+00:00           -0.003887            -0.001503   
2011-02-11 00:00:00+00:00           -0.000610            -0.004439   
2011-02-14 00:00:00+00:00           -0.004393             0.004686   
2011-02-15 00:00:00+00:00           -0.002145             0.007741   
...                                       ...                  ...   
2012-11-16 00:00:00+00:00            0.005490            -0.001144   
2012-11-19 00:00:00+00:00            0.019109             0.012118   
2012-11-20 00:00:00+00:00           -0.006723            -0.002800   
2012-11-21 00:00:00+00:00            0.006346             0.000896   
2012-11-23 00:00:00+00:00            0.016710             0.012234   
2012-11-26 00:00:00+00:00           -0.003256            -0.001120   
2012-11-27 00:00:00+00:00           -0.008477            -0.004014   
2012-11-28 00:00:00+00:00            0.003948            -0.012919   
2012-11-29 00:00:00+00:00           -0.002292             0.003963   
2012-11-30 00:00:00+00:00           -0.007779            -0.007176   
2012-12-03 00:00:00+00:00           -0.002999             0.000482   
2012-12-04 00:00:00+00:00           -0.000581            -0.010054   
2012-12-05 00:00:00+00:00           -0.003961            -0.001885   
2012-12-06 00:00:00+00:00            0.005832             0.002315   
2012-12-07 00:00:00+00:00            0.011701             0.004012   
2012-12-10 00:00:00+00:00            0.003595             0.003875   
2012-12-11 00:00:00+00:00            0.008462            -0.001025   
2012-12-12 00:00:00+00:00           -0.006846             0.000894   
2012-12-13 00:00:00+00:00           -0.004458            -0.008493   
2012-12-14 00:00:00+00:00           -0.000937            -0.001399   
2012-12-17 00:00:00+00:00            0.009797             0.001840   
2012-12-18 00:00:00+00:00            0.009805            -0.014425   
2012-12-19 00:00:00+00:00           -0.002760            -0.002468   
2012-12-20 00:00:00+00:00           -0.001589            -0.012000   
2012-12-21 00:00:00+00:00           -0.006006             0.003506   
2012-12-24 00:00:00+00:00           -0.006455             0.002059   
2012-12-26 00:00:00+00:00           -0.002703             0.001058   
2012-12-27 00:00:00+00:00            0.003909             0.002363   
2012-12-28 00:00:00+00:00           -0.014011            -0.003909   
2012-12-31 00:00:00+00:00            0.008682             0.009281   

                           Equity(8347 [XOM])  Equity(24 [AAPL])  \
2011-01-04 00:00:00+00:00            0.005368           0.004798   
2011-01-05 00:00:00+00:00           -0.002536           0.008134   
2011-01-06 00:00:00+00:00            0.006156          -0.001048   
2011-01-07 00:00:00+00:00            0.005454           0.007448   
2011-01-10 00:00:00+00:00           -0.006218           0.018347   
2011-01-11 00:00:00+00:00            0.007588          -0.002045   
2011-01-12 00:00:00+00:00            0.012036           0.008258   
2011-01-13 00:00:00+00:00            0.001423           0.003597   
2011-01-14 00:00:00+00:00            0.015252           0.008100   
2011-01-18 00:00:00+00:00            0.010657          -0.021414   
2011-01-19 00:00:00+00:00           -0.005590          -0.006322   
2011-01-20 00:00:00+00:00           -0.006388          -0.017766   
2011-01-21 00:00:00+00:00            0.015944          -0.018340   
2011-01-24 00:00:00+00:00           -0.005316           0.032630   
2011-01-25 00:00:00+00:00            0.001272           0.011909   
2011-01-26 00:00:00+00:00            0.011183           0.007238   
2011-01-27 00:00:00+00:00            0.003896          -0.001791   
2011-01-28 00:00:00+00:00           -0.011017          -0.020984   
2011-01-31 00:00:00+00:00            0.021519           0.009665   
2011-02-01 00:00:00+00:00            0.039405           0.017123   
2011-02-02 00:00:00+00:00           -0.005722          -0.002272   
2011-02-03 00:00:00+00:00            0.000480          -0.002643   
2011-02-04 00:00:00+00:00           -0.002277           0.008989   
2011-02-07 00:00:00+00:00            0.007808           0.015495   
2011-02-08 00:00:00+00:00           -0.011085           0.009807   
2011-02-09 00:00:00+00:00           -0.005062           0.007880   
2011-02-10 00:00:00+00:00            0.007511          -0.009988   
2011-02-11 00:00:00+00:00           -0.003848           0.006535   
2011-02-14 00:00:00+00:00            0.024623           0.006493   
2011-02-15 00:00:00+00:00           -0.022735           0.002144   
...                                       ...                ...   
2012-11-16 00:00:00+00:00            0.003483           0.003461   
2012-11-19 00:00:00+00:00            0.014115           0.072510   
2012-11-20 00:00:00+00:00           -0.002510          -0.008473   
2012-11-21 00:00:00+00:00            0.006634           0.001023   
2012-11-23 00:00:00+00:00            0.012271           0.017421   
2012-11-26 00:00:00+00:00           -0.005612           0.031098   
2012-11-27 00:00:00+00:00           -0.013884          -0.007733   
2012-11-28 00:00:00+00:00            0.008356          -0.003268   
2012-11-29 00:00:00+00:00            0.000454           0.011242   
2012-11-30 00:00:00+00:00           -0.000794          -0.007423   
2012-12-03 00:00:00+00:00           -0.005110           0.001903   
2012-12-04 00:00:00+00:00           -0.004680          -0.017592   
2012-12-05 00:00:00+00:00            0.006078          -0.064226   
2012-12-06 00:00:00+00:00            0.003192           0.015668   
2012-12-07 00:00:00+00:00            0.006590          -0.025992   
2012-12-10 00:00:00+00:00           -0.001919          -0.006133   
2012-12-11 00:00:00+00:00            0.006447           0.021261   
2012-12-12 00:00:00+00:00            0.005394          -0.003869   
2012-12-13 00:00:00+00:00           -0.009500          -0.017288   
2012-12-14 00:00:00+00:00           -0.005642          -0.038898   
2012-12-17 00:00:00+00:00            0.008693           0.019954   
2012-12-18 00:00:00+00:00            0.007470           0.028301   
2012-12-19 00:00:00+00:00           -0.013065          -0.014502   
2012-12-20 00:00:00+00:00            0.005883          -0.007996   
2012-12-21 00:00:00+00:00           -0.016647          -0.004936   
2012-12-24 00:00:00+00:00           -0.005720           0.001617   
2012-12-26 00:00:00+00:00            0.001496          -0.013968   
2012-12-27 00:00:00+00:00           -0.002183           0.003999   
2012-12-28 00:00:00+00:00           -0.020032          -0.010725   
2012-12-31 00:00:00+00:00            0.017505           0.046237   

                           Equity(5061 [MSFT])  Equity(23921 [TLT])  \
2011-01-04 00:00:00+00:00             0.002860             0.000963   
2011-01-05 00:00:00+00:00            -0.001783            -0.021600   
2011-01-06 00:00:00+00:00             0.028929             0.003934   
2011-01-07 00:00:00+00:00            -0.007636             0.005116   
2011-01-10 00:00:00+00:00            -0.013291             0.005632   
2011-01-11 00:00:00+00:00            -0.003545            -0.005924   
2011-01-12 00:00:00+00:00             0.015653            -0.007042   
2011-01-13 00:00:00+00:00            -0.012259             0.008511   
2011-01-14 00:00:00+00:00             0.003546            -0.006600   
2011-01-18 00:00:00+00:00             0.012721            -0.004465   
2011-01-19 00:00:00+00:00            -0.006629             0.007001   
2011-01-20 00:00:00+00:00            -0.003864            -0.013145   
2011-01-21 00:00:00+00:00            -0.011636             0.007376   
2011-01-24 00:00:00+00:00             0.012487             0.000437   
2011-01-25 00:00:00+00:00             0.002467             0.009285   
2011-01-26 00:00:00+00:00             0.010545            -0.014827   
2011-01-27 00:00:00+00:00             0.004870             0.004394   
2011-01-28 00:00:00+00:00            -0.039114             0.005141   
2011-01-31 00:00:00+00:00            -0.001261            -0.006964   
2011-02-01 00:00:00+00:00             0.010280            -0.008657   
2011-02-02 00:00:00+00:00            -0.002499             0.000111   
2011-02-03 00:00:00+00:00            -0.010379            -0.008400   
2011-02-04 00:00:00+00:00             0.004521            -0.009697   
2011-02-07 00:00:00+00:00             0.014941             0.004615   
2011-02-08 00:00:00+00:00             0.003547            -0.009075   
2011-02-09 00:00:00+00:00            -0.011912             0.008366   
2011-02-10 00:00:00+00:00            -0.016742            -0.011212   
2011-02-11 00:00:00+00:00            -0.008550             0.014287   
2011-02-14 00:00:00+00:00            -0.000734             0.000783   
2011-02-15 00:00:00+00:00            -0.009916             0.004144   
...                                        ...                  ...   
2012-11-16 00:00:00+00:00            -0.005249            -0.000711   
2012-11-19 00:00:00+00:00             0.007916            -0.005933   
2012-11-20 00:00:00+00:00            -0.001122            -0.010027   
2012-11-21 00:00:00+00:00             0.008985            -0.000643   
2012-11-23 00:00:00+00:00             0.027829            -0.000885   
2012-11-26 00:00:00+00:00            -0.010830             0.004750   
2012-11-27 00:00:00+00:00            -0.011131             0.003926   
2012-11-28 00:00:00+00:00             0.009042            -0.001437   
2012-11-29 00:00:00+00:00            -0.014704             0.000080   
2012-11-30 00:00:00+00:00            -0.011619            -0.002478   
2012-12-03 00:00:00+00:00            -0.007700            -0.001282   
2012-12-04 00:00:00+00:00            -0.003028             0.005776   
2012-12-05 00:00:00+00:00             0.012528            -0.000319   
2012-12-06 00:00:00+00:00             0.002250             0.001835   
2012-12-07 00:00:00+00:00            -0.010101            -0.009000   
2012-12-10 00:00:00+00:00             0.017385             0.004501   
2012-12-11 00:00:00+00:00             0.014859            -0.007841   
2012-12-12 00:00:00+00:00            -0.002928            -0.011451   
2012-12-13 00:00:00+00:00            -0.004772             0.000571   
2012-12-14 00:00:00+00:00            -0.010882             0.007582   
2012-12-17 00:00:00+00:00             0.010628            -0.014807   
2012-12-18 00:00:00+00:00             0.017343            -0.010184   
2012-12-19 00:00:00+00:00            -0.009431             0.003485   
2012-12-20 00:00:00+00:00             0.013182            -0.000083   
2012-12-21 00:00:00+00:00            -0.006505             0.010667   
2012-12-24 00:00:00+00:00            -0.015642            -0.001555   
2012-12-26 00:00:00+00:00            -0.006467             0.001393   
2012-12-27 00:00:00+00:00             0.002418             0.003110   
2012-12-28 00:00:00+00:00            -0.014842             0.005955   
2012-12-31 00:00:00+00:00             0.006403            -0.017274   

                           Equity(23911 [SHY])  Equity(2 [AA])  
2011-01-04 00:00:00+00:00            -0.000119        0.045598  
2011-01-05 00:00:00+00:00            -0.001787        0.003028  
2011-01-06 00:00:00+00:00             0.001074       -0.012077  
2011-01-07 00:00:00+00:00             0.001431        0.004401  
2011-01-10 00:00:00+00:00             0.000595        0.002252  
2011-01-11 00:00:00+00:00            -0.000714       -0.007954  
2011-01-12 00:00:00+00:00            -0.000119       -0.006610  
2011-01-13 00:00:00+00:00             0.000476       -0.030191  
2011-01-14 00:00:00+00:00             0.000000        0.013977  
2011-01-18 00:00:00+00:00            -0.000238        0.020677  
2011-01-19 00:00:00+00:00             0.000238       -0.014733  
2011-01-20 00:00:00+00:00            -0.000833       -0.004984  
2011-01-21 00:00:00+00:00             0.000357       -0.011271  
2011-01-24 00:00:00+00:00            -0.000476        0.040532  
2011-01-25 00:00:00+00:00             0.000834       -0.011564  
2011-01-26 00:00:00+00:00            -0.000357        0.022167  
2011-01-27 00:00:00+00:00             0.000834       -0.007831  
2011-01-28 00:00:00+00:00             0.000714       -0.021251  
2011-01-31 00:00:00+00:00            -0.000119        0.027295  
2011-02-01 00:00:00+00:00            -0.002021        0.045290  
2011-02-02 00:00:00+00:00            -0.000596       -0.005777  
2011-02-03 00:00:00+00:00            -0.000954       -0.000581  
2011-02-04 00:00:00+00:00            -0.001074       -0.003488  
2011-02-07 00:00:00+00:00            -0.000239        0.010502  
2011-02-08 00:00:00+00:00            -0.001314        0.004619  
2011-02-09 00:00:00+00:00             0.000718       -0.013218  
2011-02-10 00:00:00+00:00            -0.000478       -0.003494  
2011-02-11 00:00:00+00:00             0.000120        0.015780  
2011-02-14 00:00:00+00:00            -0.000239        0.012083  
2011-02-15 00:00:00+00:00             0.000479       -0.010233  
...                                        ...             ...  
2012-11-16 00:00:00+00:00             0.000000        0.013648  
2012-11-19 00:00:00+00:00            -0.000118        0.019584  
2012-11-20 00:00:00+00:00            -0.000118       -0.010804  
2012-11-21 00:00:00+00:00            -0.000355        0.003641  
2012-11-23 00:00:00+00:00             0.000118        0.009674  
2012-11-26 00:00:00+00:00            -0.000118       -0.005988  
2012-11-27 00:00:00+00:00             0.000118       -0.001807  
2012-11-28 00:00:00+00:00             0.000000        0.012674  
2012-11-29 00:00:00+00:00             0.000118        0.002384  
2012-11-30 00:00:00+00:00             0.000118       -0.001189  
2012-12-03 00:00:00+00:00             0.000000        0.000000  
2012-12-04 00:00:00+00:00            -0.000118        0.001190  
2012-12-05 00:00:00+00:00             0.000118        0.019025  
2012-12-06 00:00:00+00:00             0.000000        0.000000  
2012-12-07 00:00:00+00:00             0.000118       -0.009335  
2012-12-10 00:00:00+00:00             0.000000        0.010601  
2012-12-11 00:00:00+00:00            -0.000118        0.012821  
2012-12-12 00:00:00+00:00             0.000000       -0.005754  
2012-12-13 00:00:00+00:00             0.000000       -0.004630  
2012-12-14 00:00:00+00:00             0.000118        0.015116  
2012-12-17 00:00:00+00:00            -0.000355        0.001145  
2012-12-18 00:00:00+00:00            -0.000355        0.018307  
2012-12-19 00:00:00+00:00             0.000118       -0.028090  
2012-12-20 00:00:00+00:00             0.000000        0.004624  
2012-12-21 00:00:00+00:00             0.000118       -0.014960  
2012-12-24 00:00:00+00:00             0.000000        0.007009  
2012-12-26 00:00:00+00:00            -0.000237        0.013921  
2012-12-27 00:00:00+00:00             0.000355       -0.013730  
2012-12-28 00:00:00+00:00             0.000000       -0.012761  
2012-12-31 00:00:00+00:00            -0.000355        0.018801  

[501 rows x 8 columns]
In [79]:
import cvxopt as opt
from cvxopt import blas, solvers
import scipy.optimize as sco

# Turn off progress printing 
solvers.options['show_progress'] = False
Returns of Stocks
In [80]:
return_vec = returnsOfStocks.values.T
print(return_vec);
[[ 0.00162789 -0.00433399  0.01033803 ...,  0.00390869 -0.01401132
   0.0086821 ]
 [-0.02369565 -0.00252357 -0.00394375 ...,  0.00236333 -0.00390892
   0.00928118]
 [ 0.00536841 -0.00253638  0.00615632 ..., -0.00218265 -0.02003224
   0.0175047 ]
 ..., 
 [ 0.00096329 -0.02159966  0.00393443 ...,  0.00310966  0.00595529
  -0.01727354]
 [-0.00011912 -0.00178699  0.00107411 ...,  0.00035549  0.         -0.00035537]
 [ 0.04559848  0.00302847 -0.01207729 ..., -0.01372998 -0.01276102
   0.01880141]]
Create random weights that sum to 1
In [81]:
def rand_weights(n):
    ''' Produces n random weights that sum to 1 '''
    k = np.random.rand(n)
    return k / sum(k)
Generate Random portfolios
In [82]:
def random_portfolio(returns):
    ''' 
    Returns the mean and standard deviation of returns for a random portfolio
    '''

    p = np.asmatrix(np.mean(returns, axis=1)) * 252
    w = np.asmatrix(rand_weights(returns.shape[0]))
    C = np.asmatrix(np.cov(returns)) * 252
    
    mu = w * p.T
    sigma = np.sqrt(w * C * w.T)
    
    # This recursion reduces outliers to keep plots pretty
    if sigma > 2:
        return random_portfolio(returns)
    return mu, sigma

n_portfolios = 3000
means, stds = np.column_stack([
    random_portfolio(return_vec) 
    for _ in range(n_portfolios)
])
Scatter plot all portfolios
In [83]:
plt.plot(stds, means, 'o', markersize=5)
plt.xlabel('std')
plt.ylabel('mean')
plt.title('Mean and standard deviation of returns of randomly generated portfolios');
plt.show();
Solving optimization problem
In [84]:
def optimal_portfolio(returns):
    n = len(returns)
    returns = np.asmatrix(returns)
    
    N = 100
    mus = [10**(5.0 * t/N - 1.0) for t in range(N)]
    
    # Convert to cvxopt matrices
    S = opt.matrix(np.cov(returns)*252)
    pbar = opt.matrix(np.mean(returns, axis=1)*252)
    
    # Create constraint matrices
    G = -opt.matrix(np.eye(n))   # negative n x n identity matrix
    h = opt.matrix(0.0, (n ,1))
    A = opt.matrix(1.0, (1, n))
    b = opt.matrix(1.0)
    
    # Calculate efficient frontier weights using quadratic programming
    portfolios = [solvers.qp(mu*S, -pbar, G, h, A, b)['x'] 
                  for mu in mus]
    ## CALCULATE RISKS AND RETURNS FOR FRONTIER
    returns = [blas.dot(pbar, x) for x in portfolios]
    risks = [np.sqrt(blas.dot(x, S*x)) for x in portfolios]
    return returns, risks

returns, risks = optimal_portfolio(return_vec)

plt.plot(stds, means, 'o')
plt.ylabel('mean')
plt.xlabel('std')
plt.plot(risks, returns, 'y-o');
Market LIne
In [85]:
import scipy.interpolate as sci
In [86]:
def getListOfUniqueWithinPrecision(sortedArray):
    ind = 0
    currentVal = 0
    diffToIgnore = 0.00000001
    listOfIndices = [];
    for i in range(sortedArray.size):
        if(sortedArray[i] - diffToIgnore > currentVal):
            listOfIndices.append(i);
            currentVal = sortedArray[i];
    return listOfIndices;
In [87]:
twoRowsArrayForSorting = np.vstack([returns, risks]).T;
rowsAfterSorting = twoRowsArrayForSorting[twoRowsArrayForSorting[:,0].argsort()].T
returnsSorted = rowsAfterSorting[0,:];
risksSorted = rowsAfterSorting[1,:];
listOfInd = getListOfUniqueWithinPrecision(risksSorted);
print(listOfInd)
risksSorted  = risksSorted[listOfInd];
returnsSorted  = returnsSorted[listOfInd];
ind = np.argmin(risksSorted)
evols = risksSorted[ind:]
erets = returnsSorted[ind:]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 99]
In [88]:
tck = sci.splrep(evols, erets)
In [89]:
def f(x):
    ''' Efficient frontier function (splines approximation). '''
    return sci.splev(x, tck, der=0)
def df(x):
    ''' First derivative of efficient frontier function. '''
    return sci.splev(x, tck, der=1)
In [90]:
def equations(p, rf=0.06):
    eq1 = rf - p[0]
    eq2 = rf + p[1] * p[2] - f(p[2])
    eq3 = p[1] - df(p[2])
    return eq1, eq2, eq3
In [91]:
opt = sco.fsolve(equations, [0.06, 0.5, 0.15])
In [92]:
opt
Out[92]:
array([ 0.06      ,  1.23618344,  0.09128196])
In [93]:
np.round(equations(opt), 5)
Out[93]:
array([ 0., -0.,  0.])
Show market line on graph
In [94]:
plt.figure(figsize=(8, 4))
plt.plot(stds, means, 'o')
            # random portfolio composition
plt.plot(evols, erets, 'y', lw=2.0)
            # efficient frontier
cx = np.linspace(0.0, 0.2)
plt.plot(cx, opt[0] + opt[1] * cx, lw=1.0)
            # capital market line
plt.plot(opt[2], f(opt[2]), 'r*', markersize=11.0) 
plt.grid(True)
plt.axhline(0, color='k', ls='--', lw=2.0)
plt.axvline(0, color='k', ls='--', lw=2.0)
plt.xlabel('expected volatility')
plt.ylabel('expected return')
Out[94]:
<matplotlib.text.Text at 0x7f6db1cf4c90>