Shrunk Expected Returns

PortfolioOptimisers.GrandMean — Type
struct GrandMean <: AbstractShrunkExpectedReturnsTarget

Fills the shrinkage target with the grand mean of the sample expected returns.

Every element of the target holds the same value, so a shrinkage estimator pulls each asset toward the average of the whole universe. The three targets are each a multiple of the vector of ones, and only the multiplier separates them.

Mathematical definition

\[\begin{align} b_j &= \bar{\mu} = \frac{1}{N} \sum_{i=1}^{N} \hat{\mu}_i\,, \quad j = 1, \ldots, N\,. \end{align}\]

Where:

  • $b_j$: $j$-th entry of the shrinkage target vector.
  • $\hat{\boldsymbol{\mu}}$: $N \times 1$ vector of sample expected returns, whose $i$-th entry is $\hat{\mu}_i$.
  • $N$: Number of assets.

This target is the only one of the three that does not read the covariance matrix.

Equation 4.141 of [52] states this target as the scenario-dependent grand mean. Section 3.3.1 of [53] lists it and credits [52] with it. The method computes it from the same sample as the mean that it shrinks.

Algorithm

The branch of target_mean that this tag selects does these steps.

  1. Take the unweighted mean of mu as val.
  2. Return the constant range that repeats val length(mu) times.

Constructors

GrandMean() -> GrandMean

Examples

julia> GrandMean()GrandMean()

Related

References

  • [52] A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005). Section 4.4, Equation 4.141.
source
PortfolioOptimisers.VolatilityWeighted — Type
struct VolatilityWeighted <: AbstractShrunkExpectedReturnsTarget

Fills the shrinkage target with the inverse-covariance-weighted mean of the sample expected returns.

The weights come from the inverse covariance matrix. Under a diagonal covariance matrix, each weight is proportional to the reciprocal of the variance of its asset, so an asset with a larger variance gets a smaller weight. The name says volatility, but the form reads the whole inverse covariance matrix. An off-diagonal entry of the covariance matrix also changes the target.

Mathematical definition

\[\begin{align} b_j &= \bar{\mu}_{\mathrm{vol}} = \frac{\boldsymbol{1}^\intercal \hat{\mathbf{\Sigma}}^{-1} \hat{\boldsymbol{\mu}}}{\boldsymbol{1}^\intercal \hat{\mathbf{\Sigma}}^{-1} \boldsymbol{1}}\,, \quad j = 1, \ldots, N\,. \end{align}\]

Where:

  • $b_j$: $j$-th entry of the shrinkage target vector.
  • $\hat{\boldsymbol{\mu}}$: $N \times 1$ vector of sample expected returns, whose $i$-th entry is $\hat{\mu}_i$.
  • $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
  • $\boldsymbol{1}$: $N \times 1$ vector of ones.
  • $N$: Number of assets.

Algorithm

The branch of target_mean that this tag selects does these steps.

  1. When isigma is nothing, solve sigma \ LinearAlgebra.I as isigma. A caller that already has the inverse passes it, so the solve runs at most once for each estimate.
  2. When mu has one row, flatten it with vec, so that the product isigma * mu is defined.
  3. Divide the sum of isigma * mu by the sum of isigma as val. The sum of the matrix-vector product is the numerator $\boldsymbol{1}^\intercal \hat{\mathbf{\Sigma}}^{-1} \hat{\boldsymbol{\mu}}$. The sum of the matrix is the denominator $\boldsymbol{1}^\intercal \hat{\mathbf{\Sigma}}^{-1} \boldsymbol{1}$.
  4. Return the constant range that repeats val length(mu) times.

This target is the only one of the three that inverts the covariance matrix, so a singular covariance matrix raises a LinearAlgebra.SingularException here and nowhere else in target_mean.

Equation 14 of [54] defines this quotient as the grand mean $Y_0$. It notes that the quotient is the average return of the minimum variance portfolio. Equation 4.142 of [52] states it as the volatility-weighted grand mean and credits [54] with it. The method computes it from the same sample as the mean that it shrinks.

Constructors

VolatilityWeighted() -> VolatilityWeighted

Examples

julia> VolatilityWeighted()VolatilityWeighted()

Related

References

  • [54] P. Jorion. Bayes-Stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis 21, 279–292 (1986). Section IV, Equation 14.
  • [52] A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005). Section 4.4, Equation 4.142.
source
PortfolioOptimisers.MeanSquaredError — Type
struct MeanSquaredError <: AbstractShrunkExpectedReturnsTarget

Fills the shrinkage target with the trace of the covariance matrix divided by the number of observations.

Every element of the target holds the same value. The target reads only the covariance matrix, and not the sample expected returns. A shift of the mean of every asset by one constant moves the other two targets by that constant, and leaves this target as it is.

Mathematical definition

\[\begin{align} b_j &= \frac{\mathrm{tr}(\hat{\mathbf{\Sigma}})}{T}\,, \quad j = 1, \ldots, N\,. \end{align}\]

Where:

  • $b_j$: $j$-th entry of the shrinkage target vector.
  • $\mathrm{tr}(\cdot)$: Matrix trace operator.
  • $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
  • $T$: Number of observations.
  • $N$: Number of assets.

Algorithm

The branch of target_mean that this tag selects does these steps.

  1. Divide the trace of sigma by T as val. Only this branch needs the keyword T.
  2. Return the constant range that repeats val length(mu) times.

Equation 4.136 of [52] states that $\mathrm{tr}(\mathbf{\Sigma}) / T$ is the error $\mathbb{E}\lVert \hat{\boldsymbol{\mu}} - \boldsymbol{\mu} \rVert_2^2$ of the sample mean. Equation 3.29 of [53] restates it. Equation 3.43 of [12] uses that value as a shrinkage target. The search for the original source found no earlier work that does so, so the target follows [12].

Constructors

MeanSquaredError() -> MeanSquaredError

Examples

julia> MeanSquaredError()MeanSquaredError()

Related

References

  • [52] A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005). Section 4.4, Equation 4.136.
  • [53] Y. Feng and D. P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends in Signal Processing 9, 1–231 (2016). Section 3.3.1, Equation 3.29.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Equation 3.43. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
source
PortfolioOptimisers.AbstractShrunkExpectedReturnsIntensity — Type
abstract type AbstractShrunkExpectedReturnsIntensity <: AbstractExpectedReturnsAlgorithm

Chooses the interval that holds the shrinkage intensity of a blend of the sample expected returns and the target.

JamesStein and BayesStein hold a member of this family, or nothing, in their field intensity. Each computes the blend $(1 - \alpha) \hat{\boldsymbol{\mu}} + \alpha \boldsymbol{b}$. The member takes the raw intensity $\alpha$ of the formula and returns the intensity that the blend uses. UnitIntervalIntensity keeps the blend on the segment that joins the sample mean and the target. NonNegativeIntensity keeps it on the ray that starts at the sample mean and goes through the target. nothing applies no clamp, and the blend uses the raw intensity. It does not turn the shrinkage off.

Interfaces

To add a rule for the shrinkage intensity, subtype AbstractShrunkExpectedReturnsIntensity, keep its parameters in the fields of the struct, and add this method:

shrinkage_intensity

  • shrinkage_intensity(rule::MyShrunkExpectedReturnsIntensity, alpha::Number) -> Number: Returns the intensity that the blend uses.

Arguments

  • rule: The member of the family.
  • alpha: The raw intensity of the formula of the algorithm.

Returns

  • alpha::Number: The intensity that the blend uses.

Related

source
PortfolioOptimisers.UnitIntervalIntensity — Type
struct UnitIntervalIntensity <: AbstractShrunkExpectedReturnsIntensity

Clamps the shrinkage intensity into $[0, 1]$.

The blend then lies on the segment that joins the sample expected returns and the target. An intensity below zero gives the sample mean, and an intensity above one gives the target. This is the default rule of JamesStein and BayesStein.

Mathematical definition

\[\begin{align} \alpha^{\prime} &= \min\left(\max\left(\alpha,\, 0\right),\, 1\right)\,. \end{align}\]

Where:

  • $\alpha$: The raw intensity of the formula of the algorithm.
  • $\alpha^{\prime}$: The intensity that the blend uses.

Equation 4.139 of [52] gives the James-Stein intensity. The text after it constrains the weight to the interval $(0, 1)$. This rule includes the two ends of that interval, so the blend can be equal to the sample mean or to the target.

Examples

julia> PortfolioOptimisers.shrinkage_intensity(UnitIntervalIntensity(), -2.5)0.0julia> PortfolioOptimisers.shrinkage_intensity(UnitIntervalIntensity(), 1.5)1.0

Related

References

  • [52] A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005). Section 4.4, Equations 4.138 and 4.139.
source
PortfolioOptimisers.NonNegativeIntensity — Type
struct NonNegativeIntensity <: AbstractShrunkExpectedReturnsIntensity

Clamps the shrinkage intensity at zero from below.

An intensity below zero gives the sample expected returns. The rule keeps an intensity above one, so the blend can go past the target.

Mathematical definition

\[\begin{align} \alpha^{\prime} &= \max\left(\alpha,\, 0\right)\,. \end{align}\]

Where:

  • $\alpha$: The raw intensity of the formula of the algorithm.
  • $\alpha^{\prime}$: The intensity that the blend uses.

Equation 3.31 of [53] takes the James-Stein intensity "if it is positive, otherwise it is zero". The James-Stein intensity is negative exactly when $\mathrm{tr}(\hat{\mathbf{\Sigma}}) < 2 \lambda_{\max}$. Theorem 1 of [55] shows that, under this condition, the only minimax estimator of its class is the sample mean. The text after Theorem 5.7 of [56] states the same.

Examples

julia> PortfolioOptimisers.shrinkage_intensity(NonNegativeIntensity(), -2.5)0.0julia> PortfolioOptimisers.shrinkage_intensity(NonNegativeIntensity(), 1.5)1.5

Related

References

  • [53] Y. Feng and D. P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends in Signal Processing 9, 1–231 (2016). Section 3.3.1, Equation 3.31.
  • [55] M. E. Bock. Minimax estimators of the mean of a multivariate normal distribution. The Annals of Statistics 3, 209–218 (1975). Theorem 1.
  • [56] E. L. Lehmann and G. Casella. Theory of Point Estimation. 2nd ed. (Springer, 1998). Section 5.5, Theorem 5.7.
source
PortfolioOptimisers.shrinkage_intensity — Function
shrinkage_intensity(rule::UnitIntervalIntensity, alpha::Number) -> Number
shrinkage_intensity(rule::NonNegativeIntensity, alpha::Number) -> Number
shrinkage_intensity(::Nothing, alpha::Number) -> Number

Return the intensity that a blend of the sample expected returns and the target uses, from the raw intensity alpha.

UnitIntervalIntensity and NonNegativeIntensity state their formulas. nothing applies no clamp and returns alpha unchanged, so the blend can move away from the target or go past it. The move can be large. A covariance matrix whose largest eigenvalue is more than half of its trace gives a negative James-Stein intensity, and a small distance between the sample mean and the target makes the magnitude of that intensity large. Equation 6 of [57] does not clamp its factor. A NaN stays a NaN under each rule.

Arguments

Returns

  • alpha::Number: The intensity that the blend uses.

Examples

julia> PortfolioOptimisers.shrinkage_intensity(nothing, -2.5)-2.5

Related

References

  • [57] W. James and C. Stein. Estimation with quadratic loss. In: Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability, Volume 1, 361–379 (University of California Press, 1961). Section 2, Equation 6.
source
PortfolioOptimisers.JamesStein — Type
struct JamesStein{__T_tgt, __T_intensity} <: AbstractShrunkExpectedReturnsAlgorithm

Blends the sample expected returns with the target under an intensity read off the covariance eigenvalues.

The intensity is the trace of the covariance matrix minus twice its largest eigenvalue, divided by the number of observations and by the squared distance between the sample mean and the target.

Fields

  • tgt: Shrinkage target.
  • intensity: The rule that sets the interval of the shrinkage intensity. It is a member of AbstractShrunkExpectedReturnsIntensity, or nothing for no clamp. nothing keeps the shrinkage and uses the raw intensity of the formula.

Constructors

JamesStein(;    tgt::AbstractShrunkExpectedReturnsTarget = GrandMean(),    intensity::Option{<:AbstractShrunkExpectedReturnsIntensity} = UnitIntervalIntensity()) -> JamesStein

Keywords correspond to the struct's fields. The default intensity keeps the blend on the segment that joins the sample mean and the target. The intensity of the formula is negative when the largest eigenvalue of the covariance matrix is more than half of its trace. intensity = nothing applies no clamp, so it keeps that negative value.

Examples

julia> JamesStein()JamesStein        tgt ┼ GrandMean()  intensity ┴ UnitIntervalIntensity()

Related

References

  • [57] W. James and C. Stein. Estimation with quadratic loss. In: Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability, Volume 1, 361–379 (University of California Press, 1961). Section 2, Equation 6.
  • [55] M. E. Bock. Minimax estimators of the mean of a multivariate normal distribution. The Annals of Statistics 3, 209–218 (1975). Theorems 1 and 2.
  • [52] A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005). Section 4.4, Equations 4.138 and 4.139.
  • [56] E. L. Lehmann and G. Casella. Theory of Point Estimation. 2nd ed. (Springer, 1998). Section 5.5, Theorem 5.7.
source
PortfolioOptimisers.BayesStein — Type
struct BayesStein{__T_tgt, __T_intensity} <: AbstractShrunkExpectedReturnsAlgorithm

Blends the sample expected returns with the target under an empirical Bayes intensity.

The intensity falls as the number of observations increases, and as the distance between the sample mean and the target increases. The inverse covariance matrix weights that distance. A short sample therefore moves the estimate further toward the target.

Fields

  • tgt: Shrinkage target.
  • intensity: The rule that sets the interval of the shrinkage intensity. It is a member of AbstractShrunkExpectedReturnsIntensity, or nothing for no clamp. nothing keeps the shrinkage and uses the raw intensity of the formula.

Constructors

BayesStein(;    tgt::AbstractShrunkExpectedReturnsTarget = GrandMean(),    intensity::Option{<:AbstractShrunkExpectedReturnsIntensity} = UnitIntervalIntensity()) -> BayesStein

Keywords correspond to the struct's fields. The intensity of the formula lies in $(0, 1]$ when the covariance matrix is positive definite. The field intensity therefore changes the result only for a covariance estimator that returns an indefinite matrix.

Examples

julia> BayesStein()BayesStein        tgt ┼ GrandMean()  intensity ┴ UnitIntervalIntensity()

Related

References

  • [54] P. Jorion. Bayes-Stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis 21, 279–292 (1986). Section IV, Equations 14, 17 and 18.
source
PortfolioOptimisers.BodnarOkhrinParolya — Type
struct BodnarOkhrinParolya{__T_tgt} <: AbstractShrunkExpectedReturnsAlgorithm

Combines the sample expected returns and the target under two coefficients from random matrix theory.

The method computes the two coefficients separately, and neither is a convex weight. The result is therefore not a blend of the sample mean and the target. The algorithm is for a universe whose number of assets is a large fraction of its number of observations. It needs more observations than assets.

Fields

  • tgt: Shrinkage target.

Constructors

BodnarOkhrinParolya(;    tgt::AbstractShrunkExpectedReturnsTarget = GrandMean()) -> BodnarOkhrinParolya

Keywords correspond to the struct's fields.

Examples

julia> BodnarOkhrinParolya()BodnarOkhrinParolya  tgt ┴ GrandMean()

Related

References

  • [58] T. Bodnar, O. Okhrin and N. Parolya. Optimal shrinkage estimator for high-dimensional mean vector. Journal of Multivariate Analysis 170, 63–79 (2019). Section 3, Theorem 3, Equations 6 and 7.
source
PortfolioOptimisers.ShrunkExpectedReturns — Type
struct ShrunkExpectedReturns{__T_me, __T_ce, __T_alg} <: AbstractShrunkExpectedReturnsEstimator

Shrinks the sample expected returns toward a target chosen by the shrinkage algorithm.

It holds a mean estimator, a covariance estimator and a shrinkage algorithm. The shrinkage algorithm holds the target.

Fields

  • me: Expected returns estimator.
  • ce: Covariance estimator.
  • alg: The shrinkage algorithm. It holds the shrinkage target.

Constructors

ShrunkExpectedReturns(;    me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(),    ce::StatsBase.CovarianceEstimator = PortfolioOptimisersCovariance(),    alg::AbstractShrunkExpectedReturnsAlgorithm = JamesStein()) -> ShrunkExpectedReturns

Keywords correspond to the struct's fields.

Validation

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • me: Recursively updated through factory.
  • ce: Recursively updated through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Examples

julia> ShrunkExpectedReturns()ShrunkExpectedReturns   me ┼ SimpleExpectedReturns      │   w ┴ nothing   ce ┼ PortfolioOptimisersCovariance      │   ce ┼ Covariance      │      │    me ┼ SimpleExpectedReturns      │      │       │   w ┴ nothing      │      │    ce ┼ GeneralCovariance      │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)      │      │       │    w ┴ nothing      │      │   alg ┼ FullMoment()      │      │     w ┴ nothing      │   mp ┼ MatrixProcessing      │      │     pdm ┼ Posdef      │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton      │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()      │      │      dn ┼ nothing      │      │      dt ┼ nothing      │      │     alg ┼ nothing      │      │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)  alg ┼ JamesStein      │         tgt ┼ GrandMean()      │   intensity ┴ UnitIntervalIntensity()

Related

source
Statistics.mean — Method
Statistics.mean(me::ShrunkExpectedReturns, X::MatNum; dims::Int = 1, kwargs...)

Compute the shrunk expected returns of the estimator me.

The method moves the sample expected returns toward a target. The aim is a smaller estimation error of the mean when the number of assets is large compared with the number of observations. JamesStein and BayesStein return (1 - alpha) * mu + alpha * b. The member of AbstractShrunkExpectedReturnsIntensity in their field intensity sets the interval of alpha. The default UnitIntervalIntensity clamps alpha into $[0, 1]$, so the result lies on the segment that joins the sample mean and the target. Under intensity = nothing, no clamp applies, and the result can lie outside that segment. BodnarOkhrinParolya computes its two coefficients separately. They do not sum to one, and no rule clamps them.

Every formula below reads $T$ as the number of observations that the mean of me.me is worth, from effective_observation_count. An unweighted mean is worth the rows of X. A weighted mean is worth the count of its weights, because the variance of a weighted mean of independent draws is the covariance divided by that count.

Mathematical definition

James-Stein shrinkage of the sample expected returns toward the target:

\[\begin{align} \hat{\boldsymbol{\mu}}_{JS} &= (1 - \alpha^{\prime})\, \hat{\boldsymbol{\mu}} + \alpha^{\prime}\, \boldsymbol{b}\,, \\ \alpha &= \frac{N \bar{\lambda} - 2 \lambda_{\max}}{T \, \lVert \hat{\boldsymbol{\mu}} - \boldsymbol{b} \rVert_2^2}\,. \end{align}\]

Where:

  • $\hat{\boldsymbol{\mu}}_{JS}$: James-Stein shrunk expected returns.
  • $\hat{\boldsymbol{\mu}}$: $N \times 1$ vector of sample expected returns, whose $i$-th entry is $\hat{\mu}_i$.
  • $\boldsymbol{b}$: $N \times 1$ shrinkage target vector, every entry of which holds the same value.
  • $\alpha$: Shrinkage intensity, the weight the blend gives the target.
  • $\alpha^{\prime}$: The intensity that the member in intensity returns from $\alpha$. It is $\min(\max(\alpha, 0), 1)$ under the default UnitIntervalIntensity.
  • $\bar{\lambda}$: Mean eigenvalue of the covariance matrix.
  • $\lambda_{\max}$: Maximum eigenvalue of the covariance matrix.
  • $T$: Number of observations.
  • $N$: Number of assets.

The form has these limits.

  • $N \bar{\lambda}$ is the trace of the covariance matrix. Thus $N \bar{\lambda} \leq 2 \lambda_{\max}$ when $N \leq 2$. For any $N$, it also holds when the largest eigenvalue is at least half of the trace, as with one dominant factor. The intensity $\alpha$ is then not positive.
  • Under that condition, UnitIntervalIntensity and NonNegativeIntensity return the sample mean. Under intensity = nothing, the blend moves away from the target. Theorem 1 of [55] gives the same condition, $\mathrm{tr}(\mathbf{D}) \leq 2 d_L$. Under it, the only minimax estimator of its class is the sample mean.
  • The denominator is zero when the target is equal to the sample mean. GrandMean and VolatilityWeighted are both equal to the sample mean at $N = 1$, so a one-asset sample raises a DomainError under either of them. MeanSquaredError does not read the sample mean, so it stays finite there.

Equation 6 of [57] shrinks a normal mean with an identity covariance matrix toward the origin by the factor $1 - (N - 2) / \lVert \boldsymbol{x} \rVert_2^2$. It does not clamp the factor. Theorem 2 of [55] extends the minimax property to a known covariance matrix $\mathbf{D}$ that is not the identity, for $N > 2$ and $\mathrm{tr}(\mathbf{D}) \geq 2 d_L$. The factor is $1 - c / (\boldsymbol{x}^\intercal \mathbf{D}^{-1} \boldsymbol{x})$, with $0 \leq c \leq 2 (\mathrm{tr}(\mathbf{D}) / d_L - 2)$, where $d_L$ is the largest eigenvalue of $\mathbf{D}$.

The intensity above divides by the squared Euclidean norm and not by the $\mathbf{D}^{-1}$ quadratic form, so it is not the form of [55]. It is Equation 4.139 of [52], which sets the weight of Equation 4.138. That equation writes $N \bar{\lambda} - 2 \lambda_{\max}$ for $\mathrm{tr}(\mathbf{\Sigma}) - 2 \lambda_{\max}$. Equation 3.31 of [53] restates it.

Theorem 5.7 of [56] states the Euclidean form $(1 - c(\lVert \boldsymbol{x} \rVert_2^2) / \lVert \boldsymbol{x} \rVert_2^2) \boldsymbol{x}$ for a known covariance matrix. It requires that $c \geq 0$ and that $c$ is nondecreasing. It notes that the estimator differs from $\boldsymbol{x}$ only when $\mathrm{tr}(\mathbf{\Sigma}) > 2 \lambda_{\max}$. The covariance matrix of the sample mean is $\hat{\mathbf{\Sigma}} / T$, so the constant of this method is $c = (\mathrm{tr}(\hat{\mathbf{\Sigma}}) - 2 \lambda_{\max}) / T$.

The theorem prints the upper bound $2 \mathrm{tr}(\mathbf{\Sigma}) / \lambda_{\max} - 4$. This bound does not scale with $\mathbf{\Sigma}$ as $c$ does. Its Equation 5.15 writes the factor $(c + 4) \boldsymbol{x}^\intercal \mathbf{\Sigma} \boldsymbol{x} / \lVert \boldsymbol{x} \rVert_2^2$. Stein's identity gives $c + 4 \boldsymbol{x}^\intercal \mathbf{\Sigma} \boldsymbol{x} / \lVert \boldsymbol{x} \rVert_2^2$. With that term, Equation 5.16 gives the bound $0 \leq c \leq 2 (\mathrm{tr}(\mathbf{\Sigma}) - 2 \lambda_{\max})$. The constant of this method is the midpoint of that interval, which minimises the bound on the risk.

Algorithm

  1. Compute the sample expected returns mu with me.me.
  2. Compute the covariance matrix sigma with me.ce.
  3. Read T and N off size(X). Swap them when dims is 2.
  4. Compute the shrinkage target b with target_mean. Transpose it into a row when dims is 1.
  5. Compute the eigenvalues evals of sigma.
  6. Subtract b from mu as mb. Compute the intensity alpha from evals, mb, N and T.
  7. Pass alpha through shrinkage_intensity with the member in me.alg.intensity.
  8. Return the blend (1 - alpha) * mu + alpha * b.

Arguments

  • me: The shrunk expected returns estimator.

    • me::ShrunkExpectedReturns{<:Any, <:Any, <:JamesStein}: Use the James-Stein algorithm.
    • me::ShrunkExpectedReturns{<:Any, <:Any, <:BayesStein}: Use the Bayes-Stein algorithm.
    • me::ShrunkExpectedReturns{<:Any, <:Any, <:BodnarOkhrinParolya}: Use the Bodnar-Okhrin-Parolya algorithm.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.

  • dims: Dimension along which the computation runs.

  • kwargs...: More keyword arguments. The method passes them to the mean estimator and to the covariance estimator.

Validation

  • !iszero(dot(mu - b, mu - b)). The JamesStein intensity divides by this value. It is exactly zero when the target is equal to the sample mean. GrandMean and VolatilityWeighted are both equal to the sample mean at $N = 1$. The other two overloads state their own checks.

Returns

  • mu::ArrNum: Expected returns vector assets x 1 if the dims keyword does not exist or dims = 2, 1 x assets if dims = 1.

Related

References

  • [57] W. James and C. Stein. Estimation with quadratic loss. In: Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability, Volume 1, 361–379 (University of California Press, 1961). Section 2, Equation 6.
  • [55] M. E. Bock. Minimax estimators of the mean of a multivariate normal distribution. The Annals of Statistics 3, 209–218 (1975). Theorems 1 and 2.
  • [52] A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005). Section 4.4, Equations 4.138 and 4.139.
  • [56] E. L. Lehmann and G. Casella. Theory of Point Estimation. 2nd ed. (Springer, 1998). Section 5.5, Theorem 5.7.
  • [53] Y. Feng and D. P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends in Signal Processing 9, 1–231 (2016). Section 3.3.1, Equation 3.31.
source
Statistics.mean — Method
mean(
    me::ShrunkExpectedReturns{<:Any, <:Any, <:BayesStein},
    X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}};
    dims,
    kwargs...
) -> Any

BayesStein overload of mean(me::ShrunkExpectedReturns, X::MatNum; dims::Int = 1, kwargs...). Shrinks the sample expected returns toward the target under the empirical Bayes intensity of [54]. The intensity reads the inverse covariance matrix.

Mathematical definition

Bayes-Stein shrinkage of the sample expected returns toward the target:

\[\begin{align} \alpha &= \frac{N + 2}{(N + 2) + T \, (\hat{\boldsymbol{\mu}} - \boldsymbol{b})^\intercal \hat{\mathbf{\Sigma}}^{-1} (\hat{\boldsymbol{\mu}} - \boldsymbol{b})}\,, \\ \hat{\boldsymbol{\mu}}_{BS} &= (1 - \alpha)\hat{\boldsymbol{\mu}} + \alpha \boldsymbol{b}\,. \end{align}\]

Where:

  • $\alpha$: Shrinkage intensity, the weight the blend gives the target.
  • $\hat{\boldsymbol{\mu}}_{BS}$: Bayes-Stein shrunk expected returns.
  • $\hat{\boldsymbol{\mu}}$: $N \times 1$ vector of sample expected returns, whose $i$-th entry is $\hat{\mu}_i$.
  • $\boldsymbol{b}$: $N \times 1$ shrinkage target vector, every entry of which holds the same value.
  • $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
  • $T$: Number of observations.
  • $N$: Number of assets.

The form has these properties.

  • The quadratic form is non-negative when $\hat{\mathbf{\Sigma}}$ is positive definite, so $\alpha$ then lies in $(0, 1]$. Of the three algorithms, only this one gives a convex weight without a clamp. It returns the target exactly when the quadratic form is zero.
  • When a covariance estimator returns an indefinite matrix, $\alpha$ can lie outside $(0, 1]$. The member in intensity then sets the interval, as for JamesStein. Under the default UnitIntervalIntensity, the blend stays on the segment.
  • The quadratic form uses the inverse of the covariance matrix that me.ce returns. Equation 18 of [54] puts the bias-corrected matrix $\bar{\mathbf{\Sigma}} = \frac{T-1}{T-N-2} \mathbf{S}$ in the quadratic form. $\mathbf{S}$ is the sample covariance matrix that divides by $T - 1$.
  • Equation 3.44 of [12] writes the factor $\frac{T-1}{T-N-1}$ instead. This method uses $\hat{\mathbf{\Sigma}}$ and applies neither factor. Both factors are more than one. Each of them makes $\alpha$ larger when it multiplies the matrix.

Equation 17 of [54] is this intensity. Equation 14 of that work gives its target, the minimum variance grand mean of VolatilityWeighted. Equation 3.44 of [12] lets the target take the same values as for JamesStein. The use of GrandMean and MeanSquaredError here follows [12] alone.

Algorithm

  1. Compute the sample expected returns mu with me.me.
  2. Compute the covariance matrix sigma with me.ce.
  3. Read T and N off size(X). Swap them when dims is 2.
  4. Solve sigma \ LinearAlgebra.I as isigma. Pass it to target_mean, so that the VolatilityWeighted branch does not solve a second time.
  5. Compute the shrinkage target b. Transpose it into a row when dims is 1.
  6. Flatten mu - b with vec as mb. Compute the intensity alpha from mb, isigma, N and T.
  7. Pass alpha through shrinkage_intensity with the member in me.alg.intensity.
  8. Return the blend (1 - alpha) * mu + alpha * b.

Related

References

  • [54] P. Jorion. Bayes-Stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis 21, 279–292 (1986). Section IV, Equations 14, 17 and 18.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 3.4.1.2, Equation 3.44. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
source
Statistics.mean — Method
mean(
    me::ShrunkExpectedReturns{<:Any, <:Any, <:BodnarOkhrinParolya},
    X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}};
    dims,
    kwargs...
) -> Any

BodnarOkhrinParolya overload of mean(me::ShrunkExpectedReturns, X::MatNum; dims::Int = 1, kwargs...). Combines the sample expected returns and the target under the two coefficients of [58]. It needs $T > N$. The term $N/(T-N)$ is undefined at $T = N$ and changes sign below it, so a square or wide returns matrix raises a DomainError.

Mathematical definition

The method computes three products of the sample mean and the target, weighted by the inverse covariance matrix:

\[\begin{align} u &= \hat{\boldsymbol{\mu}}^\intercal \hat{\mathbf{\Sigma}}^{-1} \hat{\boldsymbol{\mu}}\,, \\ v &= \boldsymbol{b}^\intercal \hat{\mathbf{\Sigma}}^{-1} \boldsymbol{b}\,, \\ w &= \hat{\boldsymbol{\mu}}^\intercal \hat{\mathbf{\Sigma}}^{-1} \boldsymbol{b}\,. \end{align}\]

The two coefficients and the combination follow from them:

\[\begin{align} \alpha &= \frac{(u - N/(T-N))v - w^2}{uv - w^2}\,, \\ \beta &= \frac{(1-\alpha) w}{v}\,, \\ \hat{\boldsymbol{\mu}}_{BOP} &= \alpha \hat{\boldsymbol{\mu}} + \beta \boldsymbol{b}\,. \end{align}\]

Where:

  • $u$, $v$, $w$: The three products above.
  • $\alpha$, $\beta$: The coefficients of the sample mean and of the target.
  • $\hat{\boldsymbol{\mu}}_{BOP}$: Bodnar-Okhrin-Parolya shrunk expected returns.
  • $\hat{\boldsymbol{\mu}}$: $N \times 1$ vector of sample expected returns, whose $i$-th entry is $\hat{\mu}_i$.
  • $\boldsymbol{b}$: $N \times 1$ shrinkage target vector, every entry of which holds the same value.
  • $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
  • $T$: Number of observations.
  • $N$: Number of assets.

The form has these properties, which the other two algorithms do not have.

  • The method computes $\alpha$ and $\beta$ separately, and they do not sum to one. The result is therefore not a point on the segment that joins $\hat{\boldsymbol{\mu}}$ and $\boldsymbol{b}$.
  • The $w^2$ terms cancel, so $\alpha = 1 - \frac{N}{T-N} \frac{v}{uv - w^2}$. Thus $\alpha < 1$ always, and $\alpha < 0$ exactly when $\frac{N}{T-N} v > uv - w^2$. The combination then moves away from the sample mean.
  • $uv - w^2$ is a Cauchy-Schwarz gap in the inner product $\langle \boldsymbol{x}, \boldsymbol{y} \rangle = \boldsymbol{x}^\intercal \hat{\mathbf{\Sigma}}^{-1} \boldsymbol{y}$. It is zero exactly when the target is a multiple of the sample mean. At $N = 1$ every vector is such a multiple, so a one-asset sample raises a DomainError under all three targets.
  • $\beta \boldsymbol{b}$ is the projection of $(1-\alpha) \hat{\boldsymbol{\mu}}$ onto the line through $\boldsymbol{b}$ in the same inner product. It depends on the direction of the target and not on its scale.
  • Every target of this file is a multiple of the vector of ones, $\boldsymbol{b} = c \boldsymbol{1}$, so $v$ scales with $c^2$ and $w$ with $c$. The factor cancels in $\alpha$ and in $\beta \boldsymbol{b}$, so the three targets return the same estimate on one sample.

The coefficient $\alpha$ is Equation 6 of [58]. The coefficient $\beta$ is Equation 7, which divides by the quadratic form $v$ of the target. Equation 3.45 of [12] divides by $u$ instead. That quotient does not minimise the quadratic loss from which [58] derives both coefficients, so this method follows [58].

This method differs from Section 3 of [58] in three ways.

  • That section computes the coefficients from the sample covariance matrix that divides by the number of observations. This method uses the matrix that me.ce returns, which divides by $T - 1$ under the default estimator.
  • That section takes a target that does not depend on the sample. The three targets of this file read the same sample as the mean.
  • That section also gives a suboptimal rule that uses a generalised inverse for $N / T > 1$. This method does not implement it.

Algorithm

  1. Compute the sample expected returns mu with me.me.
  2. Compute the covariance matrix sigma with me.ce.
  3. Read T and N off size(X). Swap them when dims is 2.
  4. Solve sigma \ LinearAlgebra.I as isigma. Pass it to target_mean, so that the VolatilityWeighted branch does not solve a second time.
  5. Compute the shrinkage target b. Transpose it into a row when dims is 1.
  6. When dims is 1, flatten mu and b with vec as vm and vb. When dims is 2, use mu and b as they are.
  7. Compute the three products u, v and w from vm, vb and isigma.
  8. Compute alpha from u, v, w, N and T. Then compute beta from alpha, w and v.
  9. Return the combination alpha * mu + beta * b.

Validation

  • T > N. This is the condition that [58] publishes for the estimator. The term $N/(T-N)$ is undefined at $T = N$ and negative below it.
  • !iszero(u * v - w^2). Both coefficients divide by this Cauchy-Schwarz gap. It is exactly zero when the target is a multiple of the sample mean. Every vector is such a multiple at $N = 1$.

Related

References

  • [58] T. Bodnar, O. Okhrin and N. Parolya. Optimal shrinkage estimator for high-dimensional mean vector. Journal of Multivariate Analysis 170, 63–79 (2019). Section 3, Theorem 3, Equations 6 and 7.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Equation 3.45.
source

References

[12]
D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
[52]
A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005).
[53]
Y. Feng and D. P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends in Signal Processing 9, 1–231 (2016).
[54]
P. Jorion. Bayes-Stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis 21, 279–292 (1986).
[55]
M. E. Bock. Minimax estimators of the mean of a multivariate normal distribution. The Annals of Statistics 3, 209–218 (1975).
[56]
E. L. Lehmann and G. Casella. Theory of Point Estimation. 2 Edition, Springer Texts in Statistics (Springer, 1998).
[57]
W. James and C. Stein. Estimation with quadratic loss. In: Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability, Volume 1 (University of California Press, 1961); pp. 361–379.
[58]
T. Bodnar, O. Okhrin and N. Parolya. Optimal shrinkage estimator for high-dimensional mean vector. Journal of Multivariate Analysis 170, 63–79 (2019).