Back to Community
Active share constraint DCP problems [CVXPY]

Hi Everyone,

I am working on a portfolio optimisation case with an objective function like this, to minimise tracking error

"Minimize(quad_form(w, cov) - 2*w.T*cov_b)"

I am now trying to add a constraint on active share with a minimum threshold

"sum_entries(abs(w - df_in['BENCH_WEIGHT'].as_matrix())) >= 0.8 "

so I basically want to keep my active part of the portfolio above 80%. But I now get a DCP error, which I understand why, I can do

"sum_entries(abs(w - df_in['BENCH_WEIGHT'].as_matrix())) <= 0.8" 

which will work fine. But I cant figure out how I can transform my problem into a DCP conform case, any guidance will be appreciated

2 responses

Hi Markus,

CVXPY (and, more generally, any convex optimization library) can only handle constraints where the set of all points satisfying that constraint forms a convex set. A set is convex if, for any two points a and b in the set, all points on the line between a and b are also in the set. Geometrically, that formulation corresponds to the idea that convex sets don't have any "holes" and that the boundary of a convex set has no "dents". For example, in two dimensions, circles and squares are convex, but donuts and crescents are not.

In the context of portfolio optimization, a "point" is tuple of portfolio weights, constraints correspond to sets of portfolios that satisfy the constraints we're interested in.

The constraint that you're interested in is:

sum_entries(abs(w - df_in['BENCH_WEIGHT'].as_matrix())) >= 0.8  

The set of points satisfying this constraint corresponds geometrically to the set of points outside a hypercube centered at df_in['BENCH_WEIGHT']. Unfortunately, that set isn't convex. An easy to to see that is to notice that df_in['BENCH_WEIGHT'] doesn't satisfy the constraint, but df_in['BENCH_WEIGHT'] plus or minus 0.81 does satisfy it.

As a slightly handwavey rule, it's usually possible to place upper bounds on expressions involving absolute quantities, but not possible to place lower bounds on those expressions. This is why your constraint works when you replace the greater than constraint with a less than constraint.


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi Scott,
thanks for your reply, I think i set up the constraint wrong. According to literature it should be

1-sum_entries(min_elemwise(w, df_in['BENCH_WEIGHT'])) >= 0.8