Smyth-Broby Covariance
PortfolioOptimisers.SmythBroby0 Type
struct SmythBroby0 <: SmythBrobyCovarianceAlgorithmImplements the original Smyth-Broby covariance algorithm.
Constructors
SmythBroby0() -> SmythBroby0Examples
julia> SmythBroby0()
SmythBroby0()Related
sourcePortfolioOptimisers.SmythBroby1 Type
struct SmythBroby1 <: SmythBrobyCovarianceAlgorithmImplements the first variant of the Smyth-Broby covariance algorithm.
Constructors
SmythBroby1() -> SmythBroby1Examples
julia> SmythBroby1()
SmythBroby1()Related
sourcePortfolioOptimisers.SmythBroby2 Type
struct SmythBroby2 <: SmythBrobyCovarianceAlgorithmImplements the second variant of the Smyth-Broby covariance algorithm.
Constructors
SmythBroby2() -> SmythBroby2Examples
julia> SmythBroby2()
SmythBroby2()Related
sourcePortfolioOptimisers.SmythBrobyGerber0 Type
struct SmythBrobyGerber0 <: SmythBrobyCovarianceAlgorithmImplements the original Smyth-Broby covariance algorithm scaled by vote counts.
Constructors
SmythBrobyGerber0() -> SmythBrobyGerber0Examples
julia> SmythBrobyGerber0()
SmythBrobyGerber0()Related
sourcePortfolioOptimisers.SmythBrobyGerber1 Type
struct SmythBrobyGerber1 <: SmythBrobyCovarianceAlgorithmImplements the first variant of the Smyth-Broby covariance algorithm scaled by vote counts.
Constructors
SmythBrobyGerber1() -> SmythBrobyGerber1Examples
julia> SmythBrobyGerber1()
SmythBrobyGerber1()Related
sourcePortfolioOptimisers.SmythBrobyGerber2 Type
struct SmythBrobyGerber2 <: SmythBrobyCovarianceAlgorithmImplements the second variant of the Smyth-Broby covariance algorithm scaled by vote counts.
Constructors
SmythBrobyGerber2() -> SmythBrobyGerber2Examples
julia> SmythBrobyGerber2()
SmythBrobyGerber2()Related
sourcePortfolioOptimisers.SmythBrobyCount0 Type
struct SmythBrobyCount0 <: SmythBrobyCovarianceAlgorithmImplements the original Smyth-Broby covariance algorithm using vote counts only.
Constructors
SmythBrobyCount0() -> SmythBrobyCount0Examples
julia> SmythBrobyCount0()
SmythBrobyCount0()Related
sourcePortfolioOptimisers.SmythBrobyCount1 Type
struct SmythBrobyCount1 <: SmythBrobyCovarianceAlgorithmImplements the first variant of the Smyth-Broby covariance algorithm using vote counts only.
Constructors
SmythBrobyCount1() -> SmythBrobyCount1Examples
julia> SmythBrobyCount1()
SmythBrobyCount1()Related
sourcePortfolioOptimisers.SmythBrobyCount2 Type
struct SmythBrobyCount2 <: SmythBrobyCovarianceAlgorithmImplements the second variant of the Smyth-Broby covariance algorithm using vote counts only.
Constructors
SmythBrobyCount2() -> SmythBrobyCount2Examples
julia> SmythBrobyCount2()
SmythBrobyCount2()Related
sourcePortfolioOptimisers.SmythBrobyCovariance Type
struct SmythBrobyCovariance{__T_ve, __T_me, __T_pdm, __T_c1, __T_c2, __T_c3, __T_n, __T_alg, __T_ex} <: BaseSmythBrobyCovarianceA flexible container type for configuring and applying Smyth-Broby covariance estimators in PortfolioOptimisers.jl.
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.
Fields
ve: Variance estimator.me: Expected returns estimator. Used for optionally centering the returns.pdm: Positive definite matrix estimator.c1: Zone of confusion parameter.c2: Zone of indecision lower bound.c3: Zone of indecision upper bound.n: Exponent parameter for the Smyth-Broby kernel.alg: Smyth-Broby covariance algorithm.ex: Parallel execution strategy.
Constructors
SmythBrobyCovariance(;
ve::StatsBase.CovarianceEstimator = SimpleVariance(),
me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(),
pdm::Option{<:Posdef} = 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
c3 > c2.
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
Statistics.cov Method
Statistics.cov(ce::SmythBrobyCovariance, X::MatNum; dims::Int = 1, kwargs...)Compute the Smyth-Broby covariance matrix.
This method computes the Smyth-Broby 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 Smyth-Broby covariance is then computed via smythbroby.
Arguments
ce: Smyth-Broby covariance estimator.ce::SmythBrobyCovariance: Compute the unstandardised Smyth-Broby 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::Matrix{<:Number}: The Smyth-Broby covariance matrix.
Validation
dimsis either1or2.
Related
sourceStatistics.cor Method
Statistics.cor(ce::SmythBrobyCovariance, X::MatNum; dims::Int = 1, kwargs...)Compute the Smyth-Broby correlation matrix.
This method computes the Smyth-Broby 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 Smyth-Broby correlation is then computed via smythbroby.
Arguments
ce: Smyth-Broby covariance estimator.ce::SmythBrobyCovariance: Compute the unstandardised Smyth-Broby 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::Matrix{<:Number}: The Smyth-Broby correlation matrix.
Validation
dimsis either1or2.
Related
sourcePortfolioOptimisers.BaseSmythBrobyCovariance Type
abstract type BaseSmythBrobyCovariance <: BaseGerberCovarianceAbstract supertype for all Smyth-Broby covariance estimators in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing Smyth-Broby covariance estimation algorithms should be subtypes of BaseSmythBrobyCovariance.
Related
sourcePortfolioOptimisers.SmythBrobyCovarianceAlgorithm Type
abstract type SmythBrobyCovarianceAlgorithm <: AbstractMomentAlgorithmAbstract supertype for all Smyth-Broby covariance algorithm types in PortfolioOptimisers.jl.
All concrete and/or abstract types implementing specific Smyth-Broby covariance algorithms should be subtypes of SmythBrobyCovarianceAlgorithm.
These types are used to specify the algorithm when constructing a SmythBrobyCovariance estimator.
Related
sourcePortfolioOptimisers.sb_delta Function
sb_delta(ri::Number, rj::Number, n::Number) -> NumberSmyth-Broby kernel function for covariance and correlation computation.
This function computes the kernel value for a pair of asset returns, applying the Smyth-Broby logic for zones of confusion and indecision. It is used to aggregate positive and negative co-movements in Smyth-Broby covariance algorithms. It assumes the returns are centered around zero.
Mathematical definition
Where:
: Amplitude kernel. : Divergence measure between returns. : Absolute standardised returns for assets and .
Where:
: Smyth-Broby kernel value. : Exponent parameter controlling kernel sharpness.
Arguments
ri: Absolute standardised return for asseti.rj: Absolute standardised return for assetj.n: Exponent parameter for the kernel.
Returns
score::Number: The computed score for the pair(xi, xj).
Details
- Returns
(sqrt((1 + ri) * (1 + rj)) / (1 + abs(ri - rj)^n), 1).
Related
sourcePortfolioOptimisers.smythbroby Function
smythbroby(ce::SmythBrobyCovariance, X::MatNum, mu::ArrNum, sd::ArrNum)Compute the Smyth-Broby co-movement correlation matrix for the algorithm marker in ce.alg.
All nine variants share the pairwise kernel gerber_comovement! through a SmythBrobyKernel policy: observations are noise-gated by c1 * sigma, standardised, restricted to the [c2, c3] significance zone, and classified as concordant, discordant, or neutral by the sign of the product of standardised returns. The marker selects the accumulation family and denominator policy.
Mathematical definition
For each pair
with sb_delta kernel. The Gerber-suffixed markers additionally track the counts Count-suffixed markers use the bare counts. The variant number selects the reduction:
Where nn accumulates neutral (one-sided) observations for variant 1, and variant 2 standardises the raw matrix by the geometric mean of its diagonal.
Arguments
ce: Smyth-Broby covariance estimator.X: Data matrixobservations × featuresif thedimskeyword does not exist ordims = 1,features × observationswhendims = 2.mu: Vector of asset means.sd: Vector of asset standard deviations.
Returns
rho::Matrix{<:Number}: The Smyth-Broby correlation matrix, projected to be positive definite using the estimator'spdmfield.
Related
sourcePortfolioOptimisers.GerberComovementZero Type
Union of Gerber-family co-movement algorithm markers whose pairwise statistic is (pos - neg) / (pos + neg), guarded to zero when the denominator vanishes.
Related
sourcePortfolioOptimisers.GerberComovementOne Type
Union of Gerber-family co-movement algorithm markers whose pairwise statistic is (pos - neg) / (pos + neg + nn), including neutral co-movements in the denominator, guarded to zero when the denominator vanishes.
Related
sourcePortfolioOptimisers.GerberComovementTwo Type
Union of Gerber-family co-movement algorithm markers whose pairwise statistic is the raw pos - neg, with the resulting matrix standardised by the geometric mean of its diagonal via standardise_comovement!.
Related
sourcePortfolioOptimisers.SmythBrobyDeltaAlg Type
Union of Smyth-Broby algorithm markers that accumulate the sb_delta kernel values only.
Related
sourcePortfolioOptimisers.SmythBrobyGerberAlg Type
Union of Smyth-Broby algorithm markers that accumulate both the sb_delta kernel values and co-movement counts, scoring pairs by their product.
Related
sourcePortfolioOptimisers.SmythBrobyCountAlg Type
Union of Smyth-Broby algorithm markers that accumulate co-movement counts only.
Related
sourcePortfolioOptimisers.SmythBrobyKernel Type
struct SmythBrobyKernel{T1<:SmythBrobyCovarianceAlgorithm, T2<:(AbstractArray{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}), T3<:(AbstractArray{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}}), T4<:Number, T5<:Number, T6<:Number, T7<:Number}Co-movement policy for gerber_comovement! implementing the Smyth-Broby family.
Observations are centered and standardised per asset, thresholded by c1 * sigma (noise gate), the [c2, c3] significance zone, and classified by the sign of the product of standardised returns. The alg marker selects the accumulation family (sb_add_pos) and the denominator policy (comovement_ratio).
Fields
alg: Smyth-Broby algorithm marker.mu: Vector of asset means.sd: Vector of asset standard deviations.c1,c2,c3: Noise-gate and significance-zone thresholds.n: Exponent of thesb_deltakernel.
Related
sourcePortfolioOptimisers.gerber_comovement! Function
gerber_comovement!(
rho::AbstractMatrix,
ex::Transducers.Executor,
X::AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}},
pol
) -> AnyFill the symmetric co-movement matrix rho by running the shared Gerber-family pairwise kernel.
For every asset pair (i, j) the kernel builds the pair state via comovement_pair_state, folds every observation through comovement_step into the accumulator (pos, neg, nn, cpos, cneg, cnn) of weighted scores and counts, and stores the reduction comovement_finalise symmetrically. The policy object pol (e.g. SmythBrobyKernel, GerberIQKernel) owns the thresholding, classification, and weighting of a single observation, and the reduction of a pair's accumulator; the loop skeleton lives here once.
Arguments
rho::AbstractMatrix:N × Noutput matrix, overwritten.ex:FLoopsexecutor parallelising over the outer asset index.X: Data matrixobservations × featuresif thedimskeyword does not exist ordims = 1,features × observationswhendims = 2.pol: Co-movement policy object.
Returns
nothing.
Related
sourcePortfolioOptimisers.comovement_pair_state Function
comovement_pair_state(
pol::SmythBrobyKernel,
i::Integer,
j::Integer
) -> NamedTuple{(:mui, :muj, :sigmai, :sigmaj, :c1i, :c1j), <:NTuple{6, Any}}Build the per-pair state consumed by comovement_step.
The Smyth-Broby method returns the pair's means, standard deviations, and noise-gate thresholds c1 * sigma. The Gerber IQ method returns the pair's threshold scaling factors and scaled thresholds.
Related
sourcePortfolioOptimisers.comovement_step Function
comovement_step(
pol::SmythBrobyKernel,
acc,
st,
xi::Number,
xj::Number,
_::Integer,
_::Integer
) -> AnyFold one observation of a pair into the co-movement accumulator.
The Smyth-Broby method skips observations inside the noise gate (|x| < c1 * sigma for both assets), centers and standardises the returns, skips observations outside the [c2, c3] significance zone, and classifies the rest as concordant, discordant, or neutral by the sign of the product of standardised returns. The Gerber IQ method thresholds absolute returns against the pair's scaled thresholds and weights observations by the IQ template and temporal decay via gerber_IQ_delta.
Arguments
pol: Co-movement policy object.acc: Pair accumulator(pos, neg, nn, cpos, cneg, cnn).st: Pair state fromcomovement_pair_state.xi,xj: Returns of assetsiandjat observationk.T: Number of observations.k: Observation index.
Returns
- The updated accumulator.
Related
sourcePortfolioOptimisers.comovement_finalise Function
comovement_finalise(
pol::SmythBrobyKernel,
acc,
_::Type{T}
) -> AnyReduce a pair's accumulator to the pairwise co-movement statistic.
Selects the family scores (for Smyth-Broby, via sb_pair_scores) and applies the variant's denominator policy via comovement_ratio.
Related
sourcePortfolioOptimisers.comovement_ratio Function
comovement_ratio(
_::Union{Gerber0, SmythBroby0, SmythBrobyCount0, SmythBrobyGerber0},
p::Number,
n::Number,
nn::Number,
_::Type{T}
) -> AnyReduce a pair's accumulated positive, negative, and neutral co-movement scores to the pairwise correlation entry.
The variant marker selects the denominator policy:
GerberComovementZero:(p - n) / (p + n), orzero(T)when the denominator is zero.GerberComovementOne:(p - n) / (p + n + nn), orzero(T)when the denominator is zero.GerberComovementTwo: rawp - n; the matrix is standardised afterwards bystandardise_comovement!.
Arguments
alg: Co-movement algorithm marker.p,n,nn: Accumulated positive, negative, and neutral scores.T: Element type used for the guarded zero.
Returns
- The pairwise co-movement statistic.
Related
sourcePortfolioOptimisers.standardise_comovement! Function
standardise_comovement!(_, _::AbstractMatrix)Standardise a raw co-movement matrix by the geometric mean of its diagonal.
Only the GerberComovementTwo variants standardise; the fall-through method is a no-op. Divides each entry by sqrt(rho[i, i] * rho[j, j]), clamping the diagonal roots away from zero.
Returns
nothing.
Related
sourcePortfolioOptimisers.sb_add_pos Function
sb_add_pos(
_::Union{SmythBroby0, SmythBroby1, SmythBroby2},
acc,
ari::Number,
arj::Number,
n::Number
) -> Union{NamedTuple, DataStructures.SortedMultiDict}Accumulate a concordant observation into the pair accumulator, according to the Smyth-Broby family of alg.
SmythBrobyDeltaAlg: addssb_deltato the weighted score.SmythBrobyGerberAlg: addssb_deltato the weighted score and increments the count.SmythBrobyCountAlg: increments the count only.
Related
sourcePortfolioOptimisers.sb_add_neg Function
sb_add_neg(
_::Union{SmythBroby0, SmythBroby1, SmythBroby2},
acc,
ari::Number,
arj::Number,
n::Number
) -> Union{NamedTuple, DataStructures.SortedMultiDict}Accumulate a discordant observation into the pair accumulator, according to the Smyth-Broby family of alg.
Mirrors sb_add_pos on the negative score and count.
Related
sourcePortfolioOptimisers.sb_add_neutral Function
sb_add_neutral(
_::SmythBroby1,
acc,
ari::Number,
arj::Number,
n::Number
) -> Union{NamedTuple, DataStructures.SortedMultiDict}Accumulate a neutral (one-sided) observation into the pair accumulator.
Only the GerberComovementOne variants track neutral co-movements, mirroring sb_add_pos on the neutral score and count; the fall-through method returns the accumulator unchanged.
Related
sourcePortfolioOptimisers.sb_pair_scores Function
sb_pair_scores(
_::Union{SmythBroby0, SmythBroby1, SmythBroby2},
acc
) -> Tuple{Any, Any, Any}Select the pair's positive, negative, and neutral scores from the accumulator, according to the Smyth-Broby family of alg.
SmythBrobyDeltaAlg: the weighted scores.SmythBrobyGerberAlg: the products of weighted scores and counts.SmythBrobyCountAlg: the counts.
Related
source