Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
long-only mean reversion w/ CVXPY

Thought I'd see if I could whip together a quick-and-dirty algo w/ CVXPY, which recently was released on Quantopian (and is reportedly used under the hood in the optimization API that is in the works).

If I've implemented things correctly, the code should be solving the optimization problem described in Section 4.2 of On-Line Portfolio Selection with Moving Average Reversion.

The CVXPY code:

import cvxpy as cvx  
x = cvx.Variable(m)  
objective = cvx.Minimize(cvx.sum_entries(cvx.square(x-b_t)))  
constraints = [cvx.sum_entries(x) == 1, cvx.sum_entries(x_tilde*x) >= 1, x >= 0]  
prob = cvx.Problem(objective, constraints)  
prob.solve()  
weight = x.value