Skip to content
13

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.

Related

References

source
PortfolioOptimisers.Gerber1 Type
julia
struct Gerber1 <: GerberCovarianceAlgorithm

Implements the first variant of the Gerber covariance algorithm.

Related

References

source
PortfolioOptimisers.Gerber2 Type
julia
struct Gerber2 <: GerberCovarianceAlgorithm

Implements the second variant of the Gerber covariance algorithm.

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.

Related

References

source
PortfolioOptimisers.factory Method
julia
factory(
    ce::GerberCovariance,
    w::Union{DynamicAbstractWeights, AbstractWeights}
) -> Union{GerberCovariance{<:CovarianceEstimator, <:AbstractExpectedReturnsEstimator, Nothing, <:Number, <:GerberCovarianceAlgorithm}, GerberCovariance{var"#s179", var"#s1791", Posdef{__T_alg, __T_kwargs}, <:Number, <:GerberCovarianceAlgorithm} where {var"#s179"<:CovarianceEstimator, var"#s1791"<:AbstractExpectedReturnsEstimator, __T_alg, __T_kwargs}}

Return a new GerberCovariance estimator with the specified observation weights.

Arguments

  • ce: Covariance estimator.

  • w: Optional observation weights vector observations × 1, or a concrete subtype of DynamicAbstractWeights. If nothing, the computation is unweighted.

Returns

  • ce: New covariance estimator of the same type as the argument, with the new weights applied.

Details

  • Calls factory(ce.alg, w) to update the algorithm (current algorithms do not use weights, this for future proofing).

  • Calls factory(ce.ve, w) to update the variance estimator.

  • Calls factory(ce.me, w) to update the expected returns estimator.

  • Preserves the other fields of the original estimator.

Examples

julia
julia> ce = 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()

julia> factory(ce, StatsBase.Weights([0.1, 0.2, 0.7]))
GerberCovariance
   ve ┼ SimpleVariance
      │          me ┼ SimpleExpectedReturns
      │             │   w ┴ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.1, 0.2, 0.7]
      │           w ┼ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.1, 0.2, 0.7]
      │   corrected ┴ Bool: true
   me ┼ SimpleExpectedReturns
      │   w ┴ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.1, 0.2, 0.7]
  pdm ┼ Posdef
      │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
      │   kwargs ┴ @NamedTuple{}: NamedTuple()
    t ┼ Float64: 0.5
  alg ┴ Gerber1()

Related

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

Implements the original Gerber correlation algorithm.

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.

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.

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