Skip to content
5

Buy-in Threshold Constraints

PortfolioOptimisers.BuyInThresholdEstimator Type
julia
struct BuyInThresholdEstimator{T1} <: AbstractConstraintEstimator
    val::T1
end

Estimator for buy-in threshold portfolio constraints.

BuyInThresholdEstimator 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 values, as a dictionary, pair, or vector of pairs.

Constructor

julia
BuyInThresholdEstimator(;
                        val::Union{<:AbstractDict, <:Pair{<:AbstractString, <:Real},
                                   <:AbstractVector{<:Pair{<:AbstractString, <:Real}}})

Validation

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

Examples

julia
julia> BuyInThresholdEstimator(Dict("A" => 0.05, "B" => 0.1))
BuyInThresholdEstimator
  val ┴ Dict{String, Float64}: Dict("B" => 0.1, "A" => 0.05)

julia> BuyInThresholdEstimator(["A" => 0.05, "B" => 0.1])
BuyInThresholdEstimator
  val ┴ Vector{Pair{String, Float64}}: ["A" => 0.05, "B" => 0.1]

Related

source
PortfolioOptimisers.BuyInThreshold Type
julia
struct BuyInThreshold{T1} <: AbstractConstraintResult
    val::T1
end

Container for buy-in threshold portfolio constraints.

BuyInThreshold 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: Scalar or vector of threshold values for portfolio weights.

Constructor

julia
BuyInThreshold(; val::Union{<:Real, <:AbstractVector{<:Real}})

Validation

Examples

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

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

Related

source
PortfolioOptimisers.threshold_constraints Function
julia
threshold_constraints(t::Union{Nothing, <:BuyInThreshold}, args...; kwargs...)

Propagate or pass through buy-in threshold portfolio constraints.

threshold_constraints returns the input BuyInThreshold 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 BuyInThreshold object or nothing.

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

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

Returns

  • bt::Union{Nothing, <:BuyInThreshold}: The input constraint object, unchanged.

Examples

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

julia> threshold_constraints(nothing)

Related

source
julia
threshold_constraints(t::BuyInThresholdEstimator, sets::AssetSets;
                      datatype::DataType = Float64, strict::Bool = false)

Generate buy-in threshold portfolio constraints from a BuyInThresholdEstimator and asset set.

threshold_constraints constructs a BuyInThreshold 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: BuyInThresholdEstimator 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::BuyInThreshold: 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 = BuyInThresholdEstimator(Dict("A" => 0.05, "B" => 0.1));

julia> threshold_constraints(t, sets)
BuyInThreshold
  val ┴ Vector{Float64}: [0.05, 0.1, 0.0]

Related

source
julia
threshold_constraints(bounds::UniformlyDistributedBounds, sets::AssetSets; kwargs...)

Generate uniform buy-in threshold portfolio constraints for all assets.

threshold_constraints constructs a BuyInThreshold object with a uniform threshold value for each asset in sets, using UniformlyDistributedBounds. The threshold is set to 1/N, where N is the number of assets, ensuring equal minimum allocation across all assets.

Arguments

Returns

  • BuyInThreshold: Object with uniform threshold values for all assets.

Examples

julia
julia> sets = AssetSets(; dict = Dict("nx" => ["A", "B", "C"]));

julia> threshold_constraints(UniformlyDistributedBounds(), sets)
BuyInThreshold
  val ┴ Float64: 0.3333333333333333

Related

source
julia
threshold_constraints(t::AbstractVector{<:Union{Nothing, <:BuyInThresholdEstimator,
                                                <:BuyInThreshold}}, sets::AssetSets;
                      kwargs...)

Broadcasts threshold_constraints over the vector.

Provides a uniform interface for processing multiple constraint estimators simultaneously.

source