Skip to content
13

Gerber Information Quality Covariance

PortfolioOptimisers.BaseGerberIQCovariance Type
julia
abstract type BaseGerberIQCovariance <: BaseGerberCovariance

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

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

Related

References

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

Abstract supertype for all Gerber Information Quality covariance estimation algorithms in PortfolioOptimisers.jl.

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

Related

References

source
PortfolioOptimisers.clamp_gerber_iq_n Function
julia
clamp_gerber_iq_n(
    kind::GerberIQCovarianceAlgorithm,
    args...
) -> PartialGerberIQ{<:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number}

No-op for Gerber Information Quality covariance estimation algorithms that do not need their noise suppression parameters clamped.

Returns

  • kind: The input kind instance.

Related

source
julia
clamp_gerber_iq_n(
    alg::PartialGerberIQ,
    _::Gerber2
) -> PartialGerberIQ{<:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number}

Clamps the values of the off-diagonal elements of the covariance matrix for the PartialGerberIQ template when using the Gerber2 algorithm to ensure positive definiteness.

Arguments

Details

  • Clamps off-diagonal elements to be at most equal to the geometric mean of its adjacent diagonal elements.

  • This affects n7 and n8.

Related

References

source
julia
clamp_gerber_iq_n(
    alg::FullGerberIQ,
    _::Gerber2
) -> FullGerberIQ{_A, _B, _C, _D, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number, <:Number} where {_A, _B, _C, _D}

Clamps the values of the off-diagonal elements of the covariance matrix for the FullGerberIQ template when using the Gerber2 algorithm to ensure positive definiteness.

Arguments

Details

  • Clamps off-diagonal elements to be at most equal to the geometric mean of its adjacent diagonal elements.

  • This affects n7, n8, n14, and n17.

Related

References

source
PortfolioOptimisers.GerberIQEpsEstimator Type
julia
abstract type GerberIQEpsEstimator <: AbstractEstimator

Abstract supertype for all temporal lookback and delay Gerber Information Quality parameter estimators in PortfolioOptimisers.jl.

All concrete and/or abstract types implementing Gerber Information Quality parameter estimators should be subtypes of GerberIQEpsEstimator.

Related

References

source
PortfolioOptimisers.GerberIQEps Type
julia
const GerberIQEps = Union{<:Number, Function, <:GerberIQEpsEstimator}

A type alias for the union of Number, Function, and GerberIQEpsEstimator used for Gerber Information Quality lookback and delay parameter definitions.

Related

References

source
PortfolioOptimisers.gerber_iq_eps Function
julia
gerber_iq_eps(e::Number, ::MatNum) -> Number
gerber_iq_eps(e::Function, X::MatNum) -> Number
gerber_iq_eps(e::Option{<:GerberIQEpsEstimator}, X::MatNum) -> Number

Computes or returns the Gerber Information Quality delay parameter e, potentially using X as an input.

Arguments

  • e: The delay parameter estimator, function or value for use in the decay equation.

    • ::Number: Use the number as-is.

    • ::Function: A function which takes the data matrix X as an argument and returns a Number.

    • ::Option{<:GerberIQEpsEstimator}: Fallback returning round(Int, T - T / N), where T and N are the number of rows and columns of X respectively.

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

Returns

  • tau::Number: The lookback parameter for use in the decay equation.

References

source
PortfolioOptimisers.GerberIQGammaEstimator Type
julia
abstract type GerberIQGammaEstimator <: AbstractEstimator

Abstract supertype for Gerber IQ estimators for tuning the strength of the lookback decay.

All concrete and/or abstract types implementing Gerber Information Quality parameter estimators should be subtypes of GerberIQGammaEstimator.

Related

References

source
PortfolioOptimisers.GerberIQGamma Type
julia
const GerberIQGamma = Union{<:Number, Function, <:GerberIQGammaEstimator}

A type alias for the union of Number, Function, and GerberIQGammaEstimator used for Gerber Information Quality temporal decay parameter definitions.

Related

References

source
PortfolioOptimisers.gerber_iq_gamma Function
julia
gerber_iq_gamma(y::Number, ::MatNum) -> Number
gerber_iq_gamma(y::Function, X::MatNum) -> Number
gerber_iq_gamma(y::Option{<:GerberIQGammaEstimator}, X::MatNum) -> Number

Computes or returns the Gerber Information Quality decay strength parameter y, potentially using X as an input.

Arguments

  • y: The decay strength parameter estimator, function or value for use in the decay equation.

    • ::Number: Use the number as-is.

    • ::Function: A function which takes the data matrix X as an argument and returns a Number.

    • ::Option{<:GerberIQGammaEstimator}: Fallback returning log(2) / size(X, 2).

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

Returns

  • gamma::Number: The decay strength parameter for use in the decay equation.

References

source
PortfolioOptimisers.GerberIQScalerEstimator Type
julia
abstract type GerberIQScalerEstimator <: AbstractEstimator

Abstract supertype for Gerber IQ estimators for scaling the threshold parameters for defining significant co-movements.

All concrete and/or abstract types implementing threshold scalers for Gerber Information Quality parameter estimators should be subtypes of GerberIQScalerEstimator.

Related

References

source
PortfolioOptimisers.GerberIQScaler Type
julia
const GerberIQScaler = Union{Function, <:GerberIQScalerEstimator}

A type alias for the union of Function, and GerberIQScalerEstimator used for scaling the threshold parameters for defining significant co-movements in Gerber Information Quality.

Related

References

source
PortfolioOptimisers.AssetVolatilityGerberIQScaler Type
julia
struct AssetVolatilityGerberIQScaler <: GerberIQScalerEstimator

Scales the threshold parameters using the individual asset volatilities.

Related

References

source
PortfolioOptimisers.gerber_iq_scaling Function
julia
gerber_iq_scaling(sca::AssetVolatilityGerberIQScaler, sdi::Number, sdj::Number) -> (Number, Number)
gerber_iq_scaling(sca::Function, sdi::Number, sdj::Number) -> (Number, Number)
gerber_iq_scaling(sca::Option{<:GerberIQScalerEstimator}, sdi::Number, sdj::Number) -> (Number, Number)

Computes or returns the threshold scaling parameters for defining significant co-movements in Gerber Information Quality.

Arguments

  • sca: The scaling estimator to use.
    • ::AssetVolatilityGerberIQScaler: Returns the input sdi and sdj as-is. This lets each asset scale according to its own volatility.

    • ::Option{<:GerberIQScalerEstimator}: Fallback returning the mean of sdi and sdj twice so each asset is scaled according to the mean of the two asset volatilities. Overloading this with a custom GerberIQScalerEstimator allows for custom scaling behavior.

    • ::Function: Custom scaling function that takes sdi and sdj as arguments and returns the scaled values.

Returns

  • scai::Number: The scaled value for sdi.

  • scaj::Number: The scaled value for sdj.

References

source
PortfolioOptimisers.GerberIQDecayEstimator Type
julia
abstract type GerberIQDecayEstimator <: AbstractEstimator

Abstract supertype for Gerber IQ estimators for scaling the threshold parameters for defining significant co-movements.

All concrete and/or abstract types implementing threshold scalers for Gerber Information Quality parameter estimators should be subtypes of GerberIQDecayEstimator.

Interfaces

In order to implement a new Gerber IQ decay estimator which will work seamlessly with the library, subtype GerberIQDecayEstimator with all necessary parameters as part of the struct, and implement the following methods:

Regenerate Decay

  • PortfolioOptimisers.regenerate_decay(decay::GerberIQDecayEstimator, X::AbstractMatrix) -> GerberIQDecayEstimator: Fallback for automatically computing the decay parameters based on the input data X.

Arguments

  • decay: The decay estimator to regenerate.

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

Returns

  • decay::GerberIQDecayEstimator: A new concrete instance of the subtype of GerberIQDecayEstimator with the decay parameters generated from the input data X.

Functor

  • (decay::GerberIQDecayEstimator)(T::Number, k::Number) -> Number: Evaluate the decay estimator for observation k out of T.

Arguments

  • T::Number: The total number of observations.

  • k::Number: The current observation index.

Returns

  • d::Number: The decay value for observation k out of T.

Examples

We can create a dummy Gerber IQ decay estimator as follows:

julia
julia> struct GaussianDecay{T} <: PortfolioOptimisers.GerberIQDecayEstimator
           a::T
           function GaussianDecay(a::Union{Nothing, <:Number})
               if isa(a, Number)
                   @assert(a >= 0)
               end
               return new{typeof(a)}(a)
           end
       end

julia> function GaussianDecay(; a::Union{Nothing, <:Number} = nothing)
           return GaussianDecay(a)
       end
GaussianDecay

julia> function PortfolioOptimisers.regenerate_decay(decay::GaussianDecay{<:Number},
                                                     ::AbstractMatrix)
           return decay
       end

julia> function PortfolioOptimisers.regenerate_decay(decay::GaussianDecay{Nothing},
                                                     X::AbstractMatrix)
           T = size(X, 1)
           return GaussianDecay(; a = inv(log(T)))
       end

julia> function (decay::GaussianDecay)(T::Number, k::Number)
           m = T - k + 1
           return exp(-m^2 / (2 * decay.a^2))
       end

julia> cor(GerberIQCovariance(; decay = GaussianDecay()), [1.0 2.0; 0.3 0.7; 0.5 1.1])
2×2 Matrix{Float64}:
 1.0  1.0
 1.0  1.0

julia> cov(GerberIQCovariance(; decay = GaussianDecay()), [1.0 2.0; 0.3 0.7; 0.5 1.1])
2×2 Matrix{Float64}:
 0.13      0.240069
 0.240069  0.443333

Related

References

source
PortfolioOptimisers.ExpGerberIQDecay Type
julia
struct ExpGerberIQDecay{__T_e, __T_y} <: GerberIQDecayEstimator

A concrete type for exponential Gerber IQ temporal decay.

Fields

  • e: Waiting period before the decay starts.

  • y: Decay rate parameter.

Constructors

julia
ExpGerberIQDecay(e::Option{<:GerberIQEps} = nothing,
                 y::Option{<:GerberIQGamma} = nothing)

Keywords correspond to the struct's fields.

Functors

julia
(decay::ExpGerberIQDecay)(T::Number, k::Number) -> Number

Implements the exponential decay for Gerber IQ covariance.

!!! Warning

julia
The functor is not meant to be called directly unless all parameters are numeric. Otherwise, call [`regenerate_decay`](@ref) first.
d=exp[ymax(0,Tke)]

Where:

  • T: Is the number of observations.

  • k: Is the current index.

  • e: Parameter in the instance of ExpGerberIQDecay.

  • y: Parameter in the instance of ExpGerberIQDecay.

  • d: Is the decay factor.

Arguments

  • T: Number of observations.

  • k: Current time index.

Returns

  • d: The decay factor.

Examples

julia
julia> ExpGerberIQDecay()
ExpGerberIQDecay
  e ┼ nothing
  y ┴ nothing

Related

References

source
PortfolioOptimisers.regenerate_decay Function
julia
regenerate_decay(decay::ExpGerberIQDecay, X::AbstractMatrix) -> ExpGerberIQDecay
regenerate_decay(decay::GerberIQDecayEstimator, X::AbstractMatrix) -> ExpGerberIQDecay

Automatically sets the decay parameters based on the input data X.

Arguments

  • decay: The decay estimator to regenerate.

    • ::ExpGerberIQDecay: If both parameters are numeric, returns the input, otherwise returns a new ExpGerberIQDecay with the regenerated parameters.

    • ::GerberIQDecayEstimator: Fallback for automatically setting the decay parameters e, and y based on the input data X, using gerber_iq_eps and gerber_iq_gamma with nothing as the first input. Custom subtypes of GerberIQDecayEstimator should implement this method, else they default to the fallback.

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

Returns

  • decay::ExpGerberIQDecay: With parameters based on X.

Details

Related

References

source
PortfolioOptimisers.BasicGerberIQ Type
julia
struct BasicGerberIQ{__T_d, __T_n} <: GerberIQCovarianceAlgorithm

Implements the basic Gerber IQ covariance template. Divides the comovement data into regions and applies the co-movement compression to co-movements falling within each region. Co-movements within the dashed regions may or may not be included depending on the GerberIQ algorithm used. Co-movements within the central region are always ignored.

Fields

  • d: Significance threshold parameter.

  • n: Comovement compression parameter.

Constructors

julia
BasicGerberIQ(; d::Number = 2.0, n::Number = 0.5)

Keywords correspond to the struct's fields.

Validation

Details

The diagram shows a visual representation of the regions defined by BasicGerberIQ. In this case c = 1 and d = 3.

  • The dashed lines indicate the limits of the areas where movements are considered small.

  • Only the Gerber1 algorithm takes these regions into account as part of the neutral count.

  • The region where co-movements are considered insignificant in both axes (square around r0) are always ignored.

  • Single weight lines indicate zero delimiters.

  • The double weight lines indicate areas where movements are considered significant.

  • Co-movements within each region are weighed according to their labels.

julia
            4 ┬─────┰───────────┬─────┬─────┬───────────┰─────┐
     ┌────    │  1  ┃    n^2    ╎     │     ╎    n^21
  d ─┤      3 ┾━━━━━╋━━━━━━━━━━━┿━━━━━┿━━━━━┿━━━━━━━━━━━╋━━━━━┥
     └────    │     ┃           ╎     │     ╎           ┃     │
            2 ┤ n^2 ┃     n     ╎     │     ╎     n     ┃ n^2
              │     ┃           ╎     │     ╎           ┃     │
     ┌────  1 ┼╌╌╌╌╌╂╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┴╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╂╌╌╌╌╌┤
     │        │     ┃           ╎           ╎           ┃     │
 2c ─┤ r_j  0 ┼─────╂───────────┤    r0     ├───────────╂─────┤
     │        │     ┃           ╎           ╎           ┃     │
     └──── -1 ┼╌╌╌╌╌╂╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┬╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╂╌╌╌╌╌┤
              │     ┃           ╎     │     ╎           ┃     │
           -2 ┤ n^2 ┃     n     ╎     │     ╎     n     ┃ n^2
     ┌────    │     ┃           ╎     │     ╎           ┃     │
  d ─┤     -3 ┾━━━━━╋━━━━━━━━━━━┿━━━━━┿━━━━━┿━━━━━━━━━━━╋━━━━━┥
     └────    │  1  ┃    n^2    ┊     │     ╎    n^21
           -4 ┼─────╀─────┬─────┼─────┼─────┼─────┬─────╀─────┤
             -4    -3    -2    -1     0     1     2     3     4
                                     r_i
                 │     │        │           │        │     │
                 └──┬──┘        └─────┬─────┘        └──┬──┘
                    d                2c                 d

Examples

julia
julia> BasicGerberIQ()
BasicGerberIQ
  d ┼ Float64: 2.0
  n ┴ Float64: 0.5

Related

References

source
PortfolioOptimisers.PartialGerberIQ Type
julia
struct PartialGerberIQ{__T_dcp, __T_dcn, __T_ddp, __T_ddn, __T_n1, __T_n2, __T_n3, __T_n4, __T_n5, __T_n6, __T_n7, __T_n8, __T_n9, __T_n10} <: GerberIQCovarianceAlgorithm

Fields

  • dcp: Positive concordant movement threshold parameter.

  • dcn: Negative concordant movement threshold parameter.

  • ddp: Discordant movement threshold parameter, positive in r_i, negative in r_j.

  • ddn: Discordant movement threshold parameter, negative in r_i, positive in r_j.

  • n1: Noise suppression parameter for small positive concordant movements.

  • n2: Noise suppression parameter for small negative concordant movements.

  • n3: Noise suppression parameter for small discordant movements.

  • n4: Noise suppression parameter for large positive concordant movements.

  • n5: Noise suppression parameter for large negative concordant movements.

  • n6: Noise suppression parameter for large discordant movements.

  • n7: Noise suppression parameter for positive concordant movements where one axis has a large movement and the other is small.

  • n8: Noise suppression parameter for negative concordant movements where one axis has a large movement and the other is small.

  • n9: Noise suppression parameter for discordant movements where one axis has a large movement and the other is small for the region between ddn and zero.

  • n10: Noise suppression parameter for discordant movements where one axis has a large movement and the other is small for the region between ddp and zero.

Constructors

julia
PartialGerberIQ(; dcp::Number = 2.0, dcn::Number = dcp, ddp::Number = dcp,
                  ddn::Number = dcp, n1::Number = 0.5, n2::Number = n1,
                  n3::Number = n1, n4::Number = 1.0, n5::Number = n4,
                  n6::Number = n4, n7::Number = sqrt(n1 * n4),
                  n8::Number = sqrt(n2 * n5), n9::Number = sqrt(n3 * n6),
                  n10::Number = sqrt(n3 * n6))

Keywords correspond to the struct's fields.

Validation

Details

The diagram shows a visual representation of the regions defined by PartialGerberIQ. In this case c = 1, dcp = 2, ddn = 2, ddp = 3, and dcn = 3.

  • The dashed lines indicate the limits of the areas where movements are considered small.

  • Only the Gerber1 algorithm takes these regions into account as part of the neutral count.

  • The region where co-movements are considered insignificant in both axes (square around r0) are always ignored.

  • Single weight lines indicate zero delimiters.

  • The double weight lines indicate areas where movements are considered significant.

  • Co-movements within each region are weighed according to their labels.

julia
                         ddn                     dcp
                       ┌──┴──┐                 ┌──┴──┐
                       │     │                 │     │
            4 ┬───────────┰─────┬─────┬─────┬─────┰───────────┐
     ┌────    │    n6     ┃ n9  ╎     │     ╎     ┃           │
ddp ─┤      3 ┾━━━━━━━━━━━╋━━━━━┿━━━━━┥     ╎ n7  ┃    n4     │
     └────    │           ┃     ╎     │     ╎     ┃           │ ────┐
            2 ┤    n10    ┃ n3  ╎     ┝━━━━━┿━━━━━╋━━━━━━━━━━━┥     ├─ dcp
              │           ┃     ╎     │     ╎ n1  ┃    n7     │ ────┘
     ┌────  1 ┼╌╌╌╌╌╌╌╌╌╌╌╂╌╌╌╌╌┼╌╌╌╌╌┴╌╌╌╌╌┼╌╌╌╌╌╂╌╌╌╌╌╌╌╌╌╌╌┤
     │        │           ┃     ╎           ╎     ┃           │
 2c ─┤ r_j  0 ┼─────┰─────┸─────┤    r0     ├─────┸─────┰─────┤
     │        │     ┃           ╎           ╎           ┃     │
     └──── -1 ┼╌╌╌╌╌╂╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┬╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╂╌╌╌╌╌┤
              │     ┃           ╎     │     ╎    n3     ┃ n9  │ ────┐
           -2 ┤ n8  ┃    n2     ╎     ┝━━━━━┿━━━━━━━━━━━╋━━━━━┥     ├─ ddn
     ┌────    │     ┃           ╎     │     ╎           ┃     │ ────┘
dcn ─┤     -3 ┾━━━━━╋━━━━━━━━━━━┿━━━━━┥     ╎    n10    ┃ n6  │
     └────    │ n5  ┃    n8     ╎     │     ╎           ┃     │
           -4 ┼─────╀─────┬─────┼─────┼─────┼─────┬─────╀─────┤
             -4    -3    -2    -1     0     1     2     3     4
                                     r_i
                 │     │        │           │        │     │
                 └──┬──┘        └─────┬─────┘        └──┬──┘
                   dcn               2c                ddp

Examples

julia
julia> PartialGerberIQ()
PartialGerberIQ
  dcp ┼ Float64: 2.0
  dcn ┼ Float64: 2.0
  ddp ┼ Float64: 2.0
  ddn ┼ Float64: 2.0
   n1 ┼ Float64: 0.5
   n2 ┼ Float64: 0.5
   n3 ┼ Float64: 0.5
   n4 ┼ Float64: 1.0
   n5 ┼ Float64: 1.0
   n6 ┼ Float64: 1.0
   n7 ┼ Float64: 0.7071067811865476
   n8 ┼ Float64: 0.7071067811865476
   n9 ┼ Float64: 0.7071067811865476
  n10 ┴ Float64: 0.7071067811865476

Related

References

source
PortfolioOptimisers.FullGerberIQ Type
julia
struct FullGerberIQ{__T_dp1, __T_dp2, __T_dn1, __T_dn2, __T_n1, __T_n2, __T_n3, __T_n4, __T_n5, __T_n6, __T_n7, __T_n8, __T_n9, __T_n10, __T_n11, __T_n12, __T_n13, __T_n14, __T_n15, __T_n16, __T_n17, __T_n18, __T_n19, __T_n20, __T_n21} <: GerberIQCovarianceAlgorithm

Fields

  • dp1: Threshold for larger positive co-movements.

  • dp2: Threshold for smaller positive co-movements.

  • dn1: Threshold for larger negative co-movements.

  • dn2: Threshold for smaller negative co-movements.

  • n1: Threshold for small positive concordant co-movements.

  • n2: Threshold for small negative concordant co-movements.

  • n3: Threshold for small discordant co-movements.

  • n4: Threshold for moderate positive concordant co-movements.

  • n5: Threshold for moderate negative concordant co-movements.

  • n6: Threshold for moderate discordant co-movements.

  • n7: Threshold for small and moderate positive concordant co-movements.

  • n8: Threshold for small and moderate negative concordant co-movements.

  • n9: Threshold for small and moderate discordant co-movements.

  • n10: Threshold for moderate and small discordant co-movements.

  • n11: Threshold for large positive concordant co-movements.

  • n12: Threshold for large negative concordant co-movements.

  • n13: Threshold for large discordant co-movements.

  • n14: Threshold for moderate and large positive concordant co-movements.

  • n15: Threshold for small and large positive concordant co-movements.

  • n16: Threshold for small and large negative concordant co-movements.

  • n17: Threshold for moderate and large positive concordant co-movements.

  • n18: Threshold for small and large discordant co-movements.

  • n19: Threshold for moderate and large discordant co-movements.

  • n20: Threshold for large and moderate discordant co-movements.

  • n21: Threshold for large and small discordant co-movements.

Constructors

julia
FullGerberIQ(; dp1::Number = 2.0, dp2::Number = dp1, dn1::Number = dp1,
               dn2::Number = dp1, n1::Number = 0.5, n2::Number = n1, n3::Number = n1,
               n4::Number = 0.75, n5::Number = n4, n6::Number = n4,
               n7::Number = sqrt(n1 * n4), n8::Number = sqrt(n2 * n5),
               n9::Number = sqrt(n3 * n6), n10::Number = sqrt(n3 * n6),
               n11::Number = 1.0, n12::Number = n11, n13::Number = n11,
               n14::Number = sqrt(n4 * n11), n15::Number = sqrt(n7 * n14),
               n17::Number = sqrt(n5 * n12), n16::Number = sqrt(n8 * n17),
               n19::Number = sqrt(n6 * n13), n18::Number = sqrt(n9 * n19),
               n20::Number = sqrt(n6 * n13), n21::Number = sqrt(n10 * n20))

Keywords correspond to the struct's fields.

Validation

Details

The diagram shows a visual representation of the regions defined by PartialGerberIQ. In this case c = 1, dp2 = 2, dn2 = 2, dp1 = 3, and dn1 = 3. In this version, the limits are allowed to cross over the zero line. Thus, the constructor ensures dp1 >= dp2 and dn1 >= dn2 by swapping values if necessary to ensure consistency.

  • The dashed lines indicate the limits of the areas where movements are considered small.

  • Only the Gerber1 algorithm takes these regions into account as part of the neutral count.

  • The region where co-movements are considered insignificant in both axes (square around r0) are always ignored.

  • Single weight lines indicate zero delimiters.

  • The double weight lines indicate areas where movements are considered significant.

  • Co-movements within each region are weighed according to their labels.

julia
                         dn2                     dp2
                       ┌──┴──┐                 ┌──┴──┐
                       │     │                 │     │
            4 ┬─────┰─────┰─────┬─────┬─────┬─────┰─────┰─────┐
     ┌────    │ n13 ┃ n19 ┃ n18 ╎     │     ╎ n15 ┃ n14 ┃ n11 │
dp1 ─┤      3 ┾━━━━━╋━━━━━╋━━━━━┿━━━━━┿━━━━━┿━━━━━╋━━━━━╋━━━━━┥
     └────    │ n20 ┃ n6  ┃ n9  ╎     │     ╎ n7  ┃ n4  ┃ n14 │ ────┐
            2 ┾━━━━━╋━━━━━╋━━━━━┿━━━━━┿━━━━━┿━━━━━╋━━━━━╋━━━━━┥     ├─ dp2
              │ n21 ┃ n10 ┃ n3  ╎     │     ╎ n1  ┃ n7  ┃ n15 │ ────┘
     ┌────  1 ┼╌╌╌╌╌╂╌╌╌╌╌╂╌╌╌╌╌┼╌╌╌╌╌┴╌╌╌╌╌┼╌╌╌╌╌╂╌╌╌╌╌╂╌╌╌╌╌┤
     │        │     ┃     ┃     ╎           ╎     ┃     ┃     │
 2c ─┤ r_j  0 ┼─────╂─────╂─────┤    r0     ├─────╂─────╂─────┤
     │        │     ┃     ┃     ╎           ╎     ┃     ┃     │
     └──── -1 ┼╌╌╌╌╌╂╌╌╌╌╌╂╌╌╌╌╌┼╌╌╌╌╌┬╌╌╌╌╌┼╌╌╌╌╌╂╌╌╌╌╌╂╌╌╌╌╌┤
              │ n16 ┃ n8  ┃ n2  ╎     │     ╎ n3  ┃ n9  ┃ n18 │ ────┐
           -2 ┾━━━━━╋━━━━━╋━━━━━┿━━━━━┿━━━━━┿━━━━━╋━━━━━╋━━━━━┥     ├─ dn2
     ┌────    │ n17 ┃ n5  ┃ n8  ╎     │     ╎ n10 ┃ n6  ┃ n19 │ ────┘
dn1 ─┤     -3 ┾━━━━━╋━━━━━╋━━━━━┿━━━━━┿━━━━━┿━━━━━╋━━━━━╋━━━━━┥
     └────    │ n12 ┃ n17 ┃ n16 ╎     │     ╎ n21 ┃ n20 ┃ n13 │
           -4 ┼─────╀─────╀─────┼─────┼─────┼─────╀─────╀─────┤
             -4    -3    -2    -1     0     1     2     3     4
                                     r_i
                 │     │        │           │        │     │
                 └──┬──┘        └─────┬─────┘        └──┬──┘
                   dn1               2c                dp1

Examples

julia
julia> FullGerberIQ()
FullGerberIQ
  dp1 ┼ Float64: 2.0
  dp2 ┼ Float64: 2.0
  dn1 ┼ Float64: 2.0
  dn2 ┼ Float64: 2.0
   n1 ┼ Float64: 0.5
   n2 ┼ Float64: 0.5
   n3 ┼ Float64: 0.5
   n4 ┼ Float64: 0.75
   n5 ┼ Float64: 0.75
   n6 ┼ Float64: 0.75
   n7 ┼ Float64: 0.6123724356957945
   n8 ┼ Float64: 0.6123724356957945
   n9 ┼ Float64: 0.6123724356957945
  n10 ┼ Float64: 0.6123724356957945
  n11 ┼ Float64: 1.0
  n12 ┼ Float64: 1.0
  n13 ┼ Float64: 1.0
  n14 ┼ Float64: 0.8660254037844386
  n15 ┼ Float64: 0.7282376575609851
  n16 ┼ Float64: 0.7282376575609851
  n17 ┼ Float64: 0.8660254037844386
  n18 ┼ Float64: 0.7282376575609851
  n19 ┼ Float64: 0.8660254037844386
  n20 ┼ Float64: 0.8660254037844386
  n21 ┴ Float64: 0.7282376575609851

Related

References

source
PortfolioOptimisers.gerber_iq_assert_c_d Function
julia
gerber_iq_assert_c_d(c::Number, kind::BasicGerberIQ)

Asserts that c <= kind.d, where c is the small movement threshold and d the significance threshold parameter of BasicGerberIQ.

Arguments

Related

References

source
julia
gerber_iq_assert_c_d(c::Number, kind::Union{<:PartialGerberIQ, <:FullGerberIQ}) -> Nothing

Asserts that all c <= kind.d**, where c is the small movement threshold and d** are the significance threshold parameters of PartialGerberIQ or FullGerberIQ.

Arguments

Related

References

source
PortfolioOptimisers.gerber_iq_weight Function
julia
gerber_iq_weight(
    _::Number,
    _::Number,
    axi::Number,
    axj::Number,
    sci::Number,
    scj::Number,
    kind::BasicGerberIQ
) -> Any

Computes the weight for a co-movement according to the region it falls into from the BasicGerberIQ template.

Arguments

  • xi: Return of asset i (unused).

  • xj: Return of asset j (unused).

  • axi: Absolute return of asset i.

  • axj: Absolute return of asset j.

  • sci: Scaling for movement of asset i.

  • scj: Scaling for movement of asset j.

  • kind: Instance of BasicGerberIQ.

Returns

  • res::Number: Co-movement weight.

Related

References

source
julia
gerber_iq_weight(
    xi::Number,
    xj::Number,
    axi::Number,
    axj::Number,
    sci::Number,
    scj::Number,
    kind::PartialGerberIQ
) -> Any

Computes the weight for a co-movement according to the region it falls into from the PartialGerberIQ template.

Arguments

  • xi: Return of asset i.

  • xj: Return of asset j.

  • axi: Absolute return of asset i (unused).

  • axj: Absolute return of asset j (unused).

  • sci: Scaling for movement of asset i.

  • scj: Scaling for movement of asset j.

  • kind: Instance of PartialGerberIQ.

Returns

  • res::Number: Co-movement weight.

Related

References

source
julia
gerber_iq_weight(
    xi::Number,
    xj::Number,
    axi::Number,
    axj::Number,
    sci::Number,
    scj::Number,
    kind::FullGerberIQ
) -> Any

Computes the weight for a co-movement according to the region it falls into from the FullGerberIQ template.

Arguments

  • xi: Return of asset i.

  • xj: Return of asset j.

  • axi: Absolute return of asset i (unused).

  • axj: Absolute return of asset j (unused).

  • sci: Scaling for movement of asset i.

  • scj: Scaling for movement of asset j.

  • kind: Instance of FullGerberIQ.

Returns

  • res::Number: Co-movement weight.

Related

References

source
PortfolioOptimisers.GerberIQCovariance Type
julia
struct GerberIQCovariance{__T_ve, __T_me, __T_pdm, __T_c, __T_decay, __T_sc, __T_kind, __T_alg, __T_ex} <: BaseGerberIQCovariance

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

GerberIQCovariance encapsulates all components required for Gerber Information Quality based covariance or correlation estimation.

Fields

  • ve: Variance estimator.

  • me: Expected returns estimator.

  • pdm: Positive definite matrix estimator.

  • c: Small co-movement threshold.

  • decay: Temporal decay rate estimator for past observations GerberIQDecayEstimator.

  • sc: Threshold scaling factor estimator for co-movement thresholds GerberIQScaler.

  • kind: Gerber IQ covariance kind for squeezing co-movement noise GerberIQCovarianceAlgorithm.

  • alg: Gerber covariance algorithm.

  • ex: Parallel execution strategy..

Constructors

julia
GerberIQCovariance(; ve::StatsBase.CovarianceEstimator = SimpleVariance(),
                     me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(),
                     pdm::Option{<:Posdef} = Posdef(), c::Number = 0.5,
                     decay::GerberIQDecayEstimator = ExpGerberIQDecay(),
                     sc::Option{<:GerberIQScaler} = nothing,
                     kind::GerberIQCovarianceAlgorithm = BasicGerberIQ(),
                     alg::GerberCovarianceAlgorithm = Gerber1(),
                     ex::FLoops.Transducers.Executor = FLoops.Transducers.ThreadedEx())

Keywords correspond to the struct's fields.

Validation

Related

References

source
PortfolioOptimisers.factory Method
julia
factory(
    ce::GerberIQCovariance,
    w::Union{DynamicAbstractWeights, AbstractWeights}
) -> GerberIQCovariance

Return a new GerberIQCovariance 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.

  • Calls factory(ce.decay, w) to update the decay estimator (current decay estimators do not use weights, this for future proofing).

  • Preserves the other fields of the original estimator.

Examples

julia
julia> ce = GerberIQCovariance()
GerberIQCovariance
     ve ┼ SimpleVariance
        │          me ┼ SimpleExpectedReturns
        │             │   w ┴ nothing
        │           w ┼ nothing
        │   corrected ┴ Bool: true
     me ┼ SimpleExpectedReturns
        │   w ┴ nothing
    pdm ┼ Posdef
        │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
        │   kwargs ┴ @NamedTuple{}: NamedTuple()
      c ┼ Float64: 0.5
  decay ┼ ExpGerberIQDecay
        │   e ┼ nothing
        │   y ┴ nothing
     sc ┼ nothing
   kind ┼ BasicGerberIQ
        │   d ┼ Float64: 2.0
        │   n ┴ Float64: 0.5
    alg ┼ Gerber1()
     ex ┴ Transducers.ThreadedEx{@NamedTuple{}}: Transducers.ThreadedEx()

julia> factory(ce, StatsBase.Weights([1, 2, 3]))
GerberIQCovariance
     ve ┼ SimpleVariance
        │          me ┼ SimpleExpectedReturns
        │             │   w ┴ StatsBase.Weights{Int64, Int64, Vector{Int64}}: [1, 2, 3]
        │           w ┼ StatsBase.Weights{Int64, Int64, Vector{Int64}}: [1, 2, 3]
        │   corrected ┴ Bool: true
     me ┼ SimpleExpectedReturns
        │   w ┴ StatsBase.Weights{Int64, Int64, Vector{Int64}}: [1, 2, 3]
    pdm ┼ Posdef
        │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
        │   kwargs ┴ @NamedTuple{}: NamedTuple()
      c ┼ Float64: 0.5
  decay ┼ ExpGerberIQDecay
        │   e ┼ nothing
        │   y ┴ nothing
     sc ┼ nothing
   kind ┼ BasicGerberIQ
        │   d ┼ Float64: 2.0
        │   n ┴ Float64: 0.5
    alg ┼ Gerber1()
     ex ┴ Transducers.ThreadedEx{@NamedTuple{}}: Transducers.ThreadedEx()

References

source
PortfolioOptimisers.gerber_IQ_delta Function
julia
gerber_IQ_delta(
    xi::Number,
    xj::Number,
    axi::Number,
    axj::Number,
    decay::GerberIQDecayEstimator,
    T::Integer,
    k::Number,
    sci::Number,
    scj::Number,
    kind::GerberIQCovarianceAlgorithm
) -> Any

Computes the Gerber IQ statistic for a single co-movement.

Arguments

  • xi: Return for asset i.

  • xj: Return for asset j.

  • axi: Absolute return for asset i.

  • axj: Absolute return for asset j.

  • decay: The decay estimator for the Gerber IQ statistic.

  • T: The number of observations.

  • k: The current observation.

  • sci: Scaling factor for asset i.

  • scj: Scaling factor for asset j.

  • kind: The Gerber IQ co-movement template.

Returns

  • rho::Number: The Gerber IQ statistic.

Details

  • Calls gerber_iq_weight to compute the Gerber IQ weight.

  • Calls the functor of decay to compute the decay factor.

  • Returns the product of them both.

Related

References

source
PortfolioOptimisers.gerber_IQ Function
julia
gerber_IQ(
    ce::GerberIQCovariance,
    X::MatNum,
    sd::ArrNum
) -> MatNum

Computes the Gerber IQ statistic matrix using noise compression template in ce.kind and numerator/denominator definition according to ce.alg.

Arguments

  • ce: Covariance estimator.

  • 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

  1. Calls regenerate_decay.

  2. For each pair of assets (i, j), iterate over all observations.

  3. For every pair at each observation computes the scaling factor for each asset with gerber_iq_scaling, as well as counters for concordant pos, discordant neg, and–-for Gerber1–-neutral nn counters are initialised to zero.

  4. If the absolute value of the returns of both assets is less than its respective scaled threshold ce.c, the observation is skipped.

  5. If the absolute return of both assets is greater than its respective scaled threshold ce.c. a. If the movement is concordant (both returns have the same sign), the concordant counter is incremented according to gerber_IQ_delta. b. If the movement is discordant (both returns have different signs), the discordant counter is incremented according to gerber_IQ_delta. c. For Gerber1, if the neither of the previous conditions are met, it means only one of the absolute returns is greater than its respective scaled ce.c, so the neutral counter is incremented.

  6. For each GerberCovarianceAlgorithm, the GerberIQ statistics is computed as follows: a. Gerber0: (pos - neg) / (pos + neg) b. Gerber1: (pos - neg) / (pos + neg + nn) c. Gerber2: The numerator is computes as when using Gerber0, but the resulting matrix is standardised by dividing each element by the geometric mean of the corresponding diagonal elements.

Related

References

source
Statistics.cor Method

Statistics.cor(ce::GerberIQCovariance, X::MatNum; dims::Int = 1, kwargs...) -> MatNum

Compute the Gerber IQ correlation matrix.

This method computes the Gerber IQ correlation matrix for the input data matrix X. The mean and standard deviation vectors are computed using the estimator's expected returns and variance estimators. The Gerber IQ correlation is then computed via gerber_IQ.

Arguments

  • ce: Gerber IQ covariance estimator.

    • ce::GerberIQCovariance: Compute the unstandardised Gerber IQ correlation matrix.
  • X: Data matrix (observations × assets).

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the mean and standard deviation estimators.

Returns

  • rho::MatNum: The Gerber IQ correlation matrix.

Validation

  • dims is either 1 or 2.

Related

References

source
Statistics.cov Method

Statistics.cov(ce::GerberIQCovariance, X::MatNum; dims::Int = 1, kwargs...) -> MatNum

Compute the Gerber IQ covariance matrix.

This method computes the Gerber IQ covariance matrix for the input data matrix X. The mean and standard deviation vectors are computed using the estimator's expected returns and variance estimators. The Gerber IQ correlation is then computed via gerber_IQ.

Arguments

  • ce: Gerber IQ covariance estimator.

    • ce::GerberIQCovariance: Compute the Gerber IQ covariance matrix.
  • X: Data matrix (observations × assets).

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the mean and standard deviation estimators.

Returns

  • sigma::MatNum: The Gerber IQ covariance matrix.

Validation

  • dims is either 1 or 2.

Related

References

source