2
$\begingroup$

Problem:

I am trying to set up constraints for a long/short mean variance optimization problem. My constraints include:

  • beta neutrality

  • cash neutrality

  • equality constraints on categories: A_categ is a matrix of 1s and 0 and b_categ is a vector 1xn of weights equal to 1/n where n is number of categories.

Script:

h_pos = cvx.Variable(n)
h_neg = cvx.Variable(n)
h = h_pos-h_neg
Sigma = np.identity(n)

ret = mu.T*h

risk = cvx.quad_form(h,Sigma)
objective = cvx.Maximize(ret - 50*risk)

#beta neutrality matrix
Abeta = df_t['beta'].fillna(0).values
beta = 0

constraints = [h_pos>=0, h_neg>=0,1<=cvx.sum(h_pos), cvx.sum(h_pos)<=1.0,
          1<=cvx.sum(h_neg), cvx.sum(h_neg)<=1.0, Abeta*h==beta, h>=-1,h<=1,A_categ.T*h_pos == b_categ, A_categ.T*h_neg == -b_categ, cvx.sum(h)==0]

prob = cvx.Problem(objective, constraints)
prob.solve(verbose=True)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.