Skip to content
18

Weight Constraints

PortfolioOptimisers.w_neg_flag Function
julia
w_neg_flag(_::Nothing) -> Bool

Return true when the weight bound wb contains at least one negative value, indicating a long-short strategy is required.

Arguments

  • wb: Weight bound. Accepts nothing, a scalar Number, or a VecNum.

Returns

  • flag::Bool: false when wb is nothing; wb < 0 when wb is a scalar; any(x -> x < 0, wb) when wb is a vector.

Related

source
PortfolioOptimisers.w_finite_flag Function
julia
w_finite_flag(_::Nothing) -> Bool

Return true when wb contains at least one finite value, meaning a bound constraint should be added to the model.

Arguments

  • wb: Weight bound. Accepts nothing, a scalar Number, or a VecNum.

Returns

  • flag::Bool: false when wb is nothing; isfinite(wb) when wb is a scalar; any(isfinite, wb) when wb is a vector.

Related

source
PortfolioOptimisers.set_weight_constraints! Function
julia
set_weight_constraints!(args...)

Add weight bound constraints to the JuMP optimisation model.

The fall-through method does nothing. The concrete method adds lower-bound and upper-bound constraints on the portfolio weight vector w, handles long-short decomposition when negative bounds are present via lw/sw variables, and delegates budget constraints to set_budget_constraints!.

Mathematical definition

kwku.

Where:

  • w: Portfolio weights vector N×1.

  • k: Budget scaling / homogenisation variable.

  • , u: Lower and upper bound vectors from wb.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.

  • wb::WeightBounds: Weight bound specification containing lower and upper bounds.

  • bgt: Optional total budget constraint (number or BudgetRange).

  • sbgt: Optional short-side budget constraint.

  • gbgt: Optional gross (leverage) budget constraint, applied only when the weight bounds admit shorts. See set_gross_budget_constraints!.

  • long::Bool = false: When true, raises an error if any bound is negative.

Note

The budgets set here bound the realised exposures rather than pinning them, because lw and sw are upper bounds on the parts of w. Pinning them is the xbgt option of short_mip_threshold_constraints, applied later by set_mip_constraints!.

Validation

  • Raises an error when long = true and any bound is negative.

Returns

  • nothing.

Related

source
PortfolioOptimisers.non_zero_real_or_vec Function
julia
non_zero_real_or_vec(_::Nothing) -> Bool

Return true when x is non-zero.

Arguments

  • x: Value to check. Accepts nothing, a scalar Number, or a VecNum.

Returns

  • flag::Bool: false when x is nothing; !iszero(x) for a scalar; any(!iszero, x) for a vector.

Related

source
PortfolioOptimisers.set_linear_weight_constraints! Function
julia
set_linear_weight_constraints!(args...)

Add linear inequality and equality weight constraints to the JuMP optimisation model.

The fall-through method does nothing. The concrete method iterates over the collection of LinearConstraint objects lcms and adds A * w ≤ k * B (inequality) and A * w = k * B (equality) constraints for each entry.

Mathematical definition

AineqwkBineq,Aeqw=kBeq.

Where:

  • w: Portfolio weights vector N×1.

  • k: Budget scaling / homogenisation variable.

  • Aineq, Aeq: Constraint coefficient matrices for inequality and equality constraints.

  • Bineq, Beq: Constraint response vectors for inequality and equality constraints.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.

  • lcms: Collection of LinearConstraint objects defining the linear constraints.

  • key_ineq::Symbol: Base key for naming inequality constraints in the model.

  • key_eq::Symbol: Base key for naming equality constraints in the model.

Returns

  • nothing.

Related

source