-
-
Save fnneves/d5d7d1f29016f62b589455390c20aee5 to your computer and use it in GitHub Desktop.
medium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.random.seed(42) | |
num_ports = 6000 | |
all_weights = np.zeros((num_ports, len(stocks.columns))) | |
ret_arr = np.zeros(num_ports) | |
vol_arr = np.zeros(num_ports) | |
sharpe_arr = np.zeros(num_ports) | |
for x in range(num_ports): | |
# Weights | |
weights = np.array(np.random.random(4)) | |
weights = weights/np.sum(weights) | |
# Save weights | |
all_weights[x,:] = weights | |
# Expected return | |
ret_arr[x] = np.sum( (log_ret.mean() * weights * 252)) | |
# Expected volatility | |
vol_arr[x] = np.sqrt(np.dot(weights.T, np.dot(log_ret.cov()*252, weights))) | |
# Sharpe Ratio | |
sharpe_arr[x] = ret_arr[x]/vol_arr[x] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment