Weight Constraints: private API

PortfolioOptimisers.w_neg_flagFunction
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_flagFunction
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
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, a BudgetRange, or a BudgetCostEstimator, which is the whole of JuMPOptimiser's own bgt bound.
  • sbgt: Optional short-side budget constraint. A BudgetCostEstimator bgt forbids one, so the pair never meets here.
  • 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

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.

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
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: When true, raises an error if any weight bound is negative.

Returns

  • nothing.

Related

source
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 of LinearConstraint objects 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

source