Smyth-Broby Covariance: private API

PortfolioOptimisers.SmythBrobyCovarianceAlgorithm — Type
abstract type SmythBrobyCovarianceAlgorithm <: AbstractAlgorithm

Abstract supertype for all Smyth-Broby covariance algorithm types.

Every concrete or abstract type that implements a Smyth-Broby covariance algorithm must subtype SmythBrobyCovarianceAlgorithm. A subtype goes in the alg field of a SmythBrobyCovariance estimator.

A marker makes two independent choices. Its prefix selects the score triple through sb_pair_scores. Its trailing digit selects the denominator through comovement_ratio, and the digit has the same meaning as in the Gerber family.

Related

References

  • [35] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022). Section 2, Equation 5.
source
PortfolioOptimisers.GerberComovementZero — Type

Union of the Gerber-family markers that divide the net score of a pair by the sum of its concordant and discordant scores.

The statistic is zero when that sum is zero. The trailing 0 has the same meaning in all four families of the Gerber lineage, so one method of comovement_ratio serves all four. A new family adds a member to this union, not a new method.

Related

source
PortfolioOptimisers.GerberComovementOne — Type

Union of the Gerber-family markers that divide the net score of a pair by the sum of its three scores, the neutral score included.

The statistic is zero when that sum is zero. The trailing 1 has the same meaning in all four families of the Gerber lineage, so one method of comovement_ratio serves all four. Gerber1 is the statistic of [33], and SmythBroby1 is the statistic of [35]. Section 2 of [35] states, with no proof, that the neutral term keeps the matrix positive semidefinite. The claim is false for SmythBroby1 and SmythBrobyGerber1.

Related

source
PortfolioOptimisers.GerberComovementTwo — Type

Union of the Gerber-family markers that keep the net score of each pair and divide the matrix by the geometric mean of its diagonal.

The trailing 2 has the same meaning in all four families of the Gerber lineage. Only this denominator comes from the whole matrix, not from the scores of one pair. These markers are therefore the only ones that reach the acting method of standardise_comovement!.

Related

source
PortfolioOptimisers.SmythBrobyDeltaAlg — Type

Union of the Smyth-Broby markers that accumulate only the sb_delta contributions, and not the counts.

The prefix of a marker selects the score triple, and the trailing digit selects the denominator. The two choices are independent, so each prefix has its own union. This prefix is the one that the source defines. It adds contributions and keeps no count.

Related

source
PortfolioOptimisers.SmythBrobyGerberAlg — Type

Union of the Smyth-Broby markers that accumulate both the sb_delta contributions and the co-movement counts, and score a pair by their product.

The prefix of a marker selects the score triple, and the trailing digit selects the denominator. The two choices are independent, so each prefix has its own union. Section 5 of the source suggests a count beside each sum and states no formula. The product is a choice of the library.

Related

source
PortfolioOptimisers.SmythBrobyCountAlg — Type

Union of the Smyth-Broby markers that accumulate the co-movement counts only, and never evaluate sb_delta.

The prefix of a marker selects the score triple, and the trailing digit selects the denominator. The two choices are independent, so each prefix has its own union. This prefix gives a Gerber statistic on the zones of Smyth-Broby. The source keeps no count, so this prefix is a construction of the library.

Related

source
PortfolioOptimisers.SmythBrobyKernel — Type
struct SmythBrobyKernel{__T_alg, __T_mu, __T_sd, __T_c1, __T_c2, __T_c3, __T_n}

Co-movement policy of the Smyth-Broby family for the shared pairwise loop.

gerber_comovement! takes this policy. The confusion zone compares the raw, uncentred return with c1 * sigma. The policy centres and standardises each observation that passes the confusion zone. The indecision zone of c2, through sb_crossed, and the outer cut-off at c3 then admit or reject the observation. The sign of the product of the standardised returns gives the class of an admitted observation.

The alg marker selects the accumulation through sb_add_pos and the denominator through comovement_ratio. This type is configuration. It holds no result, and nothing changes it.

Section 2 of [35] defines the three zones:

  • The confusion zone, of half-width $c_1$ standard deviations.
  • The indecision zone, of half-width $c_2$.
  • The outer cut-off at $c_3$, which the source sets to 4.

Section 3 of the source uses $c_1 = c_2 = 0.5$, and these values are the defaults. The source keeps a magnitude strictly below the cut-off. The library rejects only a magnitude above c3, so it keeps a magnitude equal to c3.

Fields

  • alg: Smyth-Broby covariance algorithm.
  • mu: Vector of asset means, one entry per asset.
  • sd: Standard deviation vector of X, shaped to be consistent with X.
  • c1: Confusion-zone threshold on the raw, uncentred return, in standard deviations of the asset. The confusion zone rejects an observation only when both assets are inside it.
  • c2: Indecision-zone threshold on the centred, standardised return, in standard deviations of the asset. The indecision zone rejects an observation when both assets are inside it. A centred return of exactly zero is inside the zone at every c2.
  • c3: Outer cut-off on the centred, standardised return, in standard deviations of the asset. The cut-off rejects an observation when either asset is above it.
  • n: Severity exponent of the Smyth-Broby contribution. The contribution of an observation is kappa / (1 + gamma^n), where gamma is the divergence of the pair.

Related

References

  • [35] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022). Section 2 and Section 3.
source
PortfolioOptimisers.SmythBrobyPairTerms — Type
struct SmythBrobyPairTerms{__T_mui, __T_muj, __T_sigmai, __T_sigmaj, __T_c1i, __T_c1j}

Holds the quantities of one pair of assets that the Smyth-Broby step of comovement_step reads, and that do not depend on the observation.

This type is an implementation detail and is not intended for direct use. comovement_pair_state makes it once for each pair, so the inner loop does not compute these quantities again.

Fields

  • mui: mui: The mean of asset i.
  • muj: muj: The mean of asset j.
  • sigmai: sigmai: The standard deviation of asset i.
  • sigmaj: sigmaj: The standard deviation of asset j.
  • c1i: c1i: The confusion-zone threshold of asset i, c1 * sigmai.
  • c1j: c1j: The confusion-zone threshold of asset j, c1 * sigmaj.

Related

source
PortfolioOptimisers.ComovementSums — Type
struct ComovementSums{__T_pos, __T_neg, __T_nn, __T_cpos, __T_cneg, __T_cnn, __T_di, __T_dj}

Holds the sums and the counts that the pairwise loop of gerber_comovement! adds for one pair of assets.

This type is an implementation detail and is not intended for direct use. gerber_comovement! opens it for each pair. comovement_step, sb_add_pos, sb_add_neg, sb_add_neutral, iq_add_neutral and iq_add_diagonal return a new one with the fields of their step replaced through rebuild_struct, and comovement_finalise reduces it. A policy reads the fields that its marker needs, and the other fields stay at zero.

Fields

  • pos: pos: The score of the concordant observations.
  • neg: neg: The score of the discordant observations.
  • nn: nn: The score of the neutral observations.
  • cpos: cpos: The count of the concordant observations.
  • cneg: cneg: The count of the discordant observations.
  • cnn: cnn: The count of the neutral observations.
  • di: di: The diagonal projection of asset i, which only the Gerber IQ 2 marker divides by.
  • dj: dj: The diagonal projection of asset j, which only the Gerber IQ 2 marker divides by.

Related

source
PortfolioOptimisers.sb_delta — Function
sb_delta(ri::Number, rj::Number, n::Number) -> Number

Contribution of one admitted observation to a Smyth-Broby pair score.

An observation adds this real number to the score of the pair, where the Gerber statistic adds a count of one. A co-movement of four standard deviations therefore adds more than a co-movement of one standard deviation. Both arguments are absolute values, and the caller centres and standardises the returns before it takes them.

Mathematical definition

\[\begin{align} \kappa &= \sqrt{\left(1 + |\tilde{r}_{t,\,i}|\right) \left(1 + |\tilde{r}_{t,\,j}|\right)}\,, \\ \gamma &= \left\lVert |\tilde{r}_{t,\,i}| - |\tilde{r}_{t,\,j}| \right\rVert\,, \\ \delta &= \frac{\kappa}{1 + \gamma^{n}}\,. \end{align}\]

Where:

  • $\tilde{r}_{t,\,i} = (x_{t,\,i} - \mu_i) / \sigma_i$: Centred, standardised return of asset $i$ at observation $t$.
  • $\kappa$: Amplitude kernel of a pair, the geometric mean of the two gross standardised magnitudes.
  • $\gamma$: Divergence of a pair, the absolute difference of the two standardised magnitudes.
  • $\delta$: Smyth-Broby contribution of one admitted observation, in place of the Gerber count of one.
  • $n$: Severity exponent. The denominator of $\delta$ is $1 + \gamma^{n}$, so a larger $n$ gives a larger penalty to a divergence above one.

$\kappa$ increases with the two magnitudes, and $\gamma^{n}$ decreases the contribution when the two magnitudes differ. The contribution is therefore largest when both assets move far and by the same amount. $\gamma$ is the absolute difference of the two magnitudes, not of the two signed returns. The caller reads the signs first, and the signs put the observation in the concordant or the discordant set.

Equations 1 to 3 of [35] define the contribution for a general severity $n$. Equation 4 writes it out for $n = 2$, the value that Section 2 of the source uses. The default n = 2 of the estimator is that value. The formula above agrees with a direct evaluation of Equation 1 to machine precision.

Algorithm

  1. Multiply the two gross magnitudes 1 + ri and 1 + rj, and take the square root. The result is the amplitude kappa.
  2. Take the absolute difference of ri and rj. The result is the divergence gamma.
  3. Return kappa / (1 + gamma^n).

Arguments

  • ri: Absolute centred standardised return of asset i at the observation.
  • rj: Absolute centred standardised return of asset j at the observation.
  • n: Severity exponent of the Smyth-Broby contribution. The contribution of an observation is kappa / (1 + gamma^n), where gamma is the divergence of the pair.

Returns

  • delta::Number: The contribution of the observation to the pair's score.

Related

References

  • [35] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022). Section 2, Equations 1 to 4.
source
PortfolioOptimisers.smythbroby — Function
smythbroby(ce::SmythBrobyCovariance, X::MatNum, mu::ArrNum, sd::ArrNum)

Compute the Smyth-Broby correlation matrix with the marker in ce.alg.

All nine markers share the pairwise loop of gerber_comovement! through a SmythBrobyKernel policy. The marker selects the scores and the denominator.

Mathematical definition

For each pair $(i, j)$, an observation $t$ must pass two tests. The confusion zone compares the raw, uncentred return with $c_1 \sigma$. It rejects $t$ only when both assets are inside it:

\[\begin{align} |x_{ti}| < c_1 \sigma_i \quad \text{and} \quad |x_{tj}| < c_1 \sigma_j\,. \end{align}\]

The indecision zone compares the centred, standardised return $\tilde{r}_{ti} = (x_{ti} - \mu_i) / \sigma_i$ with $c_2$. Asset $i$ crosses at $t$ when

\[\begin{align} |\tilde{r}_{ti}| \geq c_2 \quad \text{and} \quad \tilde{r}_{ti} \neq 0\,, \end{align}\]

and the indecision zone rejects $t$ when neither asset crosses. The outer cut-off rejects $t$ when either asset is above $c_3$. The second condition matters only at $c_2 = 0$, because $|\tilde{r}| \geq c_2 > 0$ already excludes a zero return. sb_crossed holds this rule. Section 2 of [35] puts the confusion zone on the uncentred return and the indecision zone on the centred return. A confusion zone on the centred return changes the statistic.

An admitted observation is concordant when both assets cross and $\tilde{r}_{ti} \tilde{r}_{tj} > 0$. It is discordant when both assets cross and the product is negative. It is neutral when exactly one asset crosses. The sums and the counts of each class over the admitted observations are:

\[\begin{align} \text{pos} &= \sum_t \delta_t \, \mathbf{1}[t \in C]\,, \quad \text{neg} = \sum_t \delta_t \, \mathbf{1}[t \in D]\,, \quad \text{nn} = \sum_t \delta_t \, \mathbf{1}[t \in N]\,, \\ c^{+} &= |C|\,, \quad c^{-} = |D|\,, \quad c^{0} = |N|\,, \end{align}\]

Where:

  • $\tilde{r}_{t,\,i} = (x_{t,\,i} - \mu_i) / \sigma_i$: Centred, standardised return of asset $i$ at observation $t$.
  • $x_{t,\,i}$: Return of asset $i$ at observation $t$.
  • $\sigma_i$: Standard deviation of asset $i$.
  • $c_1$: Confusion-zone threshold on the raw, uncentred return. The confusion zone rejects an observation only when both assets are inside it.
  • $c_2$: Indecision-zone threshold on the centred, standardised return. The indecision zone rejects an observation when both assets are inside it. A centred return of exactly zero is inside the zone at every $c_2$.
  • $c_3$: Outer cut-off on the centred, standardised return. The cut-off rejects an observation when either asset is above it.
  • $\delta$: Smyth-Broby contribution of one admitted observation, in place of the Gerber count of one.
  • $C$, $D$, $N$: Concordant, discordant and neutral observation sets of a pair, over the admitted observations.
  • $\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$.
  • $p$, $q$, $u$: Concordant, discordant and neutral scores of a pair. The marker prefix selects them from the sums and the counts.

Here $\delta_t = \delta(|\tilde{r}_{t,\,i}|, |\tilde{r}_{t,\,j}|, n)$ is the sb_delta contribution. The marker prefix selects the three scores $(p, q, u)$:

  • SmythBroby*: $(\text{pos},\, \text{neg},\, \text{nn})$.
  • SmythBrobyGerber*: $(\text{pos} \, c^{+},\, \text{neg} \, c^{-},\, \text{nn} \, c^{0})$. Each sum has its own count, the neutral sum included.
  • SmythBrobyCount*: $(c^{+},\, c^{-},\, c^{0})$.

The trailing digit selects the reduction, where $h_{ij} = p - q$ is the net score:

\[\begin{align} \hat{\rho}_{ij} &= \begin{cases} (p - q) / (p + q) & 0 \\ (p - q) / (p + q + u) & 1 \\ h_{ij} / \sqrt{h_{ii} \, h_{jj}} & 2 \end{cases}\,. \end{align}\]

The digits 0 and 1 give zero when the denominator is zero. The digit 2 divides the matrix of net scores by the geometric mean of its diagonal, and clamps each root from below at $\sqrt{\varepsilon}$. The result is not the ratio of the digit 0 after a second division. The two are equal only where $p + q$ is the same for every pair.

Of the nine markers, only SmythBroby1 is a statistic of the source. It is Equation 5 of the source, and the source defines no other statistic. The trailing digits 0 and 2 are reductions of the library, as Gerber0 and Gerber2 are for the Gerber statistic. The SmythBrobyGerber* prefix is how the library reads Section 5 of the source. Section 5 suggests a count beside each sum and states no formula. The SmythBrobyCount* prefix is a construction of the library, because the source keeps no count.

Algorithm

  1. Read the asset count N from the second dimension of X, and allocate the N × N output rho.
  2. Build the policy pol as a SmythBrobyKernel from ce.alg, mu, sd, ce.c1, ce.c2, ce.c3 and ce.n.
  3. Fill rho with gerber_comovement! on the executor ce.ex.
  4. Divide rho in place by the geometric mean of its diagonal with standardise_comovement!. Only a 2 marker changes rho.
  5. Write one onto a zero diagonal entry of rho with comovement_unit_diagonal!. An asset that admits no observation has a zero diagonal entry, and that entry is one by definition.
  6. Repair rho with posdef! and the pdm field of the estimator, because a Smyth-Broby matrix is not positive definite in general. It does nothing when ce.pdm is nothing.

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.
  • mu: Vector of asset means, one entry per asset.
  • sd: Standard deviation vector of X, shaped to be consistent with X.

Returns

  • rho::Matrix{<:Number}: The Smyth-Broby correlation matrix, after the repair of the pdm field of the estimator.

Related

References

  • [35] W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022). Section 2, Equation 5.
source
PortfolioOptimisers.gerber_comovement! — Function
gerber_comovement!(
    rho::AbstractMatrix,
    ex::Transducers.Executor,
    X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
    pol
) -> Any

Fill the symmetric co-movement matrix rho with the pairwise loop that the Gerber-family policies share.

The policy object pol is a SmythBrobyKernel or a GerberIQKernel. The policy tests one observation against the thresholds, gives it a class and a weight, and reduces the accumulator of a pair. This function holds the loop over the pairs and the observations. It writes into rho and into nothing else, so X and pol do not change.

Algorithm

  1. Read the observation count T from the first dimension of X.
  2. For every asset pair (i, j) with i at most j, run steps 3 to 6. The executor ex runs the outer index in parallel.
  3. Build the pair state st with comovement_pair_state.
  4. Open the accumulator acc, a ComovementSums. The five scores start at zero of eltype(X), and the three counts start at integer zero. A policy reads the fields that its marker needs, and the other fields stay at zero. Only iq_add_diagonal writes the two diagonal projections di and dj.
  5. Add each observation k of the pair into acc with comovement_step.
  6. Reduce acc with comovement_finalise, and write the result into rho[i, j] and rho[j, i].

Arguments

  • rho::AbstractMatrix: N × N output matrix, overwritten.
  • ex: FLoops executor that runs the outer asset index in parallel.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • pol: Co-movement policy object.

Returns

  • nothing.

Related

source
PortfolioOptimisers.comovement_pair_state — Function
comovement_pair_state(
    pol::SmythBrobyKernel,
    i::Integer,
    j::Integer
) -> SmythBrobyPairTerms

Build the state of a pair that comovement_step reads.

The state holds each quantity that depends on the pair but not on the observation, so the inner loop does not compute it again. The Smyth-Broby method returns a SmythBrobyPairTerms. The Gerber IQ method returns a GerberIQPairTerms, with the threshold scale factors and the scaled thresholds of the pair.

Algorithm

The Smyth-Broby method runs these steps.

  1. Read the two standard deviations pol.sd[i] and pol.sd[j] as sigmai and sigmaj.
  2. Multiply each by pol.c1. The products are the two confusion-zone thresholds c1i and c1j.
  3. Return the SmythBrobyPairTerms of the two means read from pol.mu, the two standard deviations and the two thresholds.

Arguments

  • pol: Co-movement policy object.
  • i, j: Indices of the two assets of the pair.

Returns

  • st::Union{SmythBrobyPairTerms, GerberIQPairTerms}: The per-pair state.

Related

source
PortfolioOptimisers.sb_crossed — Function
sb_crossed(r::Number, ar::Number, c::Number) -> Any

Decide whether one asset leaves the indecision zone at one observation.

An asset leaves the indecision zone when the magnitude of its centred, standardised return is at least c2, and that return is not exactly zero. For a positive threshold, the second test changes nothing, because ar >= c > 0 already implies that r is not zero. The second test matters only at c2 = 0. There, ar >= 0 holds for every return, a return of exactly zero included. With the second test, a return of exactly zero never crosses.

This rule keeps the diagonal of the statistic at one. The pair (i, i) crosses on both axes or on neither, so it never reaches the neutral accumulator, which a GerberComovementOne marker divides by. Without the second test, at c2 = 0, a return of exactly zero crosses on both axes but has no sign. comovement_step then adds it to the neutral accumulator, and the diagonal falls below one.

The rule applies to the indecision zone and not to the confusion zone, because the two zones test different quantities. The indecision zone tests the centred return. A centred return of exactly zero is an asset at its own mean, and it has no sign to classify. The confusion zone tests the raw, uncentred return, and the zero of that return is an arbitrary point on the scale of the data. A raw return of zero is a deviation of $-\mu$ from the mean, and that deviation has a sign. The confusion zone also only rejects observations and never classifies them, so it cannot give a wrong count.

Arguments

  • r: Centred, standardised return of the asset at the observation.
  • ar: Its absolute value.
  • c: The indecision-zone threshold c2.

Returns

  • crossed::Bool: true when the asset left the indecision zone.

Related

source
PortfolioOptimisers.comovement_step — Function
comovement_step(
    pol::SmythBrobyKernel,
    acc::ComovementSums,
    st::SmythBrobyPairTerms,
    xi::Number,
    xj::Number,
    _::Integer,
    _::Integer
) -> Any

Add one observation of a pair to the co-movement accumulator.

The confusion zone tests the raw, uncentred return, and the indecision zone tests the centred, standardised return. Section 2 of [35] defines the two zones this way, and a confusion zone on the centred return changes the statistic. Because the two zones test different quantities, only the indecision zone has the rule that a return of exactly zero never crosses. sb_crossed states that rule. The Gerber IQ method compares absolute returns with the scaled thresholds of the pair through iq_crossed. It weights each observation by the IQ template and by the temporal decay through gerber_IQ_delta.

Algorithm

The Smyth-Broby method runs these steps. It does not read T or k, because the family applies no temporal decay.

  1. Return acc unchanged when abs(xi) is below st.c1i and abs(xj) is below st.c1j. This is the confusion zone, on the raw return.
  2. Centre and standardise both returns with the pair state. The results are ri and rj, and their magnitudes are ari and arj.
  3. Decide with sb_crossed whether each asset leaves the indecision zone of pol.c2.
  4. Return acc unchanged when either magnitude is above pol.c3, or when neither asset leaves the indecision zone. The first case is the outer cut-off, and the second case is the indecision zone.
  5. Accumulate through sb_add_pos when both assets cross and the product ri * rj is positive.
  6. Accumulate through sb_add_neg when both assets cross and the product is negative.
  7. In all other cases, accumulate through sb_add_neutral. This is the case where exactly one asset crosses. When both assets cross, the product is not zero, so the three branches cover every admitted observation.

Arguments

  • pol: Co-movement policy object.
  • acc: Pair accumulator, a ComovementSums. This family does not read di and dj.
  • st: Pair state from comovement_pair_state.
  • xi, xj: Returns of assets i and j at observation k.
  • T: Number of observations.
  • k: Observation index.

Returns

  • The updated accumulator.

Related

source
PortfolioOptimisers.comovement_finalise — Function
comovement_finalise(
    pol::SmythBrobyKernel,
    acc::ComovementSums,
    _::Type{T}
) -> Any

Reduce the accumulator of a pair to the co-movement statistic of the pair.

It applies both parts of the marker. The prefix selects the scores, and the trailing digit selects the denominator.

Algorithm

  1. Select the score triple (p, n, nn) from acc with sb_pair_scores, which dispatches on the marker prefix.
  2. Reduce the triple with comovement_ratio, which dispatches on the trailing digit, and return the result.

Arguments

  • pol: Co-movement policy object.
  • acc: Pair accumulator, a ComovementSums. This family does not read di and dj.
  • T: Element type of the zero that a zero denominator gives.

Returns

  • The pairwise co-movement statistic.

Related

source
PortfolioOptimisers.comovement_ratio — Function
comovement_ratio(
    _::Union{Gerber0, SmythBroby0, SmythBrobyCount0, SmythBrobyGerber0},
    p::Number,
    n::Number,
    nn::Number,
    _::Type{T}
) -> Any

Reduce the concordant, discordant and neutral scores of a pair to the correlation entry of the pair.

The marker selects the denominator. Here n is the discordant score, not the severity exponent of sb_delta. The two have the same name and no other relation.

Algorithm

The marker selects one of three branches.

  1. GerberComovementZero: return (p - n) / (p + n), or zero(T) when p + n is zero. It does not read nn.
  2. GerberComovementOne: return (p - n) / (p + n + nn), or zero(T) when p + n + nn is zero. This is the only branch that reads nn.
  3. GerberComovementTwo: return p - n, and apply no denominator. standardise_comovement! normalises the assembled matrix afterwards.

A zero denominator means that the pair admits no observation. Zero is then the correct value for an off-diagonal entry. It is the wrong value on the diagonal, where a correlation is one by definition. This function does not know whether the pair is (i, i), so it cannot tell the two cases apart. comovement_unit_diagonal! writes the diagonal after the matrix is assembled.

Arguments

  • alg: Co-movement algorithm marker.
  • p, n, nn: Accumulated concordant, discordant and neutral scores of one pair.
  • T: Element type of the zero that a zero denominator gives.

Returns

  • The pairwise co-movement statistic.

Related

source
PortfolioOptimisers.standardise_comovement! — Function
standardise_comovement!(_, _::AbstractMatrix)

Normalise a net co-movement matrix in place by the geometric mean of its own diagonal.

Only the GerberComovementTwo markers reach the acting method. The fall-through method does nothing, so a caller can call this function for every marker. It writes into rho and into nothing else. The marker and the estimator that holds the marker do not change.

The Gerber IQ family does not call this function. When sc is not pair-separable, the thresholds of an asset change from one pair to the next. The magnitude class of an asset in a pair is then not the class that the diagonal records, and the ratio can leave [-1, 1]. gerber_IQ divides by the two diagonal projections of the pair instead, which iq_add_diagonal accumulates. The other three families compare each asset with a threshold in its own units. The diagonal entry of an asset is then correct for every pair, so this function gives the correct result.

Algorithm

The acting method runs these steps. The fall-through method runs none of them.

  1. Take the square roots of the diagonal of rho, and clamp them from below at sqrt(eps(eltype(rho))). The result is h. The clamp prevents a division by zero for an asset that admits no observation.
  2. Divide rho element-wise by the outer product h * transpose(h), and copy the upper triangle into the lower triangle.

Arguments

  • alg: Co-movement algorithm marker. It selects the acting method or the method that does nothing.
  • rho: N × N co-movement matrix, overwritten.

Returns

  • nothing.

Related

source
PortfolioOptimisers.comovement_unit_diagonal! — Function
comovement_unit_diagonal!(rho::AbstractMatrix)

Write one onto a zero diagonal entry of an assembled co-movement matrix, in place.

The correlation of an asset with itself is one by definition, for every sample. Each reduction of comovement_ratio returns one on the diagonal when the asset crosses its threshold at least once. This function corrects the other case. An asset that never crosses its threshold gives a zero denominator for every pair that contains it. Its whole row is then zero(T), and its diagonal entry is zero(T) too. The function writes into rho and into nothing else, and it changes no other entry.

The function writes only where iszero holds, so it does not write over a diagonal entry that is near one. A 2 marker divides the diagonal by its own square root twice. Its diagonal entry is then within a unit in the last place of one, but not always exactly one. posdef! tests its diagonal with an exact isone to decide whether it holds a correlation matrix or a covariance matrix, and the two branches give different results. An exact one written over such an entry changes the branch, and so changes the result for a sample with no degenerate asset. The iszero test limits this function to the defect that it corrects.

Algorithm

  1. For each index i of the diagonal, write one(eltype(rho)) onto rho[i, i] when that entry is zero.

Arguments

  • rho: N × N co-movement matrix, whose zero diagonal entries are overwritten.

Returns

  • nothing.

Related

  • comovement_ratio: the reduction that gives zero on the diagonal when the denominator is zero.
  • standardise_comovement!: the division by the diagonal that runs before this function.
  • gerber_comovement!
  • posdef!: the repair that runs after this function. It keeps a zero diagonal entry and its zero row, so it does not write the one.
source
PortfolioOptimisers.sb_add_pos — Function
sb_add_pos(
    _::Union{SmythBroby0, SmythBroby1, SmythBroby2},
    acc::ComovementSums,
    ari::Number,
    arj::Number,
    n::Number
) -> ComovementSums

Add a concordant observation to the pair accumulator, as the prefix of alg selects.

The accumulator is a ComovementSums. Each method returns a new accumulator through rebuild_struct and changes no argument.

Algorithm

The marker prefix selects one of three branches.

  1. SmythBrobyDeltaAlg: add sb_delta to acc.pos, and do not change acc.cpos.
  2. SmythBrobyGerberAlg: add sb_delta to acc.pos, and add one to acc.cpos.
  3. SmythBrobyCountAlg: add one to acc.cpos, and do not evaluate sb_delta.

Arguments

  • alg: Smyth-Broby algorithm marker.
  • acc: Pair accumulator, a ComovementSums. This family does not read di and dj.
  • ari, arj: Absolute centred standardised returns of the two assets at the observation.
  • n: Severity exponent of the Smyth-Broby contribution. The contribution of an observation is kappa / (1 + gamma^n), where gamma is the divergence of the pair.

Returns

  • The updated accumulator.

Related

source
PortfolioOptimisers.sb_add_neg — Function
sb_add_neg(
    _::Union{SmythBroby0, SmythBroby1, SmythBroby2},
    acc::ComovementSums,
    ari::Number,
    arj::Number,
    n::Number
) -> ComovementSums

Add a discordant observation to the pair accumulator, as the prefix of alg selects.

It has the same three branches as sb_add_pos, on the discordant score and count.

Algorithm

The marker prefix selects one of three branches.

  1. SmythBrobyDeltaAlg: add sb_delta to acc.neg, and do not change acc.cneg.
  2. SmythBrobyGerberAlg: add sb_delta to acc.neg, and add one to acc.cneg.
  3. SmythBrobyCountAlg: add one to acc.cneg, and do not evaluate sb_delta.

Arguments

  • alg: Smyth-Broby algorithm marker.
  • acc: Pair accumulator, a ComovementSums. This family does not read di and dj.
  • ari, arj: Absolute centred standardised returns of the two assets at the observation.
  • n: Severity exponent of the Smyth-Broby contribution. The contribution of an observation is kappa / (1 + gamma^n), where gamma is the divergence of the pair.

Returns

  • The updated accumulator.

Related

source
PortfolioOptimisers.sb_add_neutral — Function
sb_add_neutral(
    _::SmythBroby1,
    acc::ComovementSums,
    ari::Number,
    arj::Number,
    n::Number
) -> ComovementSums

Add a neutral observation to the pair accumulator. An observation is neutral when exactly one of the two assets leaves the indecision zone, and sb_crossed decides which assets leave it.

Only the GerberComovementOne markers reach an acting method, because only their denominator has a neutral term. The fall-through method returns the accumulator unchanged. The neutral score of every other marker therefore stays at zero, and no reduction reads it.

Algorithm

The marker selects one of four branches.

  1. SmythBroby1: add sb_delta to acc.nn.
  2. SmythBrobyGerber1: add sb_delta to acc.nn, and add one to acc.cnn.
  3. SmythBrobyCount1: add one to acc.cnn, and do not evaluate sb_delta.
  4. Any other SmythBrobyCovarianceAlgorithm: return acc unchanged.

Arguments

  • alg: Smyth-Broby algorithm marker.
  • acc: Pair accumulator, a ComovementSums. This family does not read di and dj.
  • ari, arj: Absolute centred standardised returns of the two assets at the observation. The fall-through method reads neither.
  • n: Severity exponent of the Smyth-Broby contribution. The contribution of an observation is kappa / (1 + gamma^n), where gamma is the divergence of the pair.

Returns

  • The updated accumulator.

Related

source
PortfolioOptimisers.sb_pair_scores — Function
sb_pair_scores(
    _::Union{SmythBroby0, SmythBroby1, SmythBroby2},
    acc::ComovementSums
) -> Tuple{Any, Any, Any}

Return the concordant, discordant and neutral scores of a pair from the accumulator, as the prefix of alg selects.

This function dispatches on the prefix of the marker. comovement_ratio dispatches on its trailing digit.

Algorithm

The marker prefix selects one of three branches.

  1. SmythBrobyDeltaAlg: return the contribution sums (acc.pos, acc.neg, acc.nn).
  2. SmythBrobyGerberAlg: return each sum times its own count, (acc.pos * acc.cpos, acc.neg * acc.cneg, acc.nn * acc.cnn).
  3. SmythBrobyCountAlg: return the counts (acc.cpos, acc.cneg, acc.cnn).

Arguments

  • alg: Smyth-Broby algorithm marker.
  • acc: Pair accumulator, a ComovementSums. This family does not read di and dj.

Returns

  • The score triple (p, q, u) of the pair.

Related

source
PortfolioOptimisers.show_fields — Method
show_fields(_::SmythBrobyCovariance) -> NTuple{9, Symbol}

Renders every field of a SmythBrobyCovariance except cache.

A cache holds the state of an incremental fit, not a part of the configuration. Without this method, that state prints under the estimator at every site that renders one. Set set_show_nothing_fields!(:SmythBrobyCovariance, true) to render it.

Arguments

  • ::SmythBrobyCovariance: Smyth-Broby covariance estimator, read for its type alone.

Returns

  • fields::Tuple: The field names to render, which is (:ve, :me, :pdm, :c1, :c2, :c3, :n, :alg, :ex).

Related

source

References

[33]
S. Gerber, H. Markowitz, P. Ernst, Y. Miao, B. Javid and P. Sargen. The Gerber statistic: A robust co-movement measure for portfolio optimization. Available at SSRN 3880054 (2021).
[35]
W. Smyth and D. Broby. An enhanced Gerber statistic for portfolio optimization. Finance Research Letters 49, 103229 (2022).