Skip to content
13

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!.

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.

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

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.

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