EDIT Since the weight generation process of my random portfolios seems to preffer too similar portfolio I changed the following function:
def random_portfolios(num_portfolios, mean_returns, cov_matrix, risk_free_rate):
results = np.zeros((3,num_portfolios))
weights_record = []
for i in range(num_portfolios):
weights = abs(np.random.randn(len(mean_returns)))
weights[weights<1] = 0
if sum(weights)==0:
print("sum=0")
indexes = np.unique(np.random.randint(0,10,3)).tolist()
weights[indexes] = abs(np.random.randn(len(indexes)))
weights /= np.sum(weights)
weights_record.append(weights)
portfolio_std_dev, portfolio_return = portfolio_annualised_performance(weights, mean_returns, cov_matrix)
results[0,i] = portfolio_std_dev
results[1,i] = portfolio_return
results[2,i] = (portfolio_return - risk_free_rate) / portfolio_std_dev
return results, weights_record
After doing so, the Portfolios are way better distributed:
So, can we then agree that the above code does what it should and I can continue from here?