Base clustering optimisation: private API
PortfolioOptimisers.BaseClusteringOptimisationEstimator — Type
abstract type BaseClusteringOptimisationEstimator <: BaseOptimisationEstimatorAbstract supertype for base clustering optimisation estimators.
These are intermediate configuration types used in hierarchical/clustering optimisation pipelines.
Related
PortfolioOptimisers.ClusteringOptimisationEstimator — Type
abstract type ClusteringOptimisationEstimator <: NonFiniteAllocationOptimisationEstimatorAbstract supertype for clustering-based portfolio optimisation estimators.
Clustering optimisation estimators use asset clustering to decompose the portfolio optimisation problem. Subtypes include HRP, HERC, and SCHRP.
Related
PortfolioOptimisers.assert_clustering_universe — Function
assert_clustering_universe(
clr::AbstractClusteringResult,
N::Integer
)
Assert that a clustering covers exactly the universe the optimisation is about to allocate over.
clusterise returns a fitted AbstractClusteringResult unchanged, so a caller who states one instead of an estimator states the leaf order as well. Nothing slices that order. Under an Investable Mask, or inside a subset or a nested view, the universe below the call is narrower than the one the caller clustered, and the leaf order would index the wrong columns. The weights would still come back, and they would be wrong, so the mismatch is refused where it is first visible.
A fixed clustering under a changing universe is stated as a ClustersEstimator, which refits per window and always matches.
Algorithm
- Read one cluster label per asset with
assignments. - Throw a
DimensionMismatchwhen their count is notN.
Arguments
clr: Clustering result, fitted or just built.N: Number of assets the optimisation runs on, after the reduction.
Validation
- The clustering must carry one label per asset of the reduced universe.
Returns
nothing.
Related
PortfolioOptimisers.hierarchical_optimiser_td_defaults — Function
hierarchical_optimiser_td_defaults(
) -> @NamedTuple{pe::EmpiricalPrior{PortfolioOptimisersCovariance{Covariance{SimpleExpectedReturns{Nothing, Nothing, Nothing}, GeneralCovariance{SimpleCovariance, Nothing, Nothing}, FullMoment, Nothing, Nothing, Nothing}, MatrixProcessing{Posdef{UnionAll, @NamedTuple{}}, Nothing, Nothing, Nothing, NTuple{4, Symbol}}, Nothing}, SimpleExpectedReturns{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing}, cle::ClustersEstimator{PortfolioOptimisersCovariance{Covariance{SimpleExpectedReturns{Nothing, Nothing, Nothing}, GeneralCovariance{SimpleCovariance, Nothing, Nothing}, FullMoment, Nothing, Nothing, Nothing}, MatrixProcessing{Posdef{UnionAll, @NamedTuple{}}, Nothing, Nothing, Nothing, NTuple{4, Symbol}}, Nothing}, Distance{Nothing, CanonicalDistance}, HClustAlgorithm{Symbol}, OptimalNumberClusters{Nothing, SecondOrderDifference{StandardisedValue{MeanValue{Nothing}, StdValue{Nothing, Bool}}}}}, wb::WeightBounds{Float64, Float64}, wf::IterativeWeightFinaliser{Int64}}
Return the static defaults of the HierarchicalOptimiser fields that may hold a TimeDependent.
Shared by the constructor's test-substitution pass and time_dependent_field_defaults, so the fold-less value of a field is declared once. Fields whose static default is nothing are omitted.
Related
PortfolioOptimisers.is_time_dependent — Method
is_time_dependent(
opt::ClusteringOptimisationEstimator
) -> Any
Return true if the estimator's own problem-definition fields, the inner optimiser, or the fallback carry time-dependent constraints.
PortfolioOptimisers.reset_time_dependent_estimator — Method
reset_time_dependent_estimator(
opt::ClusteringOptimisationEstimator
) -> NestedClustered
Replace time-dependent constraints with their static defaults, both on the estimator's own fields and by recursing into the inner optimiser and fallback.
NestedClustered overrides this with its own method resetting its own fields and inner estimators.
PortfolioOptimisers.assert_internal_optimiser — Method
assert_internal_optimiser(opt)Assert that the inner (cluster-level) optimiser is valid for use in NCO.
Checks that the inner optimiser does not use pre-computed prior results or regression results, since these must be re-estimated for each cluster during NCO.
Arguments
opt: Inner optimisation estimator.
Returns
nothingon success; throws anArgumentErrorotherwise.
Related
PortfolioOptimisers.unitary_expected_risks — Method
unitary_expected_risks(r::OptimisationRiskMeasure, X::MatNum,
fees::Option{<:Fees} = nothing) -> VectorCompute the expected risk of each asset held alone.
The $i$-th entry is the risk of the portfolio whose weight vector is one in position $i$ and zero everywhere else, so the result has one entry per asset, not per cluster. For Variance the vector is the diagonal of the covariance matrix. The hierarchical optimisers invert this vector to build a naive risk parity allocation inside a cluster.
Arguments
r: Risk measure, already resolved byfactory.X: Asset return matrix, observations by assets.fees: Fees to charge against each unit portfolio, ornothing.
Returns
rk::Vector: Expected risk of each asset held alone, of lengthsize(X, 2).
Related
PortfolioOptimisers.unitary_expected_risks! — Method
unitary_expected_risks!(wk::VecNum, rk::VecNum, r::OptimisationRiskMeasure,
X::MatNum, fees::Option{<:Fees} = nothing) -> NothingWrite the expected risk of each asset held alone into rk.
The in-place form of unitary_expected_risks, for a caller that reuses one buffer across several risk measures.
Arguments
wk: Scratch weight vector, of lengthsize(X, 2). It must arrive all zero, and it leaves all zero: each iteration raises one entry to one and lowers it again.rk: Output risk vector, of lengthsize(X, 2). It is overwritten in full.r: Risk measure, already resolved byfactory.X: Asset return matrix, observations by assets.fees: Fees to charge against each unit portfolio, ornothing.
Returns
nothing. The result isrk.
Related