Clusters
PortfolioOptimisers.Clusters Type
struct Clusters{__T_res, __T_S, __T_D, __T_k} <: AbstractClusteringResultResult type for hierarchical clustering in PortfolioOptimisers.jl.
Clusters stores the output of a hierarchical clustering algorithm, including the clustering object, similarity and distance matrices, and the number of clusters.
Fields
res: Clustering result.S: Similarity matrixD: Distance matrixk: Optimal number of clusters.
Constructors
Clusters(;
res::ClTypes,
S::MatNum,
D::MatNum,
k::Integer
) -> ClustersKeywords correspond to the struct's fields.
Validation
!isempty(S).!isempty(D).size(S) == size(D)`.
k >= 1.
Related
sourcePortfolioOptimisers.clusterise Method
clusterise(cle::AbstractClusteringResult, args...; kwargs...)Return the clustering result as-is.
This function provides a generic interface for extracting or processing clustering results. By default, it simply returns the provided clustering result object unchanged. This allows for consistent downstream handling of clustering results in PortfolioOptimisers.jl workflows.
Arguments
cle::AbstractClusteringResult: The clustering result object.args...: Additional positional arguments, ignored.kwargs...: Additional keyword arguments, ignored.
Returns
- The input
cleobject.
Related
sourcePortfolioOptimisers.SecondOrderDifference Type
struct SecondOrderDifference{__T_alg} <: AbstractOptimalNumberClustersAlgorithmAlgorithm type for estimating the optimal number of clusters using the second-order difference method.
The SecondOrderDifference algorithm selects the optimal number of clusters by maximizing the second-order difference of a clustering evaluation metric (such as within-cluster sum of squares or silhouette score) across different cluster counts. This approach helps identify the "elbow" point in the metric curve.
Fields
alg: The measure used to evaluate clustering quality.
Constructors
SecondOrderDifference(;
alg::Num_VecToScaM = StandardisedValue()
) -> SecondOrderDifferenceKeywords correspond to the struct's fields.
Examples
julia> SecondOrderDifference()
SecondOrderDifference
alg ┼ StandardisedValue
│ mv ┼ MeanValue
│ │ w ┴ nothing
│ sv ┼ StdValue
│ │ w ┼ nothing
│ │ corrected ┴ Bool: trueRelated
sourcePortfolioOptimisers.SilhouetteScore Type
struct SilhouetteScore{__T_alg} <: AbstractOptimalNumberClustersAlgorithmAlgorithm type for estimating the optimal number of clusters using the standardised silhouette score.
SilhouetteScore selects the optimal number of clusters by maximizing the silhouette score, which measures how well each object lies within its cluster compared to other clusters. The score can be computed using different distance metrics.
Fields
alg: The measure used to evaluate clustering quality.
Constructors
SilhouetteScore(;
alg::Num_VecToScaM = StandardisedValue()
) -> SilhouetteScoreKeywords correspond to the struct's fields.
Examples
julia> SilhouetteScore()
SilhouetteScore
alg ┼ StandardisedValue
│ mv ┼ MeanValue
│ │ w ┴ nothing
│ sv ┼ StdValue
│ │ w ┼ nothing
│ │ corrected ┴ Bool: trueRelated
sourcePortfolioOptimisers.OptimalNumberClusters Type
struct OptimalNumberClusters{__T_max_k, __T_alg} <: AbstractOptimalNumberClustersEstimatorEstimator type for selecting the optimal number of clusters in PortfolioOptimisers.jl.
OptimalNumberClusters encapsulates the configuration for determining the optimal number of clusters, including the maximum allowed clusters and the algorithm used for selection.
Fields
max_k: Maximum number of clusters to consider. Ifnothing, computed as thefloor(Int, sqrt(features)).alg: Algorithm for selecting the optimal number of clusters. If an integer, defines the number of clusters directly.
Constructors
OptimalNumberClusters(;
max_k::Option{<:Integer} = nothing,
alg::Int_ONC = SecondOrderDifference()
) -> OptimalNumberClustersKeywords correspond to the struct's fields.
Validation
If
max_kis notnothing,max_k >= 1.If
algis notnothing,alg >= 1.
Examples
julia> OptimalNumberClusters(; max_k = 10)
OptimalNumberClusters
max_k ┼ Int64: 10
alg ┼ SecondOrderDifference
│ alg ┼ StandardisedValue
│ │ mv ┼ MeanValue
│ │ │ w ┴ nothing
│ │ sv ┼ StdValue
│ │ │ w ┼ nothing
│ │ │ corrected ┴ Bool: trueRelated
sourcePortfolioOptimisers.HClustAlgorithm Type
struct HClustAlgorithm{__T_linkage} <: AbstractHierarchicalClusteringAlgorithmAlgorithm type for hierarchical clustering in PortfolioOptimisers.jl.
HClustAlgorithm specifies the linkage method used for hierarchical clustering, such as :ward, :single, :complete, or :average.
Fields
linkage: Linkage method for hierarchical clustering fromClustering.jl.
Constructors
HClustAlgorithm(;
linkage::Symbol = :ward
) -> HClustAlgorithmKeywords correspond to the struct's fields.
Examples
julia> HClustAlgorithm(; linkage = :average)
HClustAlgorithm
linkage ┴ Symbol: :averageRelated
sourcePortfolioOptimisers.ClustersEstimator Type
struct ClustersEstimator{__T_ce, __T_de, __T_alg, __T_onc} <: AbstractClustersEstimatorEstimator type for clustering in PortfolioOptimisers.jl.
ClustersEstimator encapsulates all configuration required for clustering, including the covariance estimator, distance estimator, res algorithm, and optimal number of clusters estimator.
Fields
ce: Covariance estimator.de: Distance matrix estimator.alg: Clustering algorithm.onc: Optimal number of clusters estimator.
Constructors
ClustersEstimator(;
ce::StatsBase.CovarianceEstimator = PortfolioOptimisersCovariance(),
de::AbstractDistanceEstimator = Distance(; alg = CanonicalDistance()),
alg::AbstractClustersAlgorithm = HClustAlgorithm(),
onc::AbstractOptimalNumberClustersEstimator = OptimalNumberClusters()
) -> ClustersEstimatorKeywords correspond to the struct's fields.
Examples
julia> ClustersEstimator()
ClustersEstimator
ce ┼ PortfolioOptimisersCovariance
│ ce ┼ Covariance
│ │ me ┼ SimpleExpectedReturns
│ │ │ w ┴ nothing
│ │ ce ┼ GeneralCovariance
│ │ │ ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
│ │ │ w ┴ nothing
│ │ alg ┴ Full()
│ mp ┼ DenoiseDetoneAlgMatrixProcessing
│ │ pdm ┼ Posdef
│ │ │ alg ┼ UnionAll: NearestCorrelationMatrix.Newton
│ │ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ │ dn ┼ nothing
│ │ dt ┼ nothing
│ │ alg ┼ nothing
│ │ order ┴ DenoiseDetoneAlg()
de ┼ Distance
│ power ┼ nothing
│ alg ┴ CanonicalDistance()
alg ┼ HClustAlgorithm
│ linkage ┴ Symbol: :ward
onc ┼ OptimalNumberClusters
│ max_k ┼ nothing
│ alg ┼ SecondOrderDifference
│ │ alg ┼ StandardisedValue
│ │ │ mv ┼ MeanValue
│ │ │ │ w ┴ nothing
│ │ │ sv ┼ StdValue
│ │ │ │ w ┼ nothing
│ │ │ │ corrected ┴ Bool: trueRelated
PortfolioOptimisers.AbstractClustersEstimator Type
abstract type AbstractClustersEstimator <: AbstractPhylogenyEstimatorAbstract supertype for all clustering estimator types in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing clustering-based estimation algorithms should be subtypes of AbstractClustersEstimator.
Related
sourcePortfolioOptimisers.AbstractClustersAlgorithm Type
abstract type AbstractClustersAlgorithm <: AbstractPhylogenyAlgorithmAbstract supertype for all clustering algorithm types in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing specific clustering algorithms should be subtypes of AbstractClustersAlgorithm.
Related
sourcePortfolioOptimisers.AbstractHierarchicalClusteringAlgorithm Type
abstract type AbstractHierarchicalClusteringAlgorithm <: AbstractClustersAlgorithmAbstract supertype for all hierarchical clustering algorithm types in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing hierarchical clustering algorithms (such as hierarchical agglomerative clustering or DBHT) should be subtypes of AbstractHierarchicalClusteringAlgorithm.
Related
sourcePortfolioOptimisers.AbstractNonHierarchicalClusteringAlgorithm Type
abstract type AbstractNonHierarchicalClusteringAlgorithm <: AbstractClustersAlgorithmAbstract supertype for all non-hierarchical clustering algorithm types in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing non-hierarchical clustering algorithms (such as k-means) should be subtypes of AbstractNonHierarchicalClusteringAlgorithm.
Related
sourcePortfolioOptimisers.AbstractOptimalNumberClustersEstimator Type
abstract type AbstractOptimalNumberClustersEstimator <: AbstractEstimatorAbstract supertype for all optimal number of clusters estimator types in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing algorithms to estimate the optimal number of clusters should be subtypes of AbstractOptimalNumberClustersEstimator.
Related
sourcePortfolioOptimisers.AbstractOptimalNumberClustersAlgorithm Type
abstract type AbstractOptimalNumberClustersAlgorithm <: AbstractAlgorithmAbstract supertype for all optimal number of clusters algorithm types in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing specific algorithms for determining the optimal number of clusters should be subtypes of AbstractOptimalNumberClustersAlgorithm.
Related
sourcePortfolioOptimisers.AbstractClusteringResult Type
abstract type AbstractClusteringResult <: AbstractPhylogenyResultAbstract supertype for all clustering result types in PortfolioOptimisers.jl.
All concrete and/or abstract types representing the result of a clustering estimation should be subtypes of AbstractClusteringResult.
Related
source