Rank Covariances

PortfolioOptimisers.KendallCovarianceType
struct KendallCovariance{__T_ve} <: RankCovarianceEstimator

Measures monotonic association with Kendall's tau, counting concordant against discordant pairs.

The rank statistic is robust to outliers and to non-Gaussian data. The covariance follows from the generic fallback, which rescales the correlation matrix by the marginal standard deviations of ve.

Fields

  • ve: Variance estimator.

Constructors

KendallCovariance(;    ve::AbstractVarianceEstimator = SimpleVariance()) -> KendallCovariance

Keywords correspond to the struct's fields.

Propagated parameters

When factory is called on this type, the following @fprop-tagged fields are automatically propagated:

  • ve: Recursively updated via factory.

View parameters

When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:

Examples

julia> KendallCovariance()KendallCovariance  ve ┼ SimpleVariance     │          me ┼ SimpleExpectedReturns     │             │   w ┴ nothing     │           w ┼ nothing     │   corrected ┴ Bool: true

Related

References

  • [5] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 6.1.3, equation 6.3.
source
PortfolioOptimisers.SpearmanCovarianceType
struct SpearmanCovariance{__T_ve} <: RankCovarianceEstimator

Measures monotonic association with Spearman's rho, the Pearson correlation of the rank-transformed returns.

The rank transform is robust to outliers and to non-Gaussian data. The covariance follows from the generic fallback, which rescales the correlation matrix by the marginal standard deviations of ve.

Fields

  • ve: Variance estimator.

Constructors

SpearmanCovariance(;    ve::AbstractVarianceEstimator = SimpleVariance()) -> SpearmanCovariance

Keywords correspond to the struct's fields.

Propagated parameters

When factory is called on this type, the following @fprop-tagged fields are automatically propagated:

  • ve: Recursively updated via factory.

View parameters

When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:

Examples

julia> SpearmanCovariance()SpearmanCovariance  ve ┼ SimpleVariance     │          me ┼ SimpleExpectedReturns     │             │   w ┴ nothing     │           w ┼ nothing     │   corrected ┴ Bool: true

Related

References

  • [5] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 6.1.2, equation 6.2.
source
Statistics.corMethod
Statistics.cor(::KendallCovariance, X::MatNum; dims::Int = 1, kwargs...)

Compute the Kendall's tau rank correlation matrix using a KendallCovariance estimator.

This method computes the pairwise Kendall's tau rank correlation matrix for the input data matrix X. Kendall's tau measures the monotonic association between pairs of asset returns and is robust to outliers and non-Gaussian data.

Mathematical definition

For two asset return series $(x_1, \ldots, x_T)$ and $(y_1, \ldots, y_T)$, StatsBase.corkendall computes the tie-corrected $\tau_b$:

\[\begin{align} \hat{\tau}^b_{ij} &= \frac{C - D}{\sqrt{(n_0 - n_x)(n_0 - n_y)}}\,, \\ n_0 &= \binom{T}{2}\,, \quad n_x = \sum_{g} \binom{t_g}{2}\,, \quad n_y = \sum_{h} \binom{u_h}{2}\,. \end{align}\]

Where:

  • $\hat{\tau}^b_{ij}$: Kendall's $\tau_b$ rank correlation between assets $i$ and $j$.
  • $C$: Number of concordant pairs; a pair $(t, s)$ is concordant if $(x_t - x_s)(y_t - y_s) > 0$.
  • $D$: Number of discordant pairs; a pair $(t, s)$ is discordant if $(x_t - x_s)(y_t - y_s) < 0$.
  • $n_0$: Total number of pairs.
  • $t_g$, $u_h$: Sizes of the $g$-th group of tied $x$ values and the $h$-th group of tied $y$ values.
  • $T$: Number of observations.

Without ties, $n_x = n_y = 0$ and $\hat{\tau}^b$ reduces to $\tau_a = (C - D) / \binom{T}{2}$, which is equation 6.3 of the source. The two differ when ties are present, because the tie counts shrink the denominator.

Algorithm

  1. Orient X with dims_oriented, which transposes it when dims is 2 and refuses any other value.
  2. Return StatsBase.corkendall(X), the tie-corrected $\tau_b$ of every pair of columns. The diagonal is exactly 1, and no scaling or clamping is applied to the result.

Arguments

  • ce: Kendall's tau-based covariance estimator.
  • X: Data matrix of asset returns (observations × assets).
  • dims: Dimension along which to perform the computation.
  • kwargs...: Additional keyword arguments (currently unused).

Validation

  • dims is either 1 or 2.

Returns

  • rho::Matrix{<:Number}: Symmetric matrix of Kendall's tau rank correlation coefficients.

Examples

julia> X = [0.01 0.02; 0.03 0.04; 0.02 0.03];julia> cor(KendallCovariance(), X)2×2 Matrix{Float64}: 1.0  1.0 1.0  1.0

Related

source
Statistics.corMethod
Statistics.cor(::SpearmanCovariance, X::MatNum; dims::Int = 1, kwargs...)

Compute the Spearman's rho rank correlation matrix using a SpearmanCovariance estimator.

This method computes the pairwise Spearman's rho rank correlation matrix for the input data matrix X. Spearman's rho measures the monotonic association between pairs of asset returns and is robust to outliers and non-Gaussian data.

Mathematical definition

Spearman's $\rho$ is the Pearson correlation of the rank-transformed data. Let $\mathrm{rk}(x_t)$ denote the mid-rank of observation $x_t$ among $x_1, \ldots, x_T$, so that a group of tied values shares their average rank:

\[\begin{align} \hat{\rho}^S_{ij} &= \frac{\mathrm{cov}\!\left(\mathrm{rk}(x_{\cdot i}),\, \mathrm{rk}(x_{\cdot j})\right)}{\sigma_{\mathrm{rk}(x_{\cdot i})} \, \sigma_{\mathrm{rk}(x_{\cdot j})}}\,. \end{align}\]

Where:

  • $\hat{\rho}^S_{ij}$: Spearman's $\rho$ rank correlation between assets $i$ and $j$.
  • $T$: Number of observations.
  • $x_{ti}$: Return of asset $i$ at time $t$.
  • $\mathrm{rk}(\cdot)$: Mid-rank function.
  • $\sigma_{\mathrm{rk}(\cdot)}$: Standard deviation of the rank variable.

Without ties this equals the closed form $1 - 6 \sum_t d_t^2 / (T(T^2 - 1))$, with $d_t = \mathrm{rk}(x_{ti}) - \mathrm{rk}(x_{tj})$. The two differ when ties are present.

Algorithm

  1. Orient X with dims_oriented, which transposes it when dims is 2 and refuses any other value.
  2. Return StatsBase.corspearman(X), the Pearson correlation of the mid-ranked columns. The diagonal is exactly 1, and no scaling or clamping is applied to the result.

Arguments

  • ce: Spearman's rho-based covariance estimator.
  • X: Data matrix of asset returns (observations × assets).
  • dims: Dimension along which to perform the computation.
  • kwargs...: Additional keyword arguments (currently unused).

Validation

  • dims is either 1 or 2.

Returns

  • rho::Matrix{<:Number}: Symmetric matrix of Spearman's rho rank correlation coefficients.

Examples

julia> X = [0.01 0.02; 0.03 0.04; 0.02 0.03];julia> cor(SpearmanCovariance(), X)2×2 Matrix{Float64}: 1.0  1.0 1.0  1.0

Related

source

References

[5]
D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).