Skip to content
18

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 [5].

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

Abstract Gerber covariance types

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

PortfolioOptimisers.BaseGerberCovariance Type
julia
abstract type BaseGerberCovariance <: AbstractCovarianceEstimator

Abstract supertype for all Gerber covariance estimators in PortfolioOptimisers.jl.

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

source
PortfolioOptimisers.GerberCovarianceAlgorithm Type
julia
abstract type GerberCovarianceAlgorithm <: AbstractMomentAlgorithm

Abstract supertype for all Gerber covariance algorithm types in PortfolioOptimisers.jl.

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

source

Concrete Gerber covariance implementations

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

PortfolioOptimisers.Gerber0 Type
julia
struct Gerber0 <: GerberCovarianceAlgorithm

Implements the original Gerber covariance algorithm.

Constructors

julia
Gerber0() -> Gerber0

Examples

julia
julia> Gerber0()
Gerber0()

Related

References

source
PortfolioOptimisers.Gerber1 Type
julia
struct Gerber1 <: GerberCovarianceAlgorithm

Implements the first variant of the Gerber covariance algorithm.

Constructors

julia
Gerber1() -> Gerber1

Examples

julia
julia> Gerber1()
Gerber1()

Related

References

source
PortfolioOptimisers.Gerber2 Type
julia
struct Gerber2 <: GerberCovarianceAlgorithm

Implements the second variant of the Gerber covariance algorithm.

Constructors

julia
Gerber2() -> Gerber2

Examples

julia
julia> Gerber2()
Gerber2()

Related

References

source
PortfolioOptimisers.GerberCovariance Type
julia
struct GerberCovariance{__T_ve, __T_me, __T_pdm, __T_t, __T_alg} <: BaseGerberCovariance

A flexible container type for configuring and applying Gerber covariance estimators in PortfolioOptimisers.jl.

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

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

Keywords correspond to the struct's fields.

Validation

  • 0 <= t.

Examples

julia
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

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

Implements the original Gerber correlation algorithm.

Mathematical definition

Let U,D{0,1}T×N be indicator matrices with:

Uti=1[xtitσi],Dti=1[xtitσi].

Define H=UD and V=U+D. The Gerber0 correlation is:

ρ^=(HH)(VV).

Where:

  • xti: Return of asset i at time t.

  • t: Threshold parameter.

  • σi: Standard deviation of asset i.

  • T: Number of observations.

  • N: Number of assets.

  • : Element-wise division.

Arguments

  • ce: Gerber covariance estimator.. Configured with the Gerber0 algorithm.

  • X: Data matrix observations × features if the dims keyword does not exist or dims = 1, features × observations when dims = 2.

  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

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

Details

The algorithm proceeds as follows:

  • For each entry in X, compute two Boolean matrices:

    • U: Entries where X .>= ce.t * sd.

    • D: Entries where X .<= -ce.t * sd.

  • Compute UmD = U - D and UpD = U + D.

  • The Gerber correlation is given by (UmD' * UmD) ⊘ (UpD' * UpD).

  • The result is projected to the nearest positive definite matrix using posdef!.

Related

References

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

Implements the first variant of the Gerber correlation algorithm.

Mathematical definition

Let U,D,N{0,1}T×N be indicator matrices with:

Uti=1[xtitσi],Dti=1[xtitσi],Nti=1[tσi<xti<tσi].

Define H=UD. The Gerber1 correlation is:

ρ^=(HH)(T11NN).

Where:

  • xti: Return of asset i at time t.

  • t: Threshold parameter.

  • σi: Standard deviation of asset i.

  • T: Number of observations.

  • N: Number of assets.

  • : Element-wise division.

  • 1: Vector of ones.

Arguments

  • ce: Gerber covariance estimator.. Configured with the Gerber1 algorithm.

  • X: Data matrix observations × features if the dims keyword does not exist or dims = 1, features × observations when dims = 2.

  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

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

Details

The algorithm proceeds as follows:

  • For each entry in X, compute three Boolean matrices:

    • U: Entries where X .>= ce.t * sd.

    • D: Entries where X .<= -ce.t * sd.

    • N: Entries where X in (-ce.t * sd, ce.t * sd) (i.e., neither up nor down).

  • Compute UmD = U - D.

  • The Gerber1 correlation is given by (UmD' * UmD) ⊘ (T .- (N' * N)), where T is the number of observations.

  • The result is projected to the nearest positive definite matrix using posdef!.

Related

References

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

Implements the second variant of the Gerber correlation algorithm.

Mathematical definition

Let U,D{0,1}T×N be indicator matrices with:

Uti=1[xtitσi],Dti=1[xtitσi].

Define H=(UD)(UD) and h=diag(H). The Gerber2 correlation is:

ρ^=H(hh).

Where:

  • xti: Return of asset i at time t.

  • t: Threshold parameter.

  • σi: Standard deviation of asset i.

  • diag(): Diagonal of a matrix.

  • : Element-wise division.

Arguments

  • ce: Gerber covariance estimator.. Configured with the Gerber2 algorithm.

  • X: Data matrix observations × features if the dims keyword does not exist or dims = 1, features × observations when dims = 2.

  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

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

Details

The algorithm proceeds as follows:

  • For each entry in X, compute two Boolean matrices:

    • U: Entries where X .>= ce.t * sd.

    • D: Entries where X .<= -ce.t * sd.

  • Compute the signed indicator matrix UmD = U - D.

  • Compute the raw Gerber2 matrix H = UmD' * UmD.

  • Normalise rho = H ⊘ (h * h'), where h = sqrt.(LinearAlgebra.diag(H)).

  • The result is projected to the nearest positive definite matrix using posdef!.

Related

References

source
Statistics.cov Method
julia
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 × features if the dims keyword does not exist or dims = 1, features × observations when dims = 2.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the standard deviation estimator.

Returns

  • rho: Correlation matrix features × features.

Validation

  • dims in (1, 2).

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

source
Statistics.cor Method
julia
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 × features if the dims keyword does not exist or dims = 1, features × observations when dims = 2.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the standard deviation estimator.

Returns

  • rho: Correlation matrix features × features.

Validation

  • dims in (1, 2).

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

source