Clusters
PortfolioOptimisers.Clusters Type
struct Clusters{T1, T2, T3, T4} <: AbstractClusteringResult
res::T1
S::T2
D::T3
k::T4
endResult 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
clustering: The hierarchical clustering object.S: Similarity matrix used for clustering.D: Distance matrix used for clustering.k: Number of clusters.
Constructor
Clusters(; res::Clustering.Hclust, S::MatNum,
D::MatNum, k::Integer)Keyword arguments correspond to the fields above.
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{T1} <: AbstractOptimalNumberClustersAlgorithm
alg::T1
endAlgorithm 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 vector-to-scalar measure used to evaluate clustering quality.
Constructor
SecondOrderDifference(; alg::VectorToScalarMeasure = StandardisedValue())Keyword arguments correspond to the fields above.
Examples
julia> SecondOrderDifference()
SecondOrderDifference
alg ┼ StandardisedValue
│ mv ┼ MeanValue
│ │ w ┴ nothing
│ sv ┼ StdValue
│ │ w ┼ nothing
│ │ corrected ┴ Bool: trueRelated
sourcePortfolioOptimisers.SilhouetteScore Type
struct SilhouetteScore{T1, T2} <: AbstractOptimalNumberClustersAlgorithm
alg::T1
metric::T2
endAlgorithm 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 vector-to-scalar measure used to evaluate clustering quality.metric: The distance metric used for silhouette calculation fromDistances.jl, ornothingfor the default.
Constructor
SilhouetteScore(; alg::VectorToScalarMeasure = StandardisedValue(),
metric::Option{<:Distances.SemiMetric} = nothing)Keyword arguments correspond to the fields above.
Examples
julia> SilhouetteScore()
SilhouetteScore
alg ┼ StandardisedValue
│ mv ┼ MeanValue
│ │ w ┴ nothing
│ sv ┼ StdValue
│ │ w ┼ nothing
│ │ corrected ┴ Bool: true
metric ┴ nothingRelated
sourcePortfolioOptimisers.OptimalNumberClusters Type
struct OptimalNumberClusters{T1, T2} <: AbstractOptimalNumberClustersEstimator
max_k::T1
alg::T2
endEstimator 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 thesqrt(N), whereNis the number of assets.alg: Algorithm for selecting the optimal number of clusters. If an integer, defines the number of clusters directly.
Constructor
OptimalNumberClusters(; max_k::Option{<:Integer} = nothing,
alg::Int_ONC = SecondOrderDifference())Keyword arguments correspond to the fields above.
Validation
max_k >= 1.If
algis an integer,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{T1} <: AbstractHierarchicalClusteringAlgorithm
linkage::T1
endAlgorithm 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.
Constructor
HClustAlgorithm(; linkage::Symbol = :ward)Keyword arguments correspond to the fields above.
Examples
julia> HClustAlgorithm(; linkage = :average)
HClustAlgorithm
linkage ┴ Symbol: :averageRelated
[
AbstractHierarchicalClusteringAlgorithm]-(@ref)
PortfolioOptimisers.ClustersEstimator Type
struct ClustersEstimator{T1, T2, T3, T4} <: AbstractClustersEstimator
ce::T1
de::T2
alg::T3
onc::T4
endEstimator 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 estimator.alg: Clustering algorithm.onc: Optimal number of clusters estimator.
Constructor
ClustersEstimator(; ce::StatsBase.CovarianceEstimator = PortfolioOptimisersCovariance(),
de::AbstractDistanceEstimator = Distance(; alg = CanonicalDistance()),
alg::AbstractClustersAlgorithm = HClustAlgorithm(),
onc::AbstractOptimalNumberClustersEstimator = OptimalNumberClusters())Keyword arguments correspond to the fields above.
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
[
AbstractHierarchicalClusteringAlgorithm]-(@ref)
PortfolioOptimisers.AbstractClustersEstimator Type
abstract type AbstractClustersEstimator <: AbstractPhylogenyEstimator endAbstract 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 <: AbstractPhylogenyAlgorithm endAbstract 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.AbstractOptimalNumberClustersEstimator Type
abstract type AbstractOptimalNumberClustersEstimator <: AbstractEstimator endAbstract 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 <: AbstractAlgorithm endAbstract 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 <: AbstractPhylogenyResult endAbstract 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