MIP Constraints
PortfolioOptimisers.get_mip_ss Function
get_mip_ss(ss::Number, args...) -> NumberReturn 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
sourcePortfolioOptimisers.set_mip_ss_expr! Function
set_mip_ss_expr!(
model::Model,
ss::Union{Nothing, Number},
wb::WeightBounds
) -> AnyRegister 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 viaget_mip_sswhennothing).wb::WeightBounds: Weight bound specification containing lower and upper bounds.
Returns
ss: The registered scaling-constant expression.
Related
sourcePortfolioOptimisers.AbstractMIPSpace Type
abstract type AbstractMIPSpaceAbstract 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
sourcePortfolioOptimisers.AssetMIPSpace Type
struct AssetMIPSpace <: AbstractMIPSpaceAsset-space MIP constraints: indicators gate the portfolio weights w directly and model keys use the bare names (:ib, :i_mip, :w_mip_lt, ...).
Related
sourcePortfolioOptimisers.SubsetMIPSpace Type
struct SubsetMIPSpace{T1<:(AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}), T2<:Integer} <: AbstractMIPSpaceSub-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;:sfor cardinality sub-groups,:sgfor group-cardinality sub-groups.i::Integer: Index of the selection matrix, used in key naming.
Related
sourcePortfolioOptimisers.mip_key Function
mip_key(_::AssetMIPSpace, name::Symbol) -> SymbolMap 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
sourcePortfolioOptimisers.mip_wx! Function
mip_wx!(model::Model, _::AssetMIPSpace) -> AnyReturn 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
sourcePortfolioOptimisers.mip_bounds Function
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
sourcePortfolioOptimisers.use_direct_mip_indicators Function
use_direct_mip_indicators(
model::Model,
_::AssetMIPSpace,
k
) -> BoolWhether 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
sourcePortfolioOptimisers.mip_wb Function
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
Where:
: Portfolio weights vector . , : Long and short binary indicator vectors. , : Lower and upper bound vectors from wb, mapped into the space ofsp.
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 frommip_wx!.il: Long binary (or continuous relaxation) indicator variable.is: Short binary (or continuous relaxation) indicator variable.
Returns
nothing.
Related
sourcePortfolioOptimisers.short_mip_threshold_constraints Function
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
) -> AnyAdd 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:
Where:
, : Long and short binary indicator variables for position . , : Continuous relaxations of and . : Budget scaling / homogenisation variable.
Minimum-holding thresholds:
Where:
: Weight expression for position in the space of sp., : Long and short continuous indicator expressions. , : Long and short binary indicator variables for position . , : Long and short minimum-holding thresholds for position . : 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 viaget_mip_sswhennothing).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
sourcePortfolioOptimisers.mip_constraints Function
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
Where:
: Binary inclusion indicator for position . : Continuous relaxation of . : Budget scaling / homogenisation variable. : Big-M constant.
Minimum-holding threshold and cardinality:
Where:
: Weight expression for position in the space of sp.: Continuous relaxation of . : Minimum-holding threshold for position . : 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 viaget_mip_sswhennothing).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
PortfolioOptimisers.set_iplg_constraints! Function
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
sourcePortfolioOptimisers.set_mip_constraints! Function
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 viaget_mip_sswhennothing).miprb_flag::Bool = false: Whether to add MIP rebalancing constraints.
Returns
nothing.
Related
PortfolioOptimisers.set_all_smip_constraints! Function
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 viaget_mip_sswhennothing).i::Integer = 1: Index for generating unique names (single-matrix method only).
Returns
nothing.
Related
PortfolioOptimisers.set_scardmip_constraints! Function
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 viaget_mip_sswhennothing).i::Integer = 1: Index for generating unique names (single-matrix method only).
Returns
nothing.
Related
PortfolioOptimisers.set_sgcardmip_constraints! Function
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 viaget_mip_sswhennothing).i::Integer = 1: Index for generating unique names (single-matrix method only).
Returns
nothing.
Related
PortfolioOptimisers.set_smip_constraints! Function
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 viaget_mip_sswhennothing).
Returns
nothing.
Related