-
-
Save fnneves/55cd577332af91c3623dd62411b713cb to your computer and use it in GitHub Desktop.
Markowitz
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
def get_ret_vol_sr(weights): | |
weights = np.array(weights) | |
ret = np.sum(log_ret.mean() * weights) * 252 | |
vol = np.sqrt(np.dot(weights.T, np.dot(log_ret.cov()*252, weights))) | |
sr = ret/vol | |
return np.array([ret, vol, sr]) | |
def neg_sharpe(weights): | |
# the number 2 is the sharpe ratio index from the get_ret_vol_sr | |
return get_ret_vol_sr(weights)[2] * -1 | |
def check_sum(weights): | |
#return 0 if sum of the weights is 1 | |
return np.sum(weights)-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment