Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to do this optimisation using Quantopian Optimize API?

Hi Q,

I have the following maximisation currently that I want to port to optimize API. Could you please tell me how to go about it?

def trade(context, data):  
    stocks, alphas, betas, components = build_model(......)  
    (n,m) = betas.shape  
    x = cvx.Variable(n)  
    obj = cvx.Maximize(alphas.T * x)  
    constraints = [ sum(cvx.abs(x)) <= 1.,  
                    cvx.abs(sum(x)) < 0.01 ]  
    c = components  
    constraints.append(cvx.abs(x - betas * (c * x)) < 0.001) # how do I do this with optimize API?  
    if context.prevX is not None:  
        constraints.append(sum(cvx.abs(x-context.prevX])) < 0.5)      # turnover constraint  
    prob = cvx.Problem(obj, constraints)  
    prob.solve()  
    x = np.ravel(x.value)  
    # now we trade x weights

Best regards,
Pravin

1 response

To Q support -

Will the Optimize API code ever be published? This would be one way to tackle problems like this one...build on the existing Optimize API code, by pasting it into the algo, and then adding CVXPY constraints.