Skip to content

Instantly share code, notes, and snippets.

@0x0L
Created February 4, 2018 06:04
Show Gist options
  • Save 0x0L/69f6440bde42ee2ddc65f2e6141c174b to your computer and use it in GitHub Desktop.
Save 0x0L/69f6440bde42ee2ddc65f2e6141c174b to your computer and use it in GitHub Desktop.
def markowitz(mu, cov, hedge=None):
z = mu
K = np.linalg.inv(cov)
if hedge is not None:
Q = hedge @ K @ hedge.T
beta = np.linalg.inv(Q) @ hedge @ K @ mu
z = mu - beta @ hedge
z = K @ z
z = z / sum(abs(z))
return z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment