Skip to content
18

MIP Constraints

PortfolioOptimisers.get_mip_ss Function
julia
get_mip_ss(ss::Number, args...) -> Number

Return the big-M style scaling constant used by MIP constraints.

When ss is a number it is returned directly. When nothing, the value is derived from the largest finite bound magnitude in wb multiplied by 1000, defaulting to 1000.0 when all bounds are infinite or absent.

Arguments

  • ss::Number: Scaling constant. Returned as-is.

Returns

  • ss::Number: The scaling constant.

Related

source
PortfolioOptimisers.set_mip_ss_expr! Function
julia
set_mip_ss_expr!(
    model::Model,
    ss::Union{Nothing, Number},
    wb::WeightBounds
) -> Any

Register the big-M scaling constant as the model expression :ss and return it.

Asset-space and sub-group MIP builders share the single :ss key; the first caller registers it via get_mip_ss, subsequent callers reuse the registered expression.

Arguments

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

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

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

Returns

  • ss: The registered scaling-constant expression.

Related

source
PortfolioOptimisers.AbstractMIPSpace Type
julia
abstract type AbstractMIPSpace

Abstract supertype for the weight space a MIP constraint builder acts on.

A MIP space tells the shared builders which expression the binary indicators gate (mip_wx!), how weight bounds map into that space (mip_bounds), and how model keys are named (mip_key).

Related

source
PortfolioOptimisers.AssetMIPSpace Type
julia
struct AssetMIPSpace <: AbstractMIPSpace

Asset-space MIP constraints: indicators gate the portfolio weights w directly and model keys use the bare names (:ib, :i_mip, :w_mip_lt, ...).

Related

source
PortfolioOptimisers.SubsetMIPSpace Type
julia
struct SubsetMIPSpace{T1<:(AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}), T2<:Integer} <: AbstractMIPSpace

Sub-group MIP constraints: indicators gate the sub-group weights smtx * w and weight bounds map through the selection matrix. Model keys are namespaced as Symbol(pfx, name, :_, i) so multiple sub-groups (and the cardinality/group-cardinality variants) do not collide.

Fields

  • smtx: Selection matrix mapping assets to sub-groups.

  • pfx::Symbol: Key prefix; :s for cardinality sub-groups, :sg for group-cardinality sub-groups.

  • i::Integer: Index of the selection matrix, used in key naming.

Related

source
PortfolioOptimisers.mip_key Function
julia
mip_key(_::AssetMIPSpace, name::Symbol) -> Symbol

Map a logical MIP builder name to the model key for the given space.

Asset space returns the name unchanged; sub-group space returns Symbol(pfx, name, :_, i).

Related

source
PortfolioOptimisers.mip_wx! Function
julia
mip_wx!(model::Model, _::AssetMIPSpace) -> Any

Return the weight expression the MIP indicators gate.

Asset space returns the portfolio weights w; sub-group space registers and returns the sub-group weight expression smtx * w under the space's :mtx_expr key.

Related

source
PortfolioOptimisers.mip_bounds Function
julia
mip_bounds(
    _::AssetMIPSpace,
    b::AbstractVector{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}
) -> AbstractVector{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}

Map a weight bound vector into the MIP space.

Asset space returns the bounds unchanged; sub-group space maps them through the selection matrix, smtx * b.

Related

source
PortfolioOptimisers.use_direct_mip_indicators Function
julia
use_direct_mip_indicators(
    model::Model,
    _::AssetMIPSpace,
    k
) -> Bool

Whether the binary indicators can gate the weights directly, without the continuous big-M relaxation of indicator * k.

True when the budget k is a constant. The asset space additionally treats the presence of the RiskBudgeting normalisation constraint :crkb as a fixed budget.

Related

source
PortfolioOptimisers.mip_wb Function
julia
mip_wb(_::Model, _::AbstractMIPSpace, _::Nothing, args...)

Add MIP-compatible weight bound constraints using binary selection variables.

The fall-through method does nothing when wb is nothing. The concrete method adds wx ≥ is ⊙ lb and wx ≤ il ⊙ ub constraints when the respective finite bounds are present, where wx and the bounds live in the space selected by sp (mip_wx!, mip_bounds).

Mathematical definition

iswilu.

Where:

  • w: Portfolio weights vector N×1.

  • il, is: Long and short binary indicator vectors.

  • , u: Lower and upper bound vectors from wb, mapped into the space of sp.

Arguments

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

  • sp::AbstractMIPSpace: Weight space the constraints act on.

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

  • wx::VecNum: Weight expression from mip_wx!.

  • il: Long binary (or continuous relaxation) indicator variable.

  • is: Short binary (or continuous relaxation) indicator variable.

Returns

  • nothing.

Related

source
PortfolioOptimisers.short_mip_threshold_constraints Function
julia
short_mip_threshold_constraints(
    model::Model,
    sp::AbstractMIPSpace,
    wb::WeightBounds,
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    ffl::Union{Nothing, Number, AbstractVector{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    ffs::Union{Nothing, Number, AbstractVector{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    ss::Union{Nothing, Number},
    lt_flag::Bool,
    st_flag::Bool,
    ffl_flag::Bool,
    ffs_flag::Bool,
    miprb_flag::Bool
) -> Any

Add MIP binary selection variables and threshold constraints for long-short portfolios.

Creates long/short binary indicator variables (or their continuous relaxations when k is a JuMP variable), enforces that each position is either long or short but not both, and applies long/short minimum-holding threshold, fixed-fee, and rebalancing constraints based on the flags provided. The weight expression, bound mapping, and model key naming are selected by sp, so the same builder serves asset-space and sub-group constraints.

Mathematical definition

Mutual-exclusivity and big-M linearisation:

ilbi+isbi1,ilfi=ilbik,isfi=isbik.

Where:

  • ilbi, isbi: Long and short binary indicator variables for position i.

  • ilfi, isfi: Continuous relaxations of ilbik and isbik.

  • k: Budget scaling / homogenisation variable.

Minimum-holding thresholds:

wiilfiiM(1ilbi),wiisfiui+M(1isbi).

Where:

  • wi: Weight expression for position i in the space of sp.

  • ilfi, isfi: Long and short continuous indicator expressions.

  • ilbi, isbi: Long and short binary indicator variables for position i.

  • i, ui: Long and short minimum-holding thresholds for position i.

  • M: Big-M constant.

Arguments

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

  • sp::AbstractMIPSpace: Weight space the constraints act on.

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

  • lt::Option{<:Threshold}: Long-side minimum-holding threshold.

  • st::Option{<:Threshold}: Short-side minimum-holding threshold.

  • ffl::Option{<:Num_VecNum}: Long-side fixed fee rate(s).

  • ffs::Option{<:Num_VecNum}: Short-side fixed fee rate(s).

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

  • lt_flag::Bool: Whether to apply the long-side threshold.

  • st_flag::Bool: Whether to apply the short-side threshold.

  • ffl_flag::Bool: Whether to add long fixed fee expressions.

  • ffs_flag::Bool: Whether to add short fixed fee expressions.

  • miprb_flag::Bool: Whether to add MIP rebalancing constraints.

Returns

  • i_mip: Combined long+short indicator expression.

Related

source
PortfolioOptimisers.mip_constraints Function
julia
mip_constraints(
    model::Model,
    sp::AbstractMIPSpace,
    wb::WeightBounds,
    ffl::Union{Nothing, Number, AbstractVector{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    lt::Union{Nothing, Threshold},
    ss::Union{Nothing, Number},
    lt_flag::Bool,
    ffl_flag::Bool,
    miprb_flag::Bool
) -> Union{JuMP.Containers.DenseAxisArray{_A, _B, Ax, _C} where {_A, _B, Ax<:Tuple, _C<:NTuple{_B, JuMP.Containers._AxisLookup}}, Vector}

Add a long-only MIP binary indicator variable and associated constraints to the JuMP optimisation model.

Creates a binary variable per position indicating whether it is held. When k is a JuMP variable, introduces a continuous relaxation with big-M linking constraints. Optionally applies minimum-holding threshold, fixed-fee, and rebalancing constraints. The weight expression, bound mapping, and model key naming are selected by sp, so the same builder serves asset-space and sub-group constraints.

Mathematical definition

Big-M linearisation of ibfi=ibik:

ibfik,ibfiMibi,ibfi+M(1ibi)k.

Where:

  • ibi: Binary inclusion indicator for position i.

  • ibfi: Continuous relaxation of ibik.

  • k: Budget scaling / homogenisation variable.

  • M: Big-M constant.

Minimum-holding threshold and cardinality:

wiibfii,iibicard.

Where:

  • wi: Weight expression for position i in the space of sp.

  • ibfi: Continuous relaxation of ibik.

  • i: Minimum-holding threshold for position i.

  • card: Maximum number of non-zero positions (cardinality bound).

Arguments

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

  • sp::AbstractMIPSpace: Weight space the constraints act on.

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

  • ffl::Option{<:Num_VecNum}: Long-side fixed fee rate(s).

  • lt::Option{<:Threshold}: Long-side minimum-holding threshold.

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

  • lt_flag::Bool: Whether to apply the long-side threshold.

  • ffl_flag::Bool: Whether to add fixed fee expressions.

  • miprb_flag::Bool: Whether to add MIP rebalancing constraints.

Returns

  • ib: Binary indicator JuMP variable vector.

Related

source
PortfolioOptimisers.set_iplg_constraints! Function
julia
set_iplg_constraints!(
    model::Model,
    plgs::Union{AbstractPhylogenyConstraintResult, AbstractVector{<:AbstractPhylogenyConstraintResult}}
)

Add integer phylogeny cardinality constraints to the JuMP optimisation model.

Iterates over plgs and, for each IntegerPhylogeny entry, enforces A * ib ≤ B where ib is the binary indicator variable created by mip_constraints.

Arguments

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

  • plgs: Collection of phylogeny constraint objects.

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_mip_constraints! Function
julia
set_mip_constraints!(
    model::Model,
    wb::WeightBounds,
    card::Union{Nothing, Integer},
    gcard::Union{Nothing, LinearConstraint},
    pl::Union{Nothing, AbstractPhylogenyConstraintResult, AbstractVector{<:AbstractPhylogenyConstraintResult}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    fees::Union{Nothing, Fees},
    ss::Union{Nothing, Number}
)
set_mip_constraints!(
    model::Model,
    wb::WeightBounds,
    card::Union{Nothing, Integer},
    gcard::Union{Nothing, LinearConstraint},
    pl::Union{Nothing, AbstractPhylogenyConstraintResult, AbstractVector{<:AbstractPhylogenyConstraintResult}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    fees::Union{Nothing, Fees},
    ss::Union{Nothing, Number},
    miprb_flag::Bool
)

Add all long-only MIP constraints to the JuMP optimisation model.

Orchestrates cardinality, group cardinality, integer phylogeny, minimum-holding threshold, fixed-fee, and rebalancing MIP constraints for long-only portfolios, dispatching to mip_constraints, short_mip_threshold_constraints, and set_iplg_constraints! as appropriate.

Arguments

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

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

  • card::Option{<:Integer}: Optional maximum cardinality (number of non-zero assets).

  • gcard::Option{<:LinearConstraint}: Optional group cardinality constraint.

  • pl::Option{<:PlC_VecPlC}: Optional phylogeny constraint(s).

  • lt::Option{<:Threshold}: Long-side minimum-holding threshold.

  • st::Option{<:Threshold}: Short-side minimum-holding threshold.

  • fees::Option{<:Fees}: Optional fee specification.

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

  • miprb_flag::Bool = false: Whether to add MIP rebalancing constraints.

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_all_smip_constraints! Function
julia
set_all_smip_constraints!(
    model::Model,
    wb::WeightBounds,
    card::Union{Nothing, Integer},
    gcard::Union{Nothing, LinearConstraint},
    smtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    ss::Union{Nothing, Number}
)
set_all_smip_constraints!(
    model::Model,
    wb::WeightBounds,
    card::Union{Nothing, Integer},
    gcard::Union{Nothing, LinearConstraint},
    smtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    ss::Union{Nothing, Number},
    i::Integer
)

Add all sub-group MIP constraints for a single or multiple selection matrices.

The single-matrix method handles cardinality, group cardinality, long/short threshold, and weight-bound constraints for one sub-group via the shared builders (short_mip_threshold_constraints, mip_constraints) on a SubsetMIPSpace. The vector method iterates over collections of cardinalities, group constraints, and selection matrices.

Arguments

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

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

  • card: Cardinality bound(s) for the sub-group(s).

  • gcard: Group-cardinality constraint(s) for the sub-group(s).

  • smtx: Selection matrix (or vector thereof) for the sub-group(s).

  • lt: Long-side minimum-holding threshold(s).

  • st: Short-side minimum-holding threshold(s).

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

  • i::Integer = 1: Index for generating unique names (single-matrix method only).

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_scardmip_constraints! Function
julia
set_scardmip_constraints!(
    model::Model,
    wb::WeightBounds,
    card::Union{Nothing, Integer},
    smtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    ss::Union{Nothing, Number}
)
set_scardmip_constraints!(
    model::Model,
    wb::WeightBounds,
    card::Union{Nothing, Integer},
    smtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    ss::Union{Nothing, Number},
    i::Integer
)

Add sub-group cardinality MIP constraints using a selection matrix.

The single-matrix method enforces sum(sib) ≤ card for one sub-group. The vector method iterates over collections of cardinalities and selection matrices.

Arguments

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

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

  • card: Cardinality bound(s) for the sub-group(s).

  • smtx: Selection matrix (or vector thereof).

  • lt: Long-side minimum-holding threshold(s).

  • st: Short-side minimum-holding threshold(s).

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

  • i::Integer = 1: Index for generating unique names (single-matrix method only).

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_sgcardmip_constraints! Function
julia
set_sgcardmip_constraints!(
    model::Model,
    wb::WeightBounds,
    gcard::Union{Nothing, LinearConstraint},
    smtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    ss::Union{Nothing, Number}
)
set_sgcardmip_constraints!(
    model::Model,
    wb::WeightBounds,
    gcard::Union{Nothing, LinearConstraint},
    smtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}},
    lt::Union{Nothing, Threshold},
    st::Union{Nothing, Threshold},
    ss::Union{Nothing, Number},
    i::Integer
)

Add sub-group group-cardinality MIP constraints using a selection matrix.

The single-matrix method enforces linear group cardinality constraints A * sib ≤ B and A * sib = B on the sub-group binary indicator. The vector method iterates over multiple group constraints and selection matrices.

Arguments

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

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

  • gcard: Group-cardinality constraint(s).

  • smtx: Selection matrix (or vector thereof).

  • lt: Long-side minimum-holding threshold(s).

  • st: Short-side minimum-holding threshold(s).

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

  • i::Integer = 1: Index for generating unique names (single-matrix method only).

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_smip_constraints! Function
julia
set_smip_constraints!(
    model::Model,
    wb::WeightBounds,
    card::Union{Nothing, Integer, AbstractVector{<:Integer}},
    gcard::Union{Nothing, LinearConstraint, AbstractVector{<:LinearConstraint}},
    smtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}, AbstractVector{<:AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}}},
    sgmtx::Union{Nothing, AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}, AbstractVector{<:AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}}},
    lt::Union{Nothing, Threshold, AbstractVector{<:Union{Nothing, var"#s874"} where var"#s874"<:Threshold}},
    st::Union{Nothing, Threshold, AbstractVector{<:Union{Nothing, var"#s874"} where var"#s874"<:Threshold}},
    glt::Union{Nothing, Threshold, AbstractVector{<:Union{Nothing, var"#s874"} where var"#s874"<:Threshold}},
    gst::Union{Nothing, Threshold, AbstractVector{<:Union{Nothing, var"#s874"} where var"#s874"<:Threshold}},
    ss::Union{Nothing, Number}
)

Add all sub-group MIP constraints (both cardinality and group-cardinality) to the JuMP optimisation model.

Dispatches between combined selection matrices (calling set_all_smip_constraints!) and separate cardinality/group-cardinality selection matrices (calling set_scardmip_constraints! and set_sgcardmip_constraints! independently).

Arguments

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

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

  • card: Cardinality bound(s).

  • gcard: Group-cardinality constraint(s).

  • smtx: Cardinality selection matrix (or vector thereof).

  • sgmtx: Group-cardinality selection matrix (or vector thereof).

  • lt: Long-side minimum-holding threshold(s) for cardinality sub-groups.

  • st: Short-side minimum-holding threshold(s) for cardinality sub-groups.

  • glt: Long-side minimum-holding threshold(s) for group-cardinality sub-groups.

  • gst: Short-side minimum-holding threshold(s) for group-cardinality sub-groups.

  • ss::Option{<:Number}: Big-M scaling constant (computed via get_mip_ss when nothing).

Returns

  • nothing.

Related

source