Smyth-Broby Covariance

PortfolioOptimisers.SmythBroby0Type
struct SmythBroby0 <: SmythBrobyCovarianceAlgorithm

Divides the difference of the concordant and discordant Smyth-Broby contribution sums by their sum.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (\mathrm{pos},\, \mathrm{neg},\, \mathrm{nn})\,, \\ \rho_{i,\,j} &= \frac{p - q}{p + q}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $\mathrm{pos}$, $\mathrm{neg}$, $\mathrm{nn}$: Contribution sums of a pair over $C$, $D$ and $N$.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

The source defines one statistic, and it keeps the neutral sum in the denominator; SmythBroby1 is that statistic. This tag drops the neutral term, on the shape Gerber0 sets, so it is the library's own reduction and not a formulation of the source.

Algorithm

The branch of sb_pair_scores and of comovement_ratio that this tag selects runs these steps.

  1. Read (pos, neg, nn) from the pair accumulator, giving the scores (p, q, u). The contribution sums are taken and the counts are discarded.
  2. Return (p - q) / (p + q), or zero(T) when the denominator vanishes.

Constructors

SmythBroby0() -> SmythBroby0

Examples

julia> SmythBroby0()SmythBroby0()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBroby1Type
struct SmythBroby1 <: SmythBrobyCovarianceAlgorithm

Divides the difference of the concordant and discordant Smyth-Broby contribution sums by their sum plus the neutral sum.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (\mathrm{pos},\, \mathrm{neg},\, \mathrm{nn})\,, \\ \rho_{i,\,j} &= \frac{p - q}{p + q + u}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $\mathrm{pos}$, $\mathrm{neg}$, $\mathrm{nn}$: Contribution sums of a pair over $C$, $D$ and $N$.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

This is the statistic the source defines, and it is the only one the source defines. The neutral sum keeps the matrix positive semidefinite, which is the purpose the Gerber neutral count already served.

Algorithm

The branch of sb_pair_scores and of comovement_ratio that this tag selects runs these steps.

  1. Read (pos, neg, nn) from the pair accumulator, giving the scores (p, q, u). The contribution sums are taken and the counts are discarded.
  2. Return (p - q) / (p + q + u), or zero(T) when the denominator vanishes.

Constructors

SmythBroby1() -> SmythBroby1

Examples

julia> SmythBroby1()SmythBroby1()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBroby2Type
struct SmythBroby2 <: SmythBrobyCovarianceAlgorithm

Normalises the net Smyth-Broby contribution of a pair by the geometric mean of its own diagonal.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (\mathrm{pos},\, \mathrm{neg},\, \mathrm{nn})\,, \\ \rho_{i,\,j} &= \frac{h_{i,\,j}}{\sqrt{h_{i,\,i} \, h_{j,\,j}}}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $\mathrm{pos}$, $\mathrm{neg}$, $\mathrm{nn}$: Contribution sums of a pair over $C$, $D$ and $N$.
  • $h_{i,\,j} = p - q$: Net score of the pair, before any normalisation.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

The normalisation is a property of the whole matrix and not of one pair, so the diagonal is unit by construction rather than by a per-pair denominator as in SmythBroby0 and SmythBroby1. It is not the SmythBroby0 ratio renormalised: the two agree only where $p + q$ is constant across pairs. The source defines no such normalisation, so this tag is the library's own reduction, on the shape Gerber2 sets.

Algorithm

The branch of sb_pair_scores, of comovement_ratio and of standardise_comovement! that this tag selects runs these steps.

  1. Read (pos, neg, nn) from the pair accumulator, giving the scores (p, q, u).
  2. Return the net score p - q for every pair. This branch applies no denominator of its own.
  3. Divide the assembled matrix by the outer product of the square roots of its own diagonal. The roots are clamped from below by sqrt(eps(eltype(rho))), so an asset that admits no observation gives a zero row rather than a division by zero.

Constructors

SmythBroby2() -> SmythBroby2

Examples

julia> SmythBroby2()SmythBroby2()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBrobyGerber0Type
struct SmythBrobyGerber0 <: SmythBrobyCovarianceAlgorithm

Weights each Smyth-Broby contribution sum by its own observation count, then divides the difference by the sum.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (\mathrm{pos} \, c^{+},\, \mathrm{neg} \, c^{-},\, \mathrm{nn} \, c^{0})\,, \\ \rho_{i,\,j} &= \frac{p - q}{p + q}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $\mathrm{pos}$, $\mathrm{neg}$, $\mathrm{nn}$: Contribution sums of a pair over $C$, $D$ and $N$.
  • $c^{+}$, $c^{-}$, $c^{0}$: Observation counts of a pair over $C$, $D$ and $N$.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

The weighting reintroduces the Gerber vote count that SmythBroby0 discards, so a pair that co-moves often scores above one that co-moves rarely but sharply. The source's conclusion suggests keeping a count beside the sum in one sentence and states no formula for it, so the product above is the library's reading of that sentence. The neutral term is dropped here, as in SmythBroby0.

Algorithm

The branch of sb_pair_scores and of comovement_ratio that this tag selects runs these steps.

  1. Multiply each of pos, neg and nn by its own count cpos, cneg and cnn, giving the scores (p, q, u).
  2. Return (p - q) / (p + q), or zero(T) when the denominator vanishes.

Constructors

SmythBrobyGerber0() -> SmythBrobyGerber0

Examples

julia> SmythBrobyGerber0()SmythBrobyGerber0()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBrobyGerber1Type
struct SmythBrobyGerber1 <: SmythBrobyCovarianceAlgorithm

Weights each Smyth-Broby contribution sum by its own count, then divides the difference by the sum plus the neutral term.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (\mathrm{pos} \, c^{+},\, \mathrm{neg} \, c^{-},\, \mathrm{nn} \, c^{0})\,, \\ \rho_{i,\,j} &= \frac{p - q}{p + q + u}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $\mathrm{pos}$, $\mathrm{neg}$, $\mathrm{nn}$: Contribution sums of a pair over $C$, $D$ and $N$.
  • $c^{+}$, $c^{-}$, $c^{0}$: Observation counts of a pair over $C$, $D$ and $N$.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

The neutral term carries its own count as well, so all three terms of the denominator are scaled alike. This is the estimator's default algorithm. It composes the source's own statistic, SmythBroby1, with the count the source's conclusion suggests keeping beside the sum; the source states no formula for that product.

Algorithm

The branch of sb_pair_scores and of comovement_ratio that this tag selects runs these steps.

  1. Multiply each of pos, neg and nn by its own count cpos, cneg and cnn, giving the scores (p, q, u).
  2. Return (p - q) / (p + q + u), or zero(T) when the denominator vanishes.

Constructors

SmythBrobyGerber1() -> SmythBrobyGerber1

Examples

julia> SmythBrobyGerber1()SmythBrobyGerber1()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBrobyGerber2Type
struct SmythBrobyGerber2 <: SmythBrobyCovarianceAlgorithm

Weights each Smyth-Broby contribution sum by its own count, then normalises the net score by the geometric mean of its own diagonal.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (\mathrm{pos} \, c^{+},\, \mathrm{neg} \, c^{-},\, \mathrm{nn} \, c^{0})\,, \\ \rho_{i,\,j} &= \frac{h_{i,\,j}}{\sqrt{h_{i,\,i} \, h_{j,\,j}}}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $\mathrm{pos}$, $\mathrm{neg}$, $\mathrm{nn}$: Contribution sums of a pair over $C$, $D$ and $N$.
  • $c^{+}$, $c^{-}$, $c^{0}$: Observation counts of a pair over $C$, $D$ and $N$.
  • $h_{i,\,j} = p - q$: Net score of the pair, before any normalisation.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

The normalisation is a property of the whole matrix and not of one pair, as in SmythBroby2. The source defines no such normalisation, so this tag is the library's own reduction, on the shape Gerber2 sets.

Algorithm

The branch of sb_pair_scores, of comovement_ratio and of standardise_comovement! that this tag selects runs these steps.

  1. Multiply each of pos, neg and nn by its own count cpos, cneg and cnn, giving the scores (p, q, u).
  2. Return the net score p - q for every pair. This branch applies no denominator of its own.
  3. Divide the assembled matrix by the outer product of the square roots of its own diagonal. The roots are clamped from below by sqrt(eps(eltype(rho))), so an asset that admits no observation gives a zero row rather than a division by zero.

Constructors

SmythBrobyGerber2() -> SmythBrobyGerber2

Examples

julia> SmythBrobyGerber2()SmythBrobyGerber2()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBrobyCount0Type
struct SmythBrobyCount0 <: SmythBrobyCovarianceAlgorithm

Counts concordant and discordant observations, discards the contribution sums, and divides their difference by their sum.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (c^{+},\, c^{-},\, c^{0})\,, \\ \rho_{i,\,j} &= \frac{p - q}{p + q}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $c^{+}$, $c^{-}$, $c^{0}$: Observation counts of a pair over $C$, $D$ and $N$.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

Dropping sb_delta recovers a Gerber statistic evaluated on the Smyth-Broby admission rule rather than on the Gerber threshold, so this tag reduces exactly to Gerber0 when the confusion zone is switched off, the outer cut-off is lifted, and the centre is zero. The source counts no votes — its whole argument is that a contribution sum carries more information than a count — so the count family is the library's own construction and not a formulation of the source.

Algorithm

The branch of sb_pair_scores and of comovement_ratio that this tag selects runs these steps.

  1. Read (cpos, cneg, cnn) from the pair accumulator, giving the scores (p, q, u). The contribution sums are discarded, and sb_delta is never evaluated.
  2. Return (p - q) / (p + q), or zero(T) when the denominator vanishes.

Constructors

SmythBrobyCount0() -> SmythBrobyCount0

Examples

julia> SmythBrobyCount0()SmythBrobyCount0()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBrobyCount1Type
struct SmythBrobyCount1 <: SmythBrobyCovarianceAlgorithm

Counts concordant, discordant and neutral observations, discards the contribution sums, and divides the net count by the total.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (c^{+},\, c^{-},\, c^{0})\,, \\ \rho_{i,\,j} &= \frac{p - q}{p + q + u}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $c^{+}$, $c^{-}$, $c^{0}$: Observation counts of a pair over $C$, $D$ and $N$.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

Dropping sb_delta recovers a Gerber statistic evaluated on the Smyth-Broby admission rule rather than on the Gerber threshold, so this tag reduces exactly to Gerber1 when the confusion zone is switched off, the outer cut-off is lifted, and the centre is zero. The source counts no votes, so the count family is the library's own construction and not a formulation of the source.

Algorithm

The branch of sb_pair_scores and of comovement_ratio that this tag selects runs these steps.

  1. Read (cpos, cneg, cnn) from the pair accumulator, giving the scores (p, q, u). The contribution sums are discarded, and sb_delta is never evaluated.
  2. Return (p - q) / (p + q + u), or zero(T) when the denominator vanishes.

Constructors

SmythBrobyCount1() -> SmythBrobyCount1

Examples

julia> SmythBrobyCount1()SmythBrobyCount1()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBrobyCount2Type
struct SmythBrobyCount2 <: SmythBrobyCovarianceAlgorithm

Counts concordant and discordant observations, discards the contribution sums, and normalises the net count by the geometric mean of its own diagonal.

Mathematical definition

\[\begin{align} (p,\, q,\, u) &= (c^{+},\, c^{-},\, c^{0})\,, \\ \rho_{i,\,j} &= \frac{h_{i,\,j}}{\sqrt{h_{i,\,i} \, h_{j,\,j}}}\,. \end{align}\]

Where:

  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair, chosen from the sums and the counts by the marker prefix.
  • $c^{+}$, $c^{-}$, $c^{0}$: Observation counts of a pair over $C$, $D$ and $N$.
  • $h_{i,\,j} = p - q$: Net score of the pair, before any normalisation.
  • $\rho_{i,\,j}$: Pairwise correlation coefficient between assets $i$ and $j$.

The normalisation is a property of the whole matrix and not of one pair, as in SmythBroby2. This tag reduces exactly to Gerber2 when the confusion zone is switched off, the outer cut-off is lifted, and the centre is zero. The source counts no votes and defines no such normalisation, so this tag is the library's own construction.

Algorithm

The branch of sb_pair_scores, of comovement_ratio and of standardise_comovement! that this tag selects runs these steps.

  1. Read (cpos, cneg, cnn) from the pair accumulator, giving the scores (p, q, u). The contribution sums are discarded, and sb_delta is never evaluated.
  2. Return the net score p - q for every pair. This branch applies no denominator of its own.
  3. Divide the assembled matrix by the outer product of the square roots of its own diagonal. The roots are clamped from below by sqrt(eps(eltype(rho))), so an asset that admits no observation gives a zero row rather than a division by zero.

Constructors

SmythBrobyCount2() -> SmythBrobyCount2

Examples

julia> SmythBrobyCount2()SmythBrobyCount2()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
PortfolioOptimisers.SmythBrobyCovarianceType
struct SmythBrobyCovariance{__T_ve, __T_me, __T_pdm, __T_c1, __T_c2, __T_c3, __T_n, __T_alg, __T_ex} <: BaseSmythBrobyCovariance

Configures and applies Smyth-Broby covariance estimators.

SmythBrobyCovariance encapsulates all components required for Smyth-Broby-based covariance or correlation estimation, including the expected returns estimator, variance estimator, positive definite matrix estimator, algorithm parameters, and the specific Smyth-Broby algorithm variant. A Smyth-Broby matrix is a matrix of pairwise contribution ratios and is not positive definite in general, so pdm projects the result onto the nearest positive definite matrix; pdm = nothing returns the raw statistic instead. Of the nine algorithm tags the source defines one, SmythBroby1; each of the other eight names which part of it is the library's own, and smythbroby states the shared statistic once.

Fields

  • ve: Variance estimator.
  • me: Expected returns estimator. Used for optionally centering the returns.
  • pdm: Positive definite matrix estimator.
  • c1: Zone of confusion threshold, in units of the asset's standard deviation. It is read against the raw, uncentred return, and it rejects an observation only when both assets fall inside it.
  • c2: Zone of indecision threshold, in units of the asset's standard deviation. It is read against the centred, standardised return, and it rejects an observation when both assets fall inside it. A centred return of exactly zero is inside it at every c2.
  • c3: Outer cut-off, in units of the asset's standard deviation. It is read against the centred, standardised return, and it rejects an observation when either asset exceeds it.
  • n: Severity exponent of the Smyth-Broby contribution. It sets how hard the divergence of a pair is penalised.
  • alg: Smyth-Broby covariance algorithm.
  • ex: Parallel execution strategy.

Constructors

SmythBrobyCovariance(;    ve::StatsBase.CovarianceEstimator = SimpleVariance(),    me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(),    pdm::Option{<:AbstractPosdefEstimator} = Posdef(),    c1::Number = 0.5,    c2::Number = 0.5,    c3::Number = 4,    n::Number = 2,    alg::SmythBrobyCovarianceAlgorithm = SmythBrobyGerber1(),    ex::FLoops.Transducers.Executor = ThreadedEx()) -> SmythBrobyCovariance

Keywords correspond to the struct's fields.

Validation

  • 0 <= c1.
  • 0 <= c2.
  • 0 <= c3.
  • c3 > c2.
  • 0 <= n. Inf is permitted and NaN is not.
  • c1, c2 and c3 are validated with assert_nonempty_nonneg_finite_val, so Inf and NaN are rejected. n is validated with assert_nonneg, which rejects a negative n and NaN and admits Inf. The three thresholds are read on the scale of the data, where Inf admits no observation at all; n is an exponent whose infinite limit is a hard divergence gate, so it is kept. A negative n inverts the severity penalty of sb_delta: a pair whose two magnitudes agree would then contribute nothing, and the diagonal would be zero rather than one.

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> SmythBrobyCovariance()SmythBrobyCovariance   ve ┼ SimpleVariance      │          me ┼ SimpleExpectedReturns      │             │   w ┴ nothing      │           w ┼ nothing      │   corrected ┴ Bool: true   me ┼ SimpleExpectedReturns      │   w ┴ nothing  pdm ┼ Posdef      │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton      │   kwargs ┴ @NamedTuple{}: NamedTuple()   c1 ┼ Float64: 0.5   c2 ┼ Float64: 0.5   c3 ┼ Int64: 4    n ┼ Int64: 2  alg ┼ SmythBrobyGerber1()   ex ┴ Transducers.ThreadedEx{@NamedTuple{}}: Transducers.ThreadedEx()

Related

References

  • [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
source
Statistics.covMethod
Statistics.cov(ce::SmythBrobyCovariance, X::MatNum; dims::Int = 1, kwargs...)

Compute the Smyth-Broby covariance matrix.

The correlation matrix is rescaled by the same sd the zoning read, so the covariance is exactly the correlation times the outer product of sd, and its diagonal is exactly sd .^ 2.

Algorithm

  1. Orient X to observations × assets with dims_oriented.
  2. Compute the standard deviation of each column with ce.ve, giving sd, and clamp it from below by eps(eltype(sd)).
  3. Compute the mean of each column with ce.me, giving mu.
  4. Build the correlation matrix sigma with smythbroby from X, mu and sd.
  5. Rescale sigma in place with StatsBase.cor2cov! and sd, and return it.

Arguments

  • ce: Smyth-Broby 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 mean and standard deviation estimators.

Validation

  • dims in (1, 2).

Returns

  • sigma::Matrix{<:Number}: The Smyth-Broby covariance matrix.

Related

source
Statistics.corMethod
Statistics.cor(ce::SmythBrobyCovariance, X::MatNum; dims::Int = 1, kwargs...)

Compute the Smyth-Broby correlation matrix.

The mean and the standard deviation are computed by the estimator's own me and ve, so the centre and the scale that the zoning reads are the estimator's choice and not this method's.

Algorithm

  1. Orient X to observations × assets with dims_oriented.
  2. Compute the standard deviation of each column with ce.ve, giving sd, and clamp it from below by eps(eltype(sd)). The clamp keeps a constant column from dividing by zero.
  3. Compute the mean of each column with ce.me, giving mu.
  4. Return the matrix that smythbroby builds from X, mu and sd.

Arguments

  • ce: Smyth-Broby 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 mean and standard deviation estimators.

Validation

  • dims in (1, 2).

Returns

  • rho::Matrix{<:Number}: The Smyth-Broby correlation matrix.

Related

source

References

[14]
W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).