Diversification
The returns is equal to the average of the two, but the standard deviation is less! How is this? It is something called diversification. The ideas will be mathematically explore in the investments course, but for now we are just going to work through understanding the idea of it. Basically, as we add more stocks to a portfolio, we expect that the risk of the portfolio will converge to be just the market risk! The random other risks of stocks will cancel out with one another if we add enough.
To explore this, first define a function which combines N stocks and finds the standard deviation.
def n_stock_std(returns):
#Get the number of return series
n = len(returns)
#Multiple each by 1/n and then sum
portfolio_return = sum([r * 1/n for r in returns])
#Find the standard deviation and return it
return np.std(portfolio_return)
print(n_stock_std(stock_returns[:2]))
print(n_stock_std(stock_returns[:5]))
With this function created, let's get the standard deviation for different numbers of stocks.
#Get the standard deviation for n stocks
stds = [n_stock_std(stock_returns[:n]) for n in list(range(1, 101))]
n = list(range(1, 101))
#Get the market standard deviation
market_std = np.std(market_returns)
plt.plot(n, stds, label='N-Stock Portfolio')
plt.axhline(market_std, label='Market Std', color='grey', linestyle='--')
plt.legend()
plt.ylabel("Std")
plt.xlabel("N")
plt.title("Diversification Effects")
plt.show()
As you can see, the more stocks we add in, the more our portfolio standard deviation is going to converge to only have market risk!