Gerber covariance

The Gerber statistic is a vote-based robust co-movement measure. It ignores fluctuations below a threshold while limiting the effect of extreme movements. It extends Kendall's Tau coefficient by counting the proportion of concordant and discordant movements within the window defined by the upper and lower limits [11].

Three variants have been published and all three have been implemented because each has unique characteristics [12].

Abstract Gerber covariance types

These serve as the scaffolding for defining Gerber covariance estimators and algorithms.

PortfolioOptimisers.BaseGerberCovarianceType
abstract type BaseGerberCovariance <: AbstractCovarianceEstimator

Abstract supertype for all Gerber covariance estimators.

All concrete and/or abstract types implementing Gerber covariance estimation algorithms should be subtypes of BaseGerberCovariance.

Interfaces

If moving away from the already established Gerber covariance algorithms, you must follow AbstractCovarianceEstimator to implement the entire chain.

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
  • [12] E. Flint and D. Polakow. Deconstructing the Gerber statistic. Finance Research Letters 56, 104144 (2023).
source
PortfolioOptimisers.GerberCovarianceAlgorithmType
abstract type GerberCovarianceAlgorithm <: AbstractMomentAlgorithm

Abstract supertype for all Gerber covariance algorithm types.

All concrete and/or abstract types implementing specific Gerber covariance algorithms should be subtypes of GerberCovarianceAlgorithm.

These types are used to specify the algorithm when constructing a GerberCovariance estimator.

Interfaces

If moving away from the already established Gerber covariance algorithms, you must follow AbstractCovarianceEstimator to implement the entire chain. Else you can follow the instructions and examples in GerberCovarianceAlgorithm.

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source

Concrete Gerber covariance implementations

These define the concrete implementations of the Gerber covariance estimators and algorithms.

PortfolioOptimisers.Gerber0Type
struct Gerber0 <: GerberCovarianceAlgorithm

Normalises the net co-movement vote by the observations on which both assets crossed their threshold.

The pairwise statistic is $(n_{c} - n_{d}) / (n_{c} + n_{d})$, where an observation votes only when both assets cross a threshold, concordantly for $n_{c}$ and discordantly for $n_{d}$. This is the original Gerber statistic.

Constructors

Gerber0() -> Gerber0

Examples

julia> Gerber0()Gerber0()

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
PortfolioOptimisers.Gerber1Type
struct Gerber1 <: GerberCovarianceAlgorithm

Normalises the net co-movement vote by every observation on which at least one asset crossed its threshold.

The pairwise statistic is $(n_{c} - n_{d}) / (n_{c} + n_{d} + n_{n})$. The extra term $n_{n}$ counts the observations on which exactly one of the two assets crossed, so the denominator is larger than Gerber0's and the statistic is bounded more tightly.

Constructors

Gerber1() -> Gerber1

Examples

julia> Gerber1()Gerber1()

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
PortfolioOptimisers.Gerber2Type
struct Gerber2 <: GerberCovarianceAlgorithm

Normalises the raw net co-movement vote by the geometric mean of its own diagonal.

The pairwise statistic is $h_{ij} / \sqrt{h_{ii} h_{jj}}$ with $h_{ij} = n_{c} - n_{d}$. The diagonal is therefore unit by construction, rather than by a per-pair denominator as in Gerber0 and Gerber1.

Constructors

Gerber2() -> Gerber2

Examples

julia> Gerber2()Gerber2()

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
PortfolioOptimisers.GerberCovarianceType
struct GerberCovariance{__T_ve, __T_me, __T_pdm, __T_t, __T_alg} <: BaseGerberCovariance

Configures and applies Gerber covariance estimators.

GerberCovariance encapsulates all components required for Gerber-based covariance or correlation estimation, including the variance estimator, positive definite matrix estimator, t parameter, and the specific Gerber algorithm variant.

Fields

  • ve: Variance estimator.
  • me: Expected returns estimator. Used for centering the returns.
  • pdm: Positive definite matrix estimator.
  • t: Threshold value.
  • alg: Gerber covariance algorithm.

Constructors

GerberCovariance(;    ve::StatsBase.CovarianceEstimator = SimpleVariance(),    me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(),    pdm::Option{<:AbstractPosdefEstimator} = Posdef(),    t::Number = 0.5,    alg::GerberCovarianceAlgorithm = Gerber1()) -> GerberCovariance

Keywords correspond to the struct's fields.

Validation

  • 0 <= t.

Propagated parameters

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

  • ve: Recursively updated via factory.
  • me: Recursively updated via factory.
  • alg: 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> GerberCovariance()GerberCovariance   ve ┼ SimpleVariance      │          me ┼ SimpleExpectedReturns      │             │   w ┴ nothing      │           w ┼ nothing      │   corrected ┴ Bool: true   me ┼ SimpleExpectedReturns      │   w ┴ nothing  pdm ┼ Posdef      │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton      │   kwargs ┴ @NamedTuple{}: NamedTuple()    t ┼ Float64: 0.5  alg ┴ Gerber1()

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
PortfolioOptimisers.gerber_updownFunction
gerber_updown(
    ce::GerberCovariance,
    X::AbstractMatrix{<:Union{var"#s89", var"#s88"} where {var"#s89"<:Number, var"#s88"<:AbstractJuMPScalar}},
    sd::AbstractArray{<:Union{var"#s89", var"#s88"} where {var"#s89"<:Number, var"#s88"<:AbstractJuMPScalar}}
) -> Tuple{Matrix{Bool}, Matrix{Bool}}

Build the up and down indicator matrices shared by every Gerber correlation variant.

Arguments

  • ce: Gerber covariance estimator.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

  • (U, D)::Tuple{Matrix{Bool}, Matrix{Bool}}: U[t, i] marks X[t, i] >= ce.t * sd[i], and D[t, i] marks X[t, i] <= -ce.t * sd[i].

Related

source
PortfolioOptimisers.concordance_countsFunction
concordance_counts(
    pmn::AbstractMatrix,
    ppn::AbstractMatrix
) -> Tuple{Any, Any}

Split the concordant and discordant co-movement counts out of their difference and their sum.

nconc[i, j] counts the observations on which assets i and j both crossed a threshold in the same direction. ndisc[i, j] counts the observations on which they crossed in opposite directions. A matrix product delivers the difference and the sum directly, so the two counts are recovered from those instead of by two more matrix products. The split is exact, and the reduction in comovement_ratio sees the same numerator and denominator as the matrix formula.

Arguments

  • pmn::AbstractMatrix: The difference nconc - ndisc.
  • ppn::AbstractMatrix: The sum nconc + ndisc.

Returns

  • (nconc, ndisc)::Tuple{AbstractMatrix, AbstractMatrix}: The concordant and the discordant counts.

Related

source
PortfolioOptimisers.gerberMethod
gerber(
    ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber0},
    X::MatNum,
    sd::ArrNum
) -> MatNum

Implements the original Gerber correlation algorithm.

Mathematical definition

Let $\mathbf{U}, \mathbf{D} \in \{0,1\}^{T \times N}$ be indicator matrices with:

\[\begin{align} U_{ti} &= \mathbf{1}[x_{ti} \geq t \, \sigma_i], \quad D_{ti} = \mathbf{1}[x_{ti} \leq -t \, \sigma_i]\,. \end{align}\]

Define $\mathbf{H} = \mathbf{U} - \mathbf{D}$ and $\mathbf{V} = \mathbf{U} + \mathbf{D}$. The Gerber0 correlation is:

\[\begin{align} \hat{\boldsymbol{\rho}} &= \left(\mathbf{H}^\intercal \mathbf{H}\right) \oslash \left(\mathbf{V}^\intercal \mathbf{V}\right)\,. \end{align}\]

Where:

  • $x_{ti}$: Return of asset $i$ at time $t$.
  • $t$: Threshold parameter.
  • $\sigma_i$: Standard deviation of asset $i$.
  • $T$: Number of observations.
  • $N$: Number of assets.
  • $\oslash$: Element-wise division.

Arguments

  • ce: Gerber covariance estimator.. Configured with the Gerber0 algorithm.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

  • rho::MatNum: Correlation matrix assets x assets.

Details

The algorithm proceeds as follows:

  • Build the indicator matrices U and D with gerber_updown.
  • Compute UmD = U - D and UpD = U + D.
  • Recover the concordant and discordant counts from UmD' * UmD and UpD' * UpD with concordance_counts.
  • Reduce each pair to (nconc - ndisc) / (nconc + ndisc) with comovement_ratio, which returns zero when the denominator vanishes.
  • The result is projected to the nearest positive definite matrix using posdef!.

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
PortfolioOptimisers.gerberMethod
gerber(
    ce::GerberCovariance{<:Any, <:Any, <:Any, <:Gerber1},
    X::MatNum,
    sd::ArrNum
) -> MatNum

Implements the first variant of the Gerber correlation algorithm.

Mathematical definition

Let $\mathbf{U}, \mathbf{D}, \mathbf{N} \in \{0,1\}^{T \times N}$ be indicator matrices with:

\[\begin{align} U_{ti} &= \mathbf{1}[x_{ti} \geq t \, \sigma_i], \quad D_{ti} = \mathbf{1}[x_{ti} \leq -t \, \sigma_i], \quad N_{ti} = \mathbf{1}[{-t\sigma_i < x_{ti} < t\sigma_i}]\,. \end{align}\]

Define $\mathbf{H} = \mathbf{U} - \mathbf{D}$. The Gerber1 correlation is:

\[\begin{align} \hat{\boldsymbol{\rho}} &= \left(\mathbf{H}^\intercal \mathbf{H}\right) \oslash \left(T \boldsymbol{1}\boldsymbol{1}^\intercal - \mathbf{N}^\intercal \mathbf{N}\right)\,. \end{align}\]

Where:

  • $x_{ti}$: Return of asset $i$ at time $t$.
  • $t$: Threshold parameter.
  • $\sigma_i$: Standard deviation of asset $i$.
  • $T$: Number of observations.
  • $N$: Number of assets.
  • $\oslash$: Element-wise division.
  • $\boldsymbol{1}$: Vector of ones.

Arguments

  • ce: Gerber covariance estimator.. Configured with the Gerber1 algorithm.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

  • rho::MatNum: Correlation matrix assets x assets.

Details

The algorithm proceeds as follows:

  • Build the indicator matrices U and D with gerber_updown.
  • Compute the neutral matrix Nt, whose entries mark X in (-ce.t * sd, ce.t * sd) (i.e., neither up nor down).
  • Compute UmD = U - D.
  • Split the denominator T .- (Nt' * Nt) into the observations on which both assets crossed a threshold and the observations on which exactly one of them crossed.
  • Recover the concordant and discordant counts from UmD' * UmD and the both-crossed count with concordance_counts.
  • Reduce each pair to (nconc - ndisc) / (nconc + ndisc + nneut) with comovement_ratio, which returns zero when the denominator vanishes.
  • The result is projected to the nearest positive definite matrix using posdef!.

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
PortfolioOptimisers.gerberMethod
gerber(
    ce::GerberCovariance{<:Any, <:Any, <:Any, <:Gerber2},
    X::MatNum,
    sd::ArrNum
) -> MatNum

Implements the second variant of the Gerber correlation algorithm.

Mathematical definition

Let $\mathbf{U}, \mathbf{D} \in \{0,1\}^{T \times N}$ be indicator matrices with:

\[\begin{align} U_{ti} &= \mathbf{1}[x_{ti} \geq t \, \sigma_i], \quad D_{ti} = \mathbf{1}[x_{ti} \leq -t \, \sigma_i]\,. \end{align}\]

Define $\mathbf{H} = (\mathbf{U} - \mathbf{D})^\intercal (\mathbf{U} - \mathbf{D})$ and $\boldsymbol{h} = \sqrt{\mathrm{diag}(\mathbf{H})}$. The Gerber2 correlation is:

\[\begin{align} \hat{\boldsymbol{\rho}} &= \mathbf{H} \oslash (\boldsymbol{h} \boldsymbol{h}^\intercal)\,. \end{align}\]

Where:

  • $x_{ti}$: Return of asset $i$ at time $t$.
  • $t$: Threshold parameter.
  • $\sigma_i$: Standard deviation of asset $i$.
  • $\mathrm{diag}(\cdot)$: Diagonal of a matrix.
  • $\oslash$: Element-wise division.

Arguments

  • ce: Gerber covariance estimator.. Configured with the Gerber2 algorithm.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

  • rho::MatNum: Correlation matrix assets x assets.

Details

The algorithm proceeds as follows:

  • Build the indicator matrices U and D with gerber_updown.
  • Compute the signed indicator matrix UmD = U - D.
  • Compute the raw Gerber2 matrix rho = UmD' * UmD.
  • Normalise rho by the geometric mean of its diagonal with standardise_comovement!, which clamps the diagonal roots away from zero.
  • The result is projected to the nearest positive definite matrix using posdef!.

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
Statistics.covMethod
Statistics.cov(
    ce::GerberCovariance,
    X::MatNum;
    dims::Int = 1,
    kwargs...
) -> MatNum

Compute the Gerber covariance matrix using the algorithm specified in ce.alg.

Arguments

  • ce: Gerber covariance estimator.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • dims: Dimension along which to perform the computation.
  • kwargs...: Additional keyword arguments passed to the standard deviation estimator.

Validation

  • dims in (1, 2).

Returns

  • rho: Correlation matrix assets × assets.

Details

  • Computes the standard deviation vector for each asset using the estimator's variance estimator.
  • Demeans the returns with ce.me and demean_returns.
  • Computes the Gerber correlation matrix using the Gerber algorithm in ce.alg.
  • Rescales the Gerber correlation matrix to a covariance matrix by multiplying with the standard deviation vector outer product.

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source
Statistics.corMethod
Statistics.cor(
    ce::GerberCovariance,
    X::MatNum;
    dims::Int = 1,
    kwargs...
) -> MatNum

Compute the Gerber correlation matrix using the algorithm specified in ce.alg.

Arguments

  • ce: Gerber covariance estimator.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • dims: Dimension along which to perform the computation.
  • kwargs...: Additional keyword arguments passed to the standard deviation estimator.

Validation

  • dims in (1, 2).

Returns

  • rho: Correlation matrix assets × assets.

Details

  • Computes the standard deviation vector for each asset using the estimator's variance estimator.
  • Demeans the returns with ce.me and demean_returns.
  • Computes the Gerber correlation matrix using the Gerber algorithm in ce.alg.

Related

References

  • [11] S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
source

References

[11]
S. Gerber, H. Markowitz, P. Ernst, Y. Miao, P. Sargen and others. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
[12]
E. Flint and D. Polakow. Deconstructing the Gerber statistic. Finance Research Letters 56, 104144 (2023).