Constructing an efficient frontier with n stocks

When the number of stocks, n, increases, the correlation between each pair of stocks increases dramatically. For n stocks, we have n*(n-1)/2 correlations. For example, if n is 10, we have 45 correlations. Because of this, it is not a good idea to manually input those values. Instead, we generate means, standard deviations, and correlations by drawing random numbers from several uniform distributions. To produce correlated returns, first we generate n uncorrelated stock return time series and then apply Cholesky decomposition as follows:

import numpy as np import scipy as sp import pandas as pd import matplotlib.pyplot as plt from datetime import datetime as dt from scipy.optimize import minimize ...

Get Python for Finance - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.