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.BaseGerberCovariance — Type
abstract type BaseGerberCovariance <: AbstractCovarianceEstimatorAbstract 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
PortfolioOptimisers.GerberCovarianceAlgorithm — Type
abstract type GerberCovarianceAlgorithm <: AbstractMomentAlgorithmAbstract 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).
Concrete Gerber covariance implementations
These define the concrete implementations of the Gerber covariance estimators and algorithms.
PortfolioOptimisers.Gerber0 — Type
struct Gerber0 <: GerberCovarianceAlgorithmNormalises 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() -> Gerber0Examples
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).
PortfolioOptimisers.Gerber1 — Type
struct Gerber1 <: GerberCovarianceAlgorithmNormalises 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() -> Gerber1Examples
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).
PortfolioOptimisers.Gerber2 — Type
struct Gerber2 <: GerberCovarianceAlgorithmNormalises 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() -> Gerber2Examples
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).
PortfolioOptimisers.GerberCovariance — Type
struct GerberCovariance{__T_ve, __T_me, __T_pdm, __T_t, __T_alg} <: BaseGerberCovarianceConfigures 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()) -> GerberCovarianceKeywords 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 viafactory.me: Recursively updated viafactory.alg: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
ve: Recursively viewed viaport_opt_view.me: Recursively viewed viaport_opt_view.
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
BaseGerberCovarianceGerberCovarianceAlgorithmStatsBase.CovarianceEstimatorSimpleVariancePosdefGerber0Gerber1Gerber2factoryport_opt_view
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).
PortfolioOptimisers.gerber_updown — Function
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 matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.sd: Standard deviation vector ofX, shaped to be consistent withX.
Returns
(U, D)::Tuple{Matrix{Bool}, Matrix{Bool}}:U[t, i]marksX[t, i] >= ce.t * sd[i], andD[t, i]marksX[t, i] <= -ce.t * sd[i].
Related
PortfolioOptimisers.concordance_counts — Function
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 differencenconc - ndisc.ppn::AbstractMatrix: The sumnconc + ndisc.
Returns
(nconc, ndisc)::Tuple{AbstractMatrix, AbstractMatrix}: The concordant and the discordant counts.
Related
PortfolioOptimisers.gerber — Method
gerber(
ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber0},
X::MatNum,
sd::ArrNum
) -> MatNumImplements 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 theGerber0algorithm.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.sd: Standard deviation vector ofX, shaped to be consistent withX.
Returns
rho::MatNum: Correlation matrixassets x assets.
Details
The algorithm proceeds as follows:
- Build the indicator matrices
UandDwithgerber_updown. - Compute
UmD = U - DandUpD = U + D. - Recover the concordant and discordant counts from
UmD' * UmDandUpD' * UpDwithconcordance_counts. - Reduce each pair to
(nconc - ndisc) / (nconc + ndisc)withcomovement_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).
PortfolioOptimisers.gerber — Method
gerber(
ce::GerberCovariance{<:Any, <:Any, <:Any, <:Gerber1},
X::MatNum,
sd::ArrNum
) -> MatNumImplements 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 theGerber1algorithm.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.sd: Standard deviation vector ofX, shaped to be consistent withX.
Returns
rho::MatNum: Correlation matrixassets x assets.
Details
The algorithm proceeds as follows:
- Build the indicator matrices
UandDwithgerber_updown. - Compute the neutral matrix
Nt, whose entries markX 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' * UmDand the both-crossed count withconcordance_counts. - Reduce each pair to
(nconc - ndisc) / (nconc + ndisc + nneut)withcomovement_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).
PortfolioOptimisers.gerber — Method
gerber(
ce::GerberCovariance{<:Any, <:Any, <:Any, <:Gerber2},
X::MatNum,
sd::ArrNum
) -> MatNumImplements 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 theGerber2algorithm.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.sd: Standard deviation vector ofX, shaped to be consistent withX.
Returns
rho::MatNum: Correlation matrixassets x assets.
Details
The algorithm proceeds as follows:
- Build the indicator matrices
UandDwithgerber_updown. - Compute the signed indicator matrix
UmD = U - D. - Compute the raw Gerber2 matrix
rho = UmD' * UmD. - Normalise
rhoby the geometric mean of its diagonal withstandardise_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).
Statistics.cov — Method
Statistics.cov(
ce::GerberCovariance,
X::MatNum;
dims::Int = 1,
kwargs...
) -> MatNumCompute the Gerber covariance matrix using the algorithm specified in ce.alg.
Arguments
ce: Gerber covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 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 matrixassets × assets.
Details
- Computes the standard deviation vector for each asset using the estimator's variance estimator.
- Demeans the returns with
ce.meanddemean_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
GerberCovariancegerber(ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber0}, X::MatNum, sd::ArrNum)gerber(ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber1}, X::MatNum, sd::ArrNum)gerber(ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber2}, X::MatNum, sd::ArrNum)demean_returnscor(ce::GerberCovariance, X::MatNum; dims::Int = 1, kwargs...)
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).
Statistics.cor — Method
Statistics.cor(
ce::GerberCovariance,
X::MatNum;
dims::Int = 1,
kwargs...
) -> MatNumCompute the Gerber correlation matrix using the algorithm specified in ce.alg.
Arguments
ce: Gerber covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 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 matrixassets × assets.
Details
- Computes the standard deviation vector for each asset using the estimator's variance estimator.
- Demeans the returns with
ce.meanddemean_returns. - Computes the Gerber correlation matrix using the Gerber algorithm in
ce.alg.
Related
GerberCovariancegerber(ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber0}, X::MatNum, sd::ArrNum)gerber(ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber1}, X::MatNum, sd::ArrNum)gerber(ce::GerberCovariance{<:Any, <:Any, <:Any, <:Any, <:Gerber2}, X::MatNum, sd::ArrNum)demean_returnscov(ce::GerberCovariance, X::MatNum; dims::Int = 1, kwargs...)
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).
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).