Phylogeny Constraints
PortfolioOptimisers.SemiDefinitePhylogenyEstimator Type
struct SemiDefinitePhylogenyEstimator{__T_pl, __T_p} <: AbstractPhylogenyConstraintEstimatorEstimator for generating semi-definite phylogeny-based constraints in PortfolioOptimisers.jl.
SemiDefinitePhylogenyEstimator constructs constraints based on phylogenetic or clustering structures among assets, using a semi-definite matrix representation. The estimator wraps a phylogeny or clustering estimator and a non-negative penalty parameter p, which controls the strength of the constraint.
Fields
pl: Network estimator, phylogeny result, clustering estimator, or clustering result.p: Non-negative penalty parameter for the phylogeny constraint.
Constructors
SemiDefinitePhylogenyEstimator(;
pl::NwE_PlM_ClE_Cl = NetworkEstimator(),
p::Number = 0.05
) -> SemiDefinitePhylogenyEstimatorValidation
p >= 0.
Examples
julia> SemiDefinitePhylogenyEstimator()
SemiDefinitePhylogenyEstimator
pl ┼ NetworkEstimator
│ ce ┼ PortfolioOptimisersCovariance
│ │ ce ┼ Covariance
│ │ │ me ┼ SimpleExpectedReturns
│ │ │ │ w ┴ nothing
│ │ │ ce ┼ GeneralCovariance
│ │ │ │ ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
│ │ │ │ w ┴ nothing
│ │ │ alg ┴ FullMoment()
│ │ mp ┼ MatrixProcessing
│ │ │ pdm ┼ Posdef
│ │ │ │ alg ┼ UnionAll: NearestCorrelationMatrix.Newton
│ │ │ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ │ │ dn ┼ nothing
│ │ │ dt ┼ nothing
│ │ │ alg ┼ nothing
│ │ │ order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)
│ de ┼ Distance
│ │ power ┼ nothing
│ │ alg ┴ CanonicalDistance()
│ alg ┼ KruskalTree
│ │ args ┼ Tuple{}: ()
│ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ n ┴ Int64: 1
p ┴ Float64: 0.05Related
sourcePortfolioOptimisers.SemiDefinitePhylogeny Type
struct SemiDefinitePhylogeny{__T_A, __T_p} <: AbstractPhylogenyConstraintResultContainer for the result of semi-definite phylogeny-based constraint generation.
SemiDefinitePhylogeny stores the constraint matrix A and penalty parameter p resulting from a semi-definite phylogeny constraint estimator. This type is used to encapsulate the output of phylogeny-based constraint routines, enabling composable and modular constraint handling in portfolio optimisation workflows.
Fields
A: Phylogeny constraint matrix.p: Non-negative penalty parameter for the phylogeny constraint.
Constructors
SemiDefinitePhylogeny(;
A::MatNum_PhRMatNum,
p::Number = 0.05
) -> SemiDefinitePhylogenyValidation
LinearAlgebra.issymmetric(A)andall(iszero, LinearAlgebra.diag(A)).p >= 0.
Examples
julia> SemiDefinitePhylogeny([0.0 1.0; 1.0 0.0], 0.05)
SemiDefinitePhylogeny
A ┼ 2×2 Matrix{Float64}
p ┴ Float64: 0.05Related
PortfolioOptimisers.IntegerPhylogenyEstimator Type
struct IntegerPhylogenyEstimator{__T_pl, __T_B, __T_scale} <: AbstractPhylogenyConstraintEstimatorEstimator for generating integer phylogeny-based constraints in PortfolioOptimisers.jl.
IntegerPhylogenyEstimator constructs constraints based on phylogenetic or clustering structures among assets, using integer or discrete representations. The estimator wraps a phylogeny or clustering estimator, a non-negative integer or vector of integers B specifying group sizes or allocations, and a big-M parameter scale used for formulating the MIP constraints.
Fields
pl: Network estimator, phylogeny result, clustering estimator, or clustering result.B: Group sizes or allocations vector.scale: Non-negative big-M scaling factor for the MIP formulation.
Constructors
IntegerPhylogenyEstimator(;
pl::NwE_PlM_ClE_Cl = NetworkEstimator(),
B::Int_VecInt = 1,
scale::Number = 100_000.0
) -> IntegerPhylogenyEstimatorValidation
Bis validated withassert_nonempty_nonneg_finite_val.AbstractVector: It is additionally validated withvalidate_length_integer_phylogeny_constraint_B.
Examples
julia> IntegerPhylogenyEstimator()
IntegerPhylogenyEstimator
pl ┼ NetworkEstimator
│ ce ┼ PortfolioOptimisersCovariance
│ │ ce ┼ Covariance
│ │ │ me ┼ SimpleExpectedReturns
│ │ │ │ w ┴ nothing
│ │ │ ce ┼ GeneralCovariance
│ │ │ │ ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
│ │ │ │ w ┴ nothing
│ │ │ alg ┴ FullMoment()
│ │ mp ┼ MatrixProcessing
│ │ │ pdm ┼ Posdef
│ │ │ │ alg ┼ UnionAll: NearestCorrelationMatrix.Newton
│ │ │ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ │ │ dn ┼ nothing
│ │ │ dt ┼ nothing
│ │ │ alg ┼ nothing
│ │ │ order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)
│ de ┼ Distance
│ │ power ┼ nothing
│ │ alg ┴ CanonicalDistance()
│ alg ┼ KruskalTree
│ │ args ┼ Tuple{}: ()
│ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ n ┴ Int64: 1
B ┼ Int64: 1
scale ┴ Float64: 100000.0Related
sourcePortfolioOptimisers.IntegerPhylogeny Type
struct IntegerPhylogeny{__T_A, __T_B, __T_scale} <: AbstractPhylogenyConstraintResultContainer for the result of integer phylogeny-based constraint generation.
IntegerPhylogeny stores the constraint matrix A, group sizes or allocations B, and scaling parameter scale resulting from an integer phylogeny constraint estimator. This type encapsulates the output of integer/discrete phylogeny-based constraint routines, enabling composable and modular constraint handling in portfolio optimisation workflows.
Fields
A: Phylogeny constraint matrix.B: Group sizes or allocations vector.scale: Non-negative big-M scaling factor for the MIP formulation.
Constructors
IntegerPhylogeny(;
A::MatNum_PhRMatNum,
B::Int_VecInt = 1,
scale::Number = 100_000.0
) -> IntegerPhylogenyValidation
LinearAlgebra.issymmetric(A)andall(iszero, LinearAlgebra.diag(A)).Bis validated withassert_nonempty_nonneg_finite_val.AbstractVector:size(unique(A + LinearAlgebra.I; dims = 1), 1) == length(B).
Examples
julia> IntegerPhylogeny(; A = [0.0 1.0; 1.0 0.0], B = 2, scale = 100_000.0)
IntegerPhylogeny
A ┼ 1×2 Matrix{Float64}
B ┼ Int64: 2
scale ┴ Float64: 100000.0Related
PortfolioOptimisers.phylogeny_constraints Function
phylogeny_constraints(plc::Option{<:PlCE_PlC}, X::MatNum; dims::Int = 1, kwargs...)
phylogeny_constraints(plcs::VecPlCE_PlC, args...; kwargs...)Generate phylogeny-based portfolio constraints from an estimator or result.
phylogeny_constraints constructs constraint objects based on phylogenetic, res, or network structures among assets. It supports both semi-definite and integer constraint forms, accepting either an estimator (which wraps a phylogeny or clustering model and penalty parameters) or a precomputed result. If plc is nothing, returns nothing.
If plcs is a vector, this method broadcasts over each element, returning a vector of constraint results.
Arguments
plc: A phylogeny constraint estimator, result, ornothing.X: Data matrix of asset features or returns (ignored whenplcis not an estimator).dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to the underlying phylogeny matrix routine (ignored whenestis not an estimator).
Returns
res: Constraint result.SemiDefinitePhylogeny: For semi-definite constraint estimators/results.IntegerPhylogeny: For integer constraint estimators/results.nothing: Ifestisnothing.
Related
phylogeny_constraints(
plc::AbstractPhylogenyConstraintEstimator,
pr::Union{AbstractPriorResult, ReturnsResult};
rd,
cle_pr,
kwargs...
) -> Union{IntegerPhylogeny, SemiDefinitePhylogeny{<:AbstractMatrix{var"#s30"}, <:Number} where var"#s30"<:(Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar})}Compute phylogeny constraints from asset returns in a prior result using a phylogeny constraint estimator.
phylogeny_constraints delegates to the asset-returns variant by extracting X from pr (or rd if provided and cle_pr is false).
Arguments
plc: Phylogeny constraint estimator.pr: Prior result or returns result object.rd: Optional returns result (used whencle_pr = false).cle_pr: Iftrue, use asset returns frompr; otherwise, userd. Default istrue.kwargs...: Additional keyword arguments passed to the estimator.
Returns
- Phylogeny constraint result.
Related
sourcePortfolioOptimisers.AbstractCentralityConstraint Type
abstract type AbstractCentralityConstraint <: AbstractConstraintEstimatorAbstract supertype for all centrality-based constraint types in PortfolioOptimisers.jl.
All concrete types implementing centrality-based portfolio constraints should be subtypes of AbstractCentralityConstraint.
Related
sourcePortfolioOptimisers.CentralityConstraint Type
struct CentralityConstraint{__T_A, __T_B, __T_comp} <: AbstractCentralityConstraintEstimator for generating centrality-based portfolio constraints.
CentralityConstraint constructs constraints based on asset centrality measures within a phylogeny or network structure. It wraps a centrality estimator A, a VectorToScalarMeasure measure or threshold B, and a comparison operator comp ComparisonOperator.
Fields
A: Centrality estimator.B: Centrality threshold or reduction measure.comp: Comparison operator for the centrality constraint.
Constructors
CentralityConstraint(;
A::CentralityEstimator = CentralityEstimator(),
B::Num_VecToScaM = MinValue(),
comp::ComparisonOperator = <=
) -> CentralityConstraintExamples
julia> CentralityConstraint()
CentralityConstraint
A ┼ CentralityEstimator
│ pl ┼ NetworkEstimator
│ │ ce ┼ PortfolioOptimisersCovariance
│ │ │ ce ┼ Covariance
│ │ │ │ me ┼ SimpleExpectedReturns
│ │ │ │ │ w ┴ nothing
│ │ │ │ ce ┼ GeneralCovariance
│ │ │ │ │ ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
│ │ │ │ │ w ┴ nothing
│ │ │ │ alg ┴ FullMoment()
│ │ │ mp ┼ MatrixProcessing
│ │ │ │ pdm ┼ Posdef
│ │ │ │ │ alg ┼ UnionAll: NearestCorrelationMatrix.Newton
│ │ │ │ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ │ │ │ dn ┼ nothing
│ │ │ │ dt ┼ nothing
│ │ │ │ alg ┼ nothing
│ │ │ │ order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)
│ │ de ┼ Distance
│ │ │ power ┼ nothing
│ │ │ alg ┴ CanonicalDistance()
│ │ alg ┼ KruskalTree
│ │ │ args ┼ Tuple{}: ()
│ │ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ │ n ┴ Int64: 1
│ ct ┼ DegreeCentrality
│ │ kind ┼ Int64: 0
│ │ kwargs ┴ @NamedTuple{}: NamedTuple()
B ┼ MinValue()
comp ┴ typeof(<=): <=Related
sourcePortfolioOptimisers.VecCC Type
const VecCC = AbstractVector{<:CentralityConstraint}Alias for a vector of CentralityConstraint objects.
Represents a collection of centrality-based portfolio constraints.
Related
sourcePortfolioOptimisers.CC_VecCC Type
const CC_VecCC = Union{<:CentralityConstraint, <:VecCC}Alias for a single or vector of CentralityConstraint objects.
Matches either a single CentralityConstraint or a vector of them (VecCC).
Related
sourcePortfolioOptimisers.centrality_constraints Function
centrality_constraints(ccs::CC_VecCC,
X::MatNum; dims::Int = 1, kwargs...)Generate centrality-based linear constraints from one or more CentralityConstraint estimators.
centrality_constraints constructs linear constraints for portfolio optimisation based on asset centrality measures within a phylogeny or network structure. It accepts one or more CentralityConstraint estimators, computes centrality vectors for the given data matrix X, applies the specified reduction measure or threshold, and assembles the resulting constraints into a LinearConstraint object.
Arguments
ccs: A singleCentralityConstraintor a vector of such estimators.X: Data matrix of asset features or returns.dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to the centrality estimator.
Returns
lc::Option{<:LinearConstraint}: An object containing the assembled inequality and equality constraints, ornothingif no constraints are present.
Details
For each constraint, computes the centrality vector using the estimator in
cc.A.Applies the comparison operator and reduction measure or threshold in
cc.Bandcc.comp.Aggregates constraints into equality and inequality forms.
Returns
nothingif no valid constraints are generated.
Related
sourcecentrality_constraints(ccs::Option{<:LinearConstraint}, args...; kwargs...)No-op fallback for centrality-based constraint propagation.
This method returns the input LinearConstraint object or nothing unchanged. It is used to pass through an already constructed centrality-based constraint object, enabling composability and uniform interface handling in constraint generation workflows.
Arguments
ccs: An existingLinearConstraintobject ornothing.args...: Additional positional arguments (ignored).kwargs...: Additional keyword arguments (ignored).
Returns
ccs::Option{<:LinearConstraint}: The input constraint object ornothing, unchanged.
Related
sourcecentrality_constraints(
ccs::Union{CentralityConstraint, AbstractVector{<:CentralityConstraint}},
pr::Union{AbstractPriorResult, ReturnsResult};
rd,
cle_pr,
kwargs...
) -> Union{Nothing, LinearConstraint}Compute centrality constraints from asset returns in a prior result using a centrality constraint estimator.
centrality_constraints delegates to the asset-returns variant by extracting X from pr (or rd if provided and cle_pr is false).
Arguments
ccs: Centrality constraint estimator or vector thereof.pr: Prior result or returns result object.rd: Optional returns result (used whencle_pr = false).cle_pr: Iftrue, use asset returns frompr; otherwise, userd. Default istrue.kwargs...: Additional keyword arguments passed to the estimator.
Returns
- Centrality constraint result.
Related
sourcePortfolioOptimisers.AbstractPhylogenyConstraintEstimator Type
abstract type AbstractPhylogenyConstraintEstimator <: AbstractConstraintEstimatorAbstract supertype for all phylogeny-based constraint estimators in PortfolioOptimisers.jl.
All concrete and/or abstract types representing phylogeny-based constraint estimators should be subtypes of AbstractPhylogenyConstraintEstimator.
Related
PortfolioOptimisers.AbstractPhylogenyConstraintResult Type
abstract type AbstractPhylogenyConstraintResult <: AbstractConstraintResultAbstract supertype for all phylogeny-based constraint result types in PortfolioOptimisers.jl.
All concrete and/or abstract types representing the results of phylogeny-based constraint generation should be subtypes of AbstractPhylogenyConstraintResult.
Related
sourcePortfolioOptimisers.PlCE_PlC Type
const PlCE_PlC = Union{<:AbstractPhylogenyConstraintEstimator,
<:AbstractPhylogenyConstraintResult}Alias for a phylogeny constraint estimator or result.
Matches either a AbstractPhylogenyConstraintEstimator or a AbstractPhylogenyConstraintResult. Used internally for dispatch in phylogeny-based constraint generation.
Related
sourcePortfolioOptimisers.VecPlC Type
const VecPlC = AbstractVector{<:AbstractPhylogenyConstraintResult}Alias for a vector of phylogeny constraint results.
Represents a collection of AbstractPhylogenyConstraintResult objects.
Related
sourcePortfolioOptimisers.PlC_VecPlC Type
const PlC_VecPlC = Union{<:AbstractPhylogenyConstraintResult, <:VecPlC}Alias for a single or vector of phylogeny constraint results.
Matches either a single AbstractPhylogenyConstraintResult or a vector of them (VecPlC).
Related
sourcePortfolioOptimisers.VecPlCE_PlC Type
const VecPlCE_PlC = AbstractVector{<:PlCE_PlC}Alias for a vector of phylogeny constraint estimators or results.
Represents a collection of PlCE_PlC objects, enabling batch processing of multiple phylogeny-based constraint estimators or results.
Related
sourcePortfolioOptimisers.PlCE_PhC_VecPlCE_PlC Type
const PlCE_PhC_VecPlCE_PlC = Union{<:PlCE_PlC, <:VecPlCE_PlC}Alias for a single or vector of phylogeny constraint estimators or results.
Matches either a single PlCE_PlC or a vector of them (VecPlCE_PlC). Used internally for dispatch on phylogeny-based constraint generation that accepts one or many constraints.
Related
sourcePortfolioOptimisers.MatNum_PhRMatNum Type
const MatNum_PhRMatNum = Union{<:PhylogenyResult{<:MatNum}, <:MatNum}Alias for a phylogeny result wrapping a numeric matrix or a numeric matrix directly.
Used internally to accept either a PhylogenyResult containing a numeric matrix or a plain numeric matrix as a constraint matrix input.
Related
sourcePortfolioOptimisers.Lc_CC_VecCC Type
const Lc_CC_VecCC = Union{<:CC_VecCC, <:LinearConstraint}Alias for a centrality constraint or linear constraint.
Matches either a CentralityConstraint, a vector of them, or a LinearConstraint. Used for dispatch in centrality-based constraint generation that also accepts linear constraints.
Related
sourcePortfolioOptimisers._validate_length_integer_phylogeny_constraint_B Function
_validate_length_integer_phylogeny_constraint_B(alg::Option{<:Integer},
B::VecNum)Validate that the length of the vector B does not exceed the integer value alg.
This function is used internally to ensure that the number of groups or allocations specified by B does not exceed the allowed maximum defined by alg. If the validation fails, a DomainError is thrown.
Arguments
alg:Nothing: No validation is performed.Integer: Specifying the maximum allowed length forB.
B: Vector of integers representing group sizes or allocations.
Returns
nothing.
Validation
- Throws
DomainErroriflength(B) > alg.
Details
Checks that
length(B) <= alg.Used in the construction and validation of integer phylogeny constraints.
Related
sourcePortfolioOptimisers.validate_length_integer_phylogeny_constraint_B Function
validate_length_integer_phylogeny_constraint_B(cle::ClustersEstimator, B::VecNum)
validate_length_integer_phylogeny_constraint_B(args...)Validate that the length of the vector B does not exceed the maximum allowed by the clustering estimator cle.
Arguments
cle: Clustering estimator containing algorithm and maximum group information.B: Vector of integers representing group sizes or allocations.args...: No validation is performed.
Returns
nothing.
Validation
Throws
DomainErroriflength(B) > cle.onc.max_k(whenmax_kis set).Calls internal
_validate_length_integer_phylogeny_constraint_Bfor further checks.
Details
Checks if
cle.onc.max_kis set and validateslength(B)accordingly.Delegates to
_validate_length_integer_phylogeny_constraint_Bfor algorithm-specific validation.Used in the construction and validation of integer phylogeny constraints.
Related
source