| # Mean-Variance Trade-Off in Portfolio Optimization LP and QP > Applications > Back | Portfolio Optimization | Next ## Portfolio optimization with sign constraints We return to the portfolio optimization problem. This time, we assume that shorting is not allowed. In other words, we can only invest in any given asset, or decide not to invest; but we can't borrow and hold any negative position. The problem we have introduced now takes the form where is our target for the nominal return, and is a positive semi-definite matrix that contains information about the uncertainty on the assets’ returns (see here). The above is a QP. CVX implementation
    cvx_begin
        variable x(n,1);
        minimize( x'*S*x );
        subject to
           rhat'*x == mu;
           x >= 0;
    cvx_end
## Other constraints We can add other linear or affine inequality constraints to the problem. ### Sector bounds For example, we can put upper bounds on some elements of , to limit the amount of investment in any single asset. We can also require that the total sum invested in a given sector (corresponding to say, the first assets) does not exceed a fraction of the total sum invested. This can be modeled by Again, the above is a QP, with just one more affine inequality. ## Diversification We can also impose some diversification constraints. For example, we may impose that no group of (with ) assets contain more than of the total invested. We write this as where is the -th largest component of , so that is the sum of the largest elements in . The function is convex, since it is the point-wise maximum of linear functions (hence it is polyhedral): The function is implemented in CVX by invoking `sum_largest`. CVX implementation
    cvx_begin
        variable x(n,1);
        minimize( x'*S*x );
        subject to
           rhat'*x == mu;
           x >= 0;
           sum_largest(x,10) <= 0.8*sum(x);
    cvx_end
The above expression for simply states that the function is the pointwise maximum of the ( choose ) linear functions obtained by choosing any subset of indices in . For example, with and : Since is polyhedral, we can definitely represent the constraint as a finite set of affine inequality constraints, that is, a polyhedron. However the list of constraints is huge: for , , we have to list more than constraints! A more efficient way is based in the following expression, proven here: In this form, the diversification constraint can be expressed as: there exist a scalar and a -vector such that In the above, is the vector of ones in . Here, are additional variables that allow a QP representation with a moderate number of variables and constraints: The lesson here is that a polyhedron in a -dimensional space, with an exponential number of facets, can be represented as a polyhedron in a higher dimensional space (in our case, with dimension ), with a moderate number of facets (precisely facets). By adding just a few dimensions to the problem we are able to deal (implicitly) with a very high number of constraints.