There's more...

Having simulated 100,000 random portfolios, we can also investigate which one has the highest Sharpe ratio (maximum expected return per unit of risk, also known as the Tangency Portfolio) or minimum volatility. To locate these portfolios among the simulated ones, we use np.argmin and np.argmax, which return the index of a minimum/maximum value in the array.

The code is as follows:

max_sharpe_ind = np.argmax(portf_results_df.sharpe_ratio)
max_sharpe_portf = portf_results_df.loc[max_sharpe_ind]

min_vol_ind = np.argmin(portf_results_df.volatility)
min_vol_portf = portf_results_df.loc[min_vol_ind]

We can also investigate the constituents of these portfolios:

print('Maximum Sharpe ratio portfolio ----')
print('Performance')
for index, value in max_sharpe_portf.items():
print(f'{index}: {100 * value:.2f}% ', end="", flush=True)
print(' Weights')
for x, y in zip(RISKY_ASSETS, weights[np.argmax(portf_results_df.sharpe_ratio)]):
print(f'{x}: {100*y:.2f}% ', end="", flush=True)

The maximum Sharpe ratio portfolio allocates the majority of the resources (~75%) to Microsoft and virtually nothing to Facebook. That is because Facebook's annualized average returns for 2018 were negative:

The minimum volatility portfolio assigns ~79% of the weight to Microsoft, as it is the stock with the lowest volatility (this can be inspected by viewing the covariance matrix):

Lastly, we mark these two portfolios on the Efficient Frontier plot. To do so, we add two extra scatterplots, each with one point corresponding to the selected portfolio. We then define the marker shape with the marker argument, and the marker size with the s argument. We increase the size of the markers to make the portfolios more visible among all others.

The code is as follows:

fig, ax = plt.subplots()
portf_results_df.plot(kind='scatter', x='volatility',
y='returns', c='sharpe_ratio',
cmap='RdYlGn', edgecolors='black',
ax=ax)
ax.scatter(x=max_sharpe_portf.volatility,
y=max_sharpe_portf.returns,
c='black', marker='*',
s=200, label='Max Sharpe Ratio')
ax.scatter(x=min_vol_portf.volatility,
y=min_vol_portf.returns,
c='black', marker='P',
s=200, label='Minimum Volatility')
ax.set(xlabel='Volatility', ylabel='Expected Returns',
title='Efficient Frontier')
ax.legend()

Executing the code generates the following plot:

We did not plot the individual assets and the Efficient Frontier's line, to avoid the plot becoming too cluttered.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.21.160