Threshold Constraints
PortfolioOptimisers.ThresholdEstimator — Type
struct ThresholdEstimator{__T_val, __T_key, __T_dval} <: AbstractConstraintEstimatorResolves a minimum-holding threshold written in asset or group names against a universe.
threshold_constraints turns it into a Threshold: every name is mapped to its indices in the universe key selects, and an unnamed asset takes dval, which defaults to no threshold. A threshold may also be a scalar, a vector, or an algorithmic rule such as UniformValues.
Fields
val: Asset-specific minimum-holding threshold value(s).
key: Key to specify the universe insets.dictthat names resolve against. Ifnothing, the key is taken fromsets.xkey— or, where the caller is written against another declared axis, from that axis' key.
dval: Default value for assets not specified inval.
Constructors
ThresholdEstimator(; val::EstValType, key::Option{<:AbstractString} = nothing, dval::Option{<:Number} = nothing) -> ThresholdEstimatorKeywords correspond to the struct's fields.
Validation
valanddvalare both validated withassert_nonempty_nonneg_finite_val, so a threshold is non-empty, non-negative and finite.- If
keyis notnothing, it is a non-empty string.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
val: Sliced to the selected indices viaport_opt_view.
Only a vector val is sliced. A val that is a scalar, a Dict, a Pair or an algorithmic rule is not indexed by asset, so a view passes it through untouched and it resolves against the viewed universe when the estimator runs.
Examples
julia> ThresholdEstimator(; val = Dict("A" => 0.05, "B" => 0.1))ThresholdEstimator val ┼ Dict{String, Float64}: Dict("B" => 0.1, "A" => 0.05) key ┼ nothing dval ┴ nothingjulia> ThresholdEstimator(; val = "A" => 0.05)ThresholdEstimator val ┼ Pair{String, Float64}: "A" => 0.05 key ┼ nothing dval ┴ nothingjulia> ThresholdEstimator(; val = 0.05)ThresholdEstimator val ┼ Float64: 0.05 key ┼ nothing dval ┴ nothingjulia> ThresholdEstimator(; val = [0.05])ThresholdEstimator val ┼ Vector{Float64}: [0.05] key ┼ nothing dval ┴ nothingjulia> ThresholdEstimator(; val = UniformValues())ThresholdEstimator val ┼ UniformValues() key ┼ nothing dval ┴ nothingRelated
References
- [4] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.4.
PortfolioOptimisers.Threshold — Type
struct Threshold{__T_val} <: AbstractConstraintResultForces every held position to reach a minimum size, and drives anything smaller to zero.
The threshold is a scalar shared by every asset or a vector of one value per asset. It exists to keep a mixed-integer model from answering with a long tail of positions too small to trade.
Mathematical definition
The threshold is the lower half of a buy-in constraint, stated against the held binary:
\[\begin{align} \underset{\boldsymbol{w}}{\mathrm{opt}}\quad & \phi(\boldsymbol{w})\\ \textrm{s.t.}\quad & \ell_i z_i \leq w_i \leq u_i z_i\,,\quad \forall i = 1,\ldots,N\,,\\ & \boldsymbol{z} \in \{0, 1\}^{N}\,,\quad \boldsymbol{w} \in \mathcal{W}\,. \end{align}\]
Where:
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\boldsymbol{z}$: Held binary, one entry per asset.
- $\ell_i$: Minimum-holding threshold for asset $i$, the
valfield. - $u_i$: Upper weight bound for asset $i$, from
WeightBounds. - $N$: Number of assets.
- $\phi$: Objective function of the optimiser.
- $\mathcal{W}$: Rest of the feasible set.
The binary carries both halves. Where $z_i = 0$ the two bounds collapse to $w_i = 0$; where $z_i = 1$ the position must reach $\ell_i$. A long and a short threshold are separate objects, each bound to its own side's binary.
The threshold binds the held weight, not the trade. The source writes the same constraint over positive and negative trades against a reference portfolio; this library writes it over the position, so no reference portfolio enters it. On a six-asset conditional-value-at-risk model at Threshold(0.15) every held weight came back at or above 0.15, with the smallest exactly 0.15.
Fields
val: Minimum-holding threshold(s) on the portfolio weights. A held position must reach its threshold; a position below it is driven to zero. The threshold binds the held weight, never the trade, so a reference portfolio does not enter it.
Constructors
Threshold( val::Num_VecNum) -> ThresholdThreshold(; val::Num_VecNum) -> ThresholdKeywords correspond to the struct's fields.
Validation
valis validated withassert_nonempty_nonneg_finite_val.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
val: Sliced to the selected indices viaport_opt_view.
Examples
julia> Threshold(0.05)Threshold val ┴ Float64: 0.05julia> Threshold([0.05, 0.1, 0.0])Threshold val ┴ Vector{Float64}: [0.05, 0.1, 0.0]Related
short_mip_threshold_constraintsmip_constraintsset_mip_constraints!ThresholdEstimatorthreshold_constraintsAbstractConstraintResultWeightBoundsport_opt_view
References
- [4] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.4.
PortfolioOptimisers.BtE_Bt — Type
const BtE_Bt = Union{<:Threshold, <:ThresholdEstimator}Alias for a threshold constraint result or estimator.
Matches either a Threshold result or a ThresholdEstimator. Used internally for dispatch in threshold constraint generation.
Related
PortfolioOptimisers.VecOptBtE_Bt — Type
const VecOptBtE_Bt = AbstractVector{<:Option{<:BtE_Bt}}Alias for a vector of optional threshold estimators or results.
Represents a collection of optional BtE_Bt elements (threshold estimators or results, or nothing).
Related
PortfolioOptimisers.BtE_Bt_VecOptBtE_Bt — Type
const BtE_Bt_VecOptBtE_Bt = Union{<:BtE_Bt, <:VecOptBtE_Bt}Alias for a single or vector of optional threshold estimators or results.
Matches either a single BtE_Bt or a vector of optional ones.
Related
PortfolioOptimisers.VecOptBt — Type
const VecOptBt = AbstractVector{<:Option{<:Threshold}}Alias for a vector of optional threshold results.
Represents a collection of optional Threshold elements.
Related
PortfolioOptimisers.threshold_constraints — Function
threshold_constraints(t::Option{<:Threshold}, args...; kwargs...)Propagate or pass through buy-in threshold portfolio constraints.
threshold_constraints returns the input Threshold object or nothing unchanged. This method is used to propagate already constructed buy-in threshold constraints, enabling composability and uniform interface handling in constraint generation workflows.
Arguments
t: An existingThresholdobject ornothing.args...: Additional positional arguments (ignored).kwargs...: Additional keyword arguments (ignored).
Returns
bt::Option{<:Threshold}: The input constraint object, unchanged.
Examples
julia> threshold_constraints(Threshold(0.05))Threshold val ┴ Float64: 0.05julia> threshold_constraints(nothing)Related
threshold_constraints(t::ThresholdEstimator, sets::UniverseSets;
datatype::DataType = Float64, strict::Bool = false)Generate buy-in threshold portfolio constraints from a ThresholdEstimator and asset set.
threshold_constraints constructs a Threshold object representing minimum allocation thresholds for the assets in sets, using the specifications in t. Supports scalar, vector, dictionary, pair, or custom threshold types for flexible assignment and validation.
Arguments
t:ThresholdEstimatorspecifying asset-specific threshold values.sets:UniverseSetscontaining asset names or indices.datatype: Output data type for thresholds.strict: Iftrue, a name int.valthatsetsdoes not resolve throws; iffalse, it issues a warning and is skipped.
Returns
bt::Threshold: Object containing threshold values aligned withsets.
Details
- Thresholds are extracted and mapped to assets by
estimator_to_val, against the universet.keyselects. - An asset that
t.valdoes not name takest.dval. The defaultdval = nothinggives itzero(datatype), which is no threshold. strictgoverns unresolvable names, not unnamed assets. An unnamed asset always takes the default and never throws.
Examples
julia> sets = UniverseSets(; dict = Dict("nx" => ["A", "B", "C"]));julia> t = ThresholdEstimator(Dict("A" => 0.05, "B" => 0.1));julia> threshold_constraints(t, sets)Threshold val ┴ Vector{Float64}: [0.05, 0.1, 0.0]Related
threshold_constraints(t::VecOptBtE_Bt, sets::UniverseSets;
kwargs...)Broadcasts threshold_constraints over the vector.
Provides a uniform interface for processing multiple constraint estimators simultaneously.
References
- [4]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).