Smyth-Broby Covariance
PortfolioOptimisers.SmythBroby0 — Type
struct SmythBroby0 <: SmythBrobyCovarianceAlgorithmDivides 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.
- Read
(pos, neg, nn)from the pair accumulator, giving the scores(p, q, u). The contribution sums are taken and the counts are discarded. - Return
(p - q) / (p + q), orzero(T)when the denominator vanishes.
Constructors
SmythBroby0() -> SmythBroby0Examples
julia> SmythBroby0()SmythBroby0()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBroby1 — Type
struct SmythBroby1 <: SmythBrobyCovarianceAlgorithmDivides 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.
- Read
(pos, neg, nn)from the pair accumulator, giving the scores(p, q, u). The contribution sums are taken and the counts are discarded. - Return
(p - q) / (p + q + u), orzero(T)when the denominator vanishes.
Constructors
SmythBroby1() -> SmythBroby1Examples
julia> SmythBroby1()SmythBroby1()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBroby2 — Type
struct SmythBroby2 <: SmythBrobyCovarianceAlgorithmNormalises 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.
- Read
(pos, neg, nn)from the pair accumulator, giving the scores(p, q, u). - Return the net score
p - qfor every pair. This branch applies no denominator of its own. - 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() -> SmythBroby2Examples
julia> SmythBroby2()SmythBroby2()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBrobyGerber0 — Type
struct SmythBrobyGerber0 <: SmythBrobyCovarianceAlgorithmWeights 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.
- Multiply each of
pos,negandnnby its own countcpos,cnegandcnn, giving the scores(p, q, u). - Return
(p - q) / (p + q), orzero(T)when the denominator vanishes.
Constructors
SmythBrobyGerber0() -> SmythBrobyGerber0Examples
julia> SmythBrobyGerber0()SmythBrobyGerber0()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBrobyGerber1 — Type
struct SmythBrobyGerber1 <: SmythBrobyCovarianceAlgorithmWeights 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.
- Multiply each of
pos,negandnnby its own countcpos,cnegandcnn, giving the scores(p, q, u). - Return
(p - q) / (p + q + u), orzero(T)when the denominator vanishes.
Constructors
SmythBrobyGerber1() -> SmythBrobyGerber1Examples
julia> SmythBrobyGerber1()SmythBrobyGerber1()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBrobyGerber2 — Type
struct SmythBrobyGerber2 <: SmythBrobyCovarianceAlgorithmWeights 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.
- Multiply each of
pos,negandnnby its own countcpos,cnegandcnn, giving the scores(p, q, u). - Return the net score
p - qfor every pair. This branch applies no denominator of its own. - 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() -> SmythBrobyGerber2Examples
julia> SmythBrobyGerber2()SmythBrobyGerber2()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBrobyCount0 — Type
struct SmythBrobyCount0 <: SmythBrobyCovarianceAlgorithmCounts 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.
- Read
(cpos, cneg, cnn)from the pair accumulator, giving the scores(p, q, u). The contribution sums are discarded, andsb_deltais never evaluated. - Return
(p - q) / (p + q), orzero(T)when the denominator vanishes.
Constructors
SmythBrobyCount0() -> SmythBrobyCount0Examples
julia> SmythBrobyCount0()SmythBrobyCount0()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBrobyCount1 — Type
struct SmythBrobyCount1 <: SmythBrobyCovarianceAlgorithmCounts 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.
- Read
(cpos, cneg, cnn)from the pair accumulator, giving the scores(p, q, u). The contribution sums are discarded, andsb_deltais never evaluated. - Return
(p - q) / (p + q + u), orzero(T)when the denominator vanishes.
Constructors
SmythBrobyCount1() -> SmythBrobyCount1Examples
julia> SmythBrobyCount1()SmythBrobyCount1()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBrobyCount2 — Type
struct SmythBrobyCount2 <: SmythBrobyCovarianceAlgorithmCounts 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.
- Read
(cpos, cneg, cnn)from the pair accumulator, giving the scores(p, q, u). The contribution sums are discarded, andsb_deltais never evaluated. - Return the net score
p - qfor every pair. This branch applies no denominator of its own. - 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() -> SmythBrobyCount2Examples
julia> SmythBrobyCount2()SmythBrobyCount2()Related
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
PortfolioOptimisers.SmythBrobyCovariance — Type
struct SmythBrobyCovariance{__T_ve, __T_me, __T_pdm, __T_c1, __T_c2, __T_c3, __T_n, __T_alg, __T_ex} <: BaseSmythBrobyCovarianceConfigures 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 everyc2.
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()) -> SmythBrobyCovarianceKeywords correspond to the struct's fields.
Validation
0 <= c1.0 <= c2.0 <= c3.c3 > c2.0 <= n.Infis permitted andNaNis not.c1,c2andc3are validated withassert_nonempty_nonneg_finite_val, soInfandNaNare rejected.nis validated withassert_nonneg, which rejects a negativenandNaNand admitsInf. The three thresholds are read on the scale of the data, whereInfadmits no observation at all;nis an exponent whose infinite limit is a hard divergence gate, so it is kept. A negativeninverts the severity penalty ofsb_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 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> 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
BaseSmythBrobyCovarianceAbstractExpectedReturnsEstimatorSimpleExpectedReturnsStatsBase.CovarianceEstimatorSimpleVariancePosdefSmythBrobyCovarianceAlgorithmSmythBroby0SmythBroby1SmythBroby2SmythBrobyGerber0SmythBrobyGerber1SmythBrobyGerber2SmythBrobyCount0SmythBrobyCount1SmythBrobyCount2smythbrobyGerberCovariance: the statistic this family extends. Its zoning is the threshold rule the confusion zone and the indecision zone replace.FLoops.Transducers.Executorfactoryport_opt_view
References
- [14] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).
Statistics.cov — Method
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
- Orient
Xto observations × assets withdims_oriented. - Compute the standard deviation of each column with
ce.ve, givingsd, and clamp it from below byeps(eltype(sd)). - Compute the mean of each column with
ce.me, givingmu. - Build the correlation matrix
sigmawithsmythbrobyfromX,muandsd. - Rescale
sigmain place withStatsBase.cor2cov!andsd, and return it.
Arguments
ce: Smyth-Broby 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 mean and standard deviation estimators.
Validation
dims in (1, 2).
Returns
sigma::Matrix{<:Number}: The Smyth-Broby covariance matrix.
Related
Statistics.cor — Method
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
- Orient
Xto observations × assets withdims_oriented. - Compute the standard deviation of each column with
ce.ve, givingsd, and clamp it from below byeps(eltype(sd)). The clamp keeps a constant column from dividing by zero. - Compute the mean of each column with
ce.me, givingmu. - Return the matrix that
smythbrobybuilds fromX,muandsd.
Arguments
ce: Smyth-Broby 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 mean and standard deviation estimators.
Validation
dims in (1, 2).
Returns
rho::Matrix{<:Number}: The Smyth-Broby correlation matrix.
Related
References
- [14]
- W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).