Weight Constraints: private API
PortfolioOptimisers.w_neg_flag — Function
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. Acceptsnothing, a scalarNumber, or aVecNum.
Returns
flag::Bool:falsewhenwbisnothing;wb < 0whenwbis a scalar;any(x -> x < 0, wb)whenwbis a vector.
Related
PortfolioOptimisers.w_finite_flag — Function
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. Acceptsnothing, a scalarNumber, or aVecNum.
Returns
flag::Bool:falsewhenwbisnothing;isfinite(wb)whenwbis a scalar;any(isfinite, wb)whenwbis a vector.
Related
PortfolioOptimisers.set_weight_constraints! — Function
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
\[\begin{align} k \boldsymbol{\ell} &\leq \boldsymbol{w} \leq k \boldsymbol{u}\,. \end{align}\]
Where:
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $k$: Budget scaling / homogenisation variable.
- $\boldsymbol{\ell}$, $\boldsymbol{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. A number, aBudgetRange, or aBudgetCostEstimator, which is the whole ofJuMPOptimiser's ownbgtbound.sbgt: Optional short-side budget constraint. ABudgetCostEstimatorbgtforbids one, so the pair never meets here.gbgt: Optional gross (leverage) budget constraint, applied only when the weight bounds admit shorts. Seeset_gross_budget_constraints!.long::Bool = false: Whentrue, raises an error if any bound is negative.
Optimiser heads do not call this method directly. They pass their JuMPOptimiser, whose method forwards the whole budget group (bgt, sbgt, gbgt) in one hand-off, so a budget field cannot reach one head and miss the others.
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 = trueand any bound is negative.
Returns
nothing.
Related
set_weight_constraints!(
model::Model,
wb::WeightBounds,
opt::JuMPOptimiser
)
set_weight_constraints!(
model::Model,
wb::WeightBounds,
opt::JuMPOptimiser,
long::Bool
)
Add weight bound and budget constraints to model from the optimiser's own budget group.
Every JuMP optimiser head reaches set_weight_constraints! through this method, so the whole budget group (bgt, sbgt, gbgt) travels as one object. A budget field added to JuMPOptimiser is therefore read in one place rather than at every head, which is how the gross budget once reached MeanRisk alone and was silently dropped by the other four heads.
long = true forbids negative weight bounds, so the long/short decomposition is never built and sbgt and gbgt cannot apply; they are still forwarded, because the bound check is what rejects the combination.
Arguments
model::JuMP.Model: The JuMP optimisation model.wb::WeightBounds: Weight bound specification containing lower and upper bounds.opt::JuMPOptimiser: Optimiser supplying the budget group.long::Bool = false: Whentrue, raises an error if any weight bound is negative.
Returns
nothing.
Related
PortfolioOptimisers.non_zero_real_or_vec — Function
non_zero_real_or_vec(_::Nothing) -> Bool
Return true when x is non-zero.
Arguments
x: Value to check. Acceptsnothing, a scalarNumber, or aVecNum.
Returns
flag::Bool:falsewhenxisnothing;!iszero(x)for a scalar;any(!iszero, x)for a vector.
Related
PortfolioOptimisers.set_linear_weight_constraints! — Function
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
\[\begin{align} \mathbf{A}_{\mathrm{ineq}} \boldsymbol{w} \leq k \boldsymbol{B}_{\mathrm{ineq}}\,, \\ \mathbf{A}_{\mathrm{eq}} \boldsymbol{w} &= k \boldsymbol{B}_{\mathrm{eq}}\,. \end{align}\]
Where:
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $k$: Budget scaling / homogenisation variable.
- $\mathbf{A}_{\mathrm{ineq}}$, $\mathbf{A}_{\mathrm{eq}}$: Constraint coefficient matrices for inequality and equality constraints.
- $\boldsymbol{B}_{\mathrm{ineq}}$, $\boldsymbol{B}_{\mathrm{eq}}$: Constraint response vectors for inequality and equality constraints.
Arguments
model::JuMP.Model: The JuMP optimisation model.lcms: Collection ofLinearConstraintobjects defining the linear constraints.name_ineq::Symbol: Bare Model State entry name seeding the indexed inequality constraint entries.name_eq::Symbol: Bare Model State entry name seeding the indexed equality constraint entries.
Returns
nothing.
Related