Distance

PortfolioOptimisers.DistanceType
struct 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

source
PortfolioOptimisers.distanceMethod
distance(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.

  • 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

source
PortfolioOptimisers.distanceMethod
distance(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 with LogDistance 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

source
PortfolioOptimisers.distanceMethod
distance(::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 the CanonicalDistance 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

source
PortfolioOptimisers.distanceMethod
distance(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 with VariationInfoDistance algorithm.
  • ::Any: Placeholder for compatibility, ignored.
  • X: Data matrix (observations × features).
  • dims: Dimension along which to compute the distance. If 2, the data is transposed.
  • kwargs...: Additional keyword arguments, ignored.

Validation

  • dims is either 1 or 2.

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

source
PortfolioOptimisers.distanceMethod
distance(::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.

  • 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 using StatsBase.cov2cor.

Related

source
PortfolioOptimisers.cor_and_distMethod
cor_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 either 1 or 2.

Returns

  • (rho::Matrix{<:Real}, dist::Matrix{<:Real}): Tuple of correlation matrix and distance matrix.

Related

source