Distance
PortfolioOptimisers.Distance Type
struct Distance{T1, T2} <: AbstractDistanceEstimator
power::T1
alg::T2
endIf power is not nothing, computes the generalised distance estimator.
where
Fields
power: Optional integer power to which the base correlation or distance matrix is raised.alg: The base distance algorithm.
Constructor
Distance(; power::Union{Nothing, <:Integer} = nothing,
alg::AbstractDistanceAlgorithm = SimpleDistance())Keyword arguments correspond to the fields above.
Validation
- If
poweris notnothing, thenpower >= 1.
Examples
julia> Distance()
Distance
power ┼ nothing
alg ┴ SimpleDistance()Related
PortfolioOptimisers.distance Method
distance(de::Distance{<:Any,
<:Union{<:SimpleDistance, <:SimpleAbsoluteDistance, <:LogDistance,
<:CorrelationDistance, <:CanonicalDistance}},
ce::StatsBase.CovarianceEstimator, X::AbstractMatrix; dims::Int = 1, kwargs...)This method computes the correlation matrix using the provided covariance estimator ce and data matrix X, which is used to compute the distance matrix based on the specified distance algorithm in de.
Arguments
de: Distance estimator.de::Distance{<:Any, <:SimpleDistance}: Use theSimpleDistancealgorithm.de::Distance{<:Any, <:SimpleAbsoluteDistance}: Use theSimpleAbsoluteDistancealgorithm.de::Distance{<:Any, <:LogDistance}: Use theLogDistancealgorithm.de::Distance{<:Any, <:CorrelationDistance}: Use theCorrelationDistancealgorithm.de::Distance{<:Any, <:CanonicalDistance}: Use theCanonicalDistancealgorithm.
ce: Covariance estimator.X: Data matrix (observations × features).dims: Dimension along which to compute the correlation.kwargs...: Additional keyword arguments passed to the correlation computation.
Returns
dist::Matrix{<:Real}: Matrix of pairwise distances.
Related
PortfolioOptimisers.distance Method
distance(de::Distance{<:Any, <:LogDistance},
ce::Union{<:LowerTailDependenceCovariance,
<:PortfolioOptimisersCovariance{<:LowerTailDependenceCovariance, <:Any}},
X::AbstractMatrix; dims::Int = 1, kwargs...)Compute the log-distance matrix from a Lower Tail Dependence (LTD) covariance estimator and data matrix.
Arguments
de::Distance{<:Any, <:LogDistance}: Distance estimator withLogDistancealgorithm.ce: LTD covariance estimator or a PortfolioOptimisersCovariance wrapping an LTD estimator.X: Data matrix (observations × features).dims: Dimension along which to compute the correlation.kwargs...: Additional keyword arguments passed to the correlation computation.
Returns
dist::Matrix{<:Real}: Matrix of pairwise log-distances.
Related
sourcePortfolioOptimisers.distance Method
distance(de::Distance{<:Any, <:VariationInfoDistance}, ::Any, X::AbstractMatrix;
dims::Int = 1, kwargs...)Compute the variation of information (VI) distance matrix from a data matrix.
Arguments
de::Distance{<:Any, <:VariationInfoDistance}: Distance estimator withVariationInfoDistancealgorithm.::Any: Covariance estimator placeholder for API compatibility (ignored).X: Data matrix (observations × features).dims: Dimension along which to compute the distance. If2, the data is transposed.kwargs...: Additional keyword arguments (ignored).
Validation
dimsis either1or2.
Returns
dist::Matrix{<:Real}: Matrix of pairwise variation of information distances.
Details
The number of bins and normalisation are taken from the
VariationInfoDistancealgorithm fields.If
dims == 2, the data matrix is transposed before computation.
Related
sourcePortfolioOptimisers.distance Method
distance(::Distance{<:Any,
<:Union{<:SimpleDistance, <:SimpleAbsoluteDistance, <:LogDistance,
<:CorrelationDistance, <:CanonicalDistance}},
rho::AbstractMatrix, args...; kwargs...)Compute the distance matrix from a correlation or covariance matrix.
If the input rho is a covariance matrix, it is converted to a correlation matrix which is used to compute the distance matrix using the specified distance algorithm in de.
Arguments
de: Distance estimator.de::Distance{<:Any, <:SimpleDistance}: Use theSimpleDistancealgorithm.de::Distance{<:Any, <:SimpleAbsoluteDistance}: Use theSimpleAbsoluteDistancealgorithm.de::Distance{<:Any, <:LogDistance}: Use theLogDistancealgorithm.de::Distance{<:Any, <:CorrelationDistance}: Use theCorrelationDistancealgorithm.de::Distance{<:Any, <:CanonicalDistance}: Use theCanonicalDistancealgorithm.
rho: Correlation or covariance matrix.args...: Additional arguments (ignored).kwargs...: Additional keyword arguments.
Returns
dist::Matrix{<:Real}: Matrix of pairwise Euclidean distances.
Details
- If
rhois a covariance matrix, it is converted to a correlation matrix usingStatsBase.cov2cor.
Related
PortfolioOptimisers.cor_and_dist Method
cor_and_dist(de::Distance{<:Any,
<:Union{<:SimpleDistance, <:SimpleAbsoluteDistance, <:LogDistance,
<:LogDistance, <:VariationInfoDistance,
<:CorrelationDistance}}, Nothing,
ce::StatsBase.CovarianceEstimator, X::AbstractMatrix; dims::Int = 1, kwargs...)Compute and return the correlation and distance matrices. The distance matrix depends on the combination of distance and covariance estimators (see distance).
Arguments
de: Distance estimator.ce: Covariance estimator.X: Data matrix (observations × features).dims: Dimension along which to compute the correlation.kwargs...: Additional keyword arguments passed to the correlation computation.
Validation
dims in (1, 2).
Returns
(rho::Matrix{<:Real}, dist::Matrix{<:Real}): Tuple of correlation matrix and distance matrix.
Related
sourcePortfolioOptimisers.distance Method
distance(de::Distance{<:Any, <:CanonicalDistance},
ce::Union{<:MutualInfoCovariance,
<:PortfolioOptimisersCovariance{<:MutualInfoCovariance, <:Any},
<:LowerTailDependenceCovariance, <:PortfolioOptimisersCovariance{<:LowerTailDependenceCovariance, <:Any},
<:DistanceCovariance,
<:PortfolioOptimisersCovariance{<:DistanceCovariance, <:Any}},
X::AbstractMatrix; dims::Int = 1, kwargs...)Compute the canonical distance matrix using the covariance estimator and data matrix. The method selects the appropriate distance algorithm based on the type of covariance estimator provided (see CanonicalDistance).
Arguments
de::Distance{<:Any, <:CanonicalDistance}: Distance estimator using theCanonicalDistancealgorithm.ce::MutualInfoCovariance: Mutual information covariance estimator.X: Data matrix (observations × features).dims: Dimension along which to compute the distance.kwargs...: Additional keyword arguments.
Returns
dist::Matrix{<:Real}: Matrix of pairwise canonical distances.
Related
source