Skip to content
18

Threshold Constraints

PortfolioOptimisers.ThresholdEstimator Type
julia
struct ThresholdEstimator{__T_val, __T_key, __T_dval} <: AbstractConstraintEstimator

Estimator for buy-in threshold portfolio constraints.

ThresholdEstimator specifies a minimum allocation threshold for each asset in a portfolio. Only assets with weights above the threshold are allocated nonzero weight. The estimator supports asset-specific thresholds via dictionaries, pairs, or vectors of pairs, and validates input for non-emptiness.

Fields

  • val: Asset-specific threshold value(s).

  • key: Key to specify the asset universe in sets.dict. If nothing, the key is taken from sets.key.

  • dval: Default value for assets not specified in val.

Constructors

julia
ThresholdEstimator(;
    val::EstValType,
    dval::Option{<:Number} = nothing,
    key::Option{<:AbstractString} = nothing
) -> ThresholdEstimator

Validation

  • If val is a AbstractDict or AbstractVector, !isempty(val).

  • If dval is not nothing, it is validated with assert_nonempty_nonneg_finite_val.

  • If key is not nothing, 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:

Examples

julia
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 ┴ nothing

julia> ThresholdEstimator(; val = "A" => 0.05)
ThresholdEstimator
   val ┼ Pair{String, Float64}: "A" => 0.05
   key ┼ nothing
  dval ┴ nothing

julia> ThresholdEstimator(; val = 0.05)
ThresholdEstimator
   val ┼ Float64: 0.05
   key ┼ nothing
  dval ┴ nothing

julia> ThresholdEstimator(; val = [0.05])
ThresholdEstimator
   val ┼ Vector{Float64}: [0.05]
   key ┼ nothing
  dval ┴ nothing

julia> ThresholdEstimator(; val = UniformValues())
ThresholdEstimator
   val ┼ UniformValues()
   key ┼ nothing
  dval ┴ nothing

Related

source
PortfolioOptimisers.Threshold Type
julia
struct Threshold{__T_val} <: AbstractConstraintResult

Container for buy-in threshold portfolio constraints.

Threshold stores the minimum allocation threshold(s) for assets in a portfolio. The threshold can be specified as a scalar (applied to all assets) or as a vector of per-asset values. Input validation ensures all thresholds are finite and non-negative.

Fields

  • val: Threshold value(s) for portfolio weights.

Constructors

julia
Threshold(;
    val::Num_VecNum
) -> Threshold

Validation

View parameters

When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:

Examples

julia
julia> Threshold(0.05)
Threshold
  val ┴ Float64: 0.05

julia> Threshold([0.05, 0.1, 0.0])
Threshold
  val ┴ Vector{Float64}: [0.05, 0.1, 0.0]

Related

source
PortfolioOptimisers.BtE_Bt Type
julia
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

source
PortfolioOptimisers.VecOptBtE_Bt Type
julia
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

source
PortfolioOptimisers.BtE_Bt_VecOptBtE_Bt Type
julia
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

source
PortfolioOptimisers.VecOptBt Type
julia
const VecOptBt = AbstractVector{<:Option{<:Threshold}}

Alias for a vector of optional threshold results.

Represents a collection of optional Threshold elements.

Related

source
PortfolioOptimisers.Bt_VecOptBt Type
julia
const Bt_VecOptBt = Union{<:Threshold, <:VecOptBt}

Alias for a single threshold result or a vector of optional threshold results.

Matches either a single Threshold or a vector of optional Threshold objects.

Related

source
PortfolioOptimisers.threshold_constraints Function
julia
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 existing Threshold object or nothing.

  • args...: Additional positional arguments (ignored).

  • kwargs...: Additional keyword arguments (ignored).

Returns

  • bt::Option{<:Threshold}: The input constraint object, unchanged.

Examples

julia
julia> threshold_constraints(Threshold(0.05))
Threshold
  val ┴ Float64: 0.05

julia> threshold_constraints(nothing)

Related

source
julia
threshold_constraints(t::ThresholdEstimator, sets::AssetSets;
                      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: ThresholdEstimator specifying asset-specific threshold values.

  • sets: AssetSets containing asset names or indices.

  • datatype: Output data type for thresholds.

  • strict: If true, enforces strict matching between assets and thresholds (throws error on mismatch); if false, issues a warning.

Returns

  • bt::Threshold: Object containing threshold values aligned with sets.

Details

  • Thresholds are extracted and mapped to assets using estimator_to_val.

  • If a threshold is missing for an asset, assigns zero (no threshold) unless strict is true.

Examples

julia
julia> sets = AssetSets(; 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

source
julia
threshold_constraints(t::VecOptBtE_Bt, sets::AssetSets;
                      kwargs...)

Broadcasts threshold_constraints over the vector.

Provides a uniform interface for processing multiple constraint estimators simultaneously.

source