Distance
PortfolioOptimisers.Distance
— Typestruct Distance{T1} <: AbstractDistanceEstimator
alg::T1
end
Distance estimator for portfolio optimization.
Fields
alg
: The distance algorithm.
Constructor
Distance(; alg::AbstractDistanceAlgorithm = SimpleDistance())
Keyword arguments correspond to the fields above.
Examples
julia> Distance()
Distance
alg | SimpleDistance()
Related
PortfolioOptimisers.distance
— Methoddistance(de::Distance{<: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{<:SimpleDistance}
: Use theSimpleDistance
algorithm.de::Distance{<:SimpleAbsoluteDistance}
: Use theSimpleAbsoluteDistance
algorithm.de::Distance{<:LogDistance}
: Use theLogDistance
algorithm.de::Distance{<:CorrelationDistance}
: Use theCorrelationDistance
algorithm.de::Distance{<:CanonicalDistance}
: Use theCanonicalDistance
algorithm.
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
— Methoddistance(de::Distance{<:LogDistance},
ce::Union{<:LTDCovariance,
<:PortfolioOptimisersCovariance{<:LTDCovariance, <:Any}},
X::AbstractMatrix; dims::Int = 1, kwargs...)
Compute the log-distance matrix from a Lower Tail Dependence (LTD) covariance estimator and data matrix.
Arguments
::Distance{<:LogDistance}
: Distance estimator withLogDistance
algorithm.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
PortfolioOptimisers.distance
— Methoddistance(::Distance{<:CanonicalDistance},
ce::Union{<:MutualInfoCovariance,
<:PortfolioOptimisersCovariance{<:MutualInfoCovariance, <:Any},
<:LTDCovariance, <:PortfolioOptimisersCovariance{<:LTDCovariance, <: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
::Distance{<:CanonicalDistance}
: Distance estimator using theCanonicalDistance
algorithm.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
PortfolioOptimisers.distance
— Methoddistance(de::Distance{<:VariationInfoDistance}, ::Any, X::AbstractMatrix; dims::Int = 1,
kwargs...)
Compute the variation of information (VI) distance matrix from a data matrix.
Arguments
de::Distance{<:VariationInfoDistance}
: Distance estimator withVariationInfoDistance
algorithm.::Any
: Placeholder for 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
dims
is either1
or2
.
Returns
dist::Matrix{<:Real}
: Matrix of pairwise variation of information distances.
Details
- The number of bins and normalisation are taken from the
VariationInfoDistance
algorithm fields. - If
dims == 2
, the data matrix is transposed before computation.
Related
PortfolioOptimisers.distance
— Methoddistance(::Distance{<: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{<:SimpleDistance}
: Use theSimpleDistance
algorithm.de::Distance{<:SimpleAbsoluteDistance}
: Use theSimpleAbsoluteDistance
algorithm.de::Distance{<:LogDistance}
: Use theLogDistance
algorithm.de::Distance{<:CorrelationDistance}
: Use theCorrelationDistance
algorithm.de::Distance{<:CanonicalDistance}
: Use theCanonicalDistance
algorithm.
rho
: Correlation or covariance matrix.args...
: Additional arguments (ignored).kwargs...
: Additional keyword arguments.
Returns
dist::Matrix{<:Real}
: Matrix of pairwise Euclidean distances.
Details
- If
rho
is a covariance matrix, it is converted to a correlation matrix usingStatsBase.cov2cor
.
Related
PortfolioOptimisers.cor_and_dist
— Methodcor_and_dist(de::Distance, 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
is either1
or2
.
Returns
(rho::Matrix{<:Real}, dist::Matrix{<:Real})
: Tuple of correlation matrix and distance matrix.
Related