A long-only constraint requires every portfolio weight or position to be nonnegative. It prevents short positions by enforcing w ≥ 0 in an optimization model. section 10.3.1 section 13.3.2
In a mean-variance allocation, LongOnlyConstraint is combined with FullInvestmentConstraint and other limits, such as a volatility bound. The constraint itself needs no asset-specific inputs: it simply applies a nonnegativity condition to the optimization variable w. section 10.3.1
Portfolio allocation
A maximum-expected-return problem can combine LongOnlyConstraint(), FullInvestmentConstraint(), and a 15% volatility constraint. The resulting weights allocate 73.1976% to VWO and 26.8023% to AGG, with zero weights for VTI, VEA, BNDX, and EMB; every position remains nonnegative and the weights sum to one.
The same rule applies during rebalancing, where the variables represent monetary positions rather than normalized weights. Its generate_constraint method returns one condition v ≥ 0 for every position, alongside a full-investment condition requiring total invested value to equal the desired amount. section 13.3.2
