Shrunk Expected Returns: private API

PortfolioOptimisers.target_mean — Function
target_mean(
    tgt::GrandMean,
    mu::ArrNum,
    sigma::MatNum,
    args...;
    kwargs...
) -> StepRangeLen

target_mean(
    tgt::VolatilityWeighted,
    mu::ArrNum,
    sigma::MatNum,
    isigma::Option{<:MatNum} = nothing;
    kwargs...
) -> StepRangeLen

target_mean(
    tgt::MeanSquaredError,
    mu::ArrNum,
    sigma::MatNum,
    args...;
    T::Real,
    kwargs...
) -> StepRangeLen

Compute the shrinkage target vector for expected returns estimation.

JamesStein, BayesStein and BodnarOkhrinParolya all call target_mean, so the library computes each target in one place.

Every element of the returned vector holds the same value, so the function returns a StepRangeLen and not a dense vector.

Algorithm

Julia selects the method from the type of tgt. The docstring of each target type states the closed form of its method. Every method computes one scalar val and returns the constant range range(val, val; length = length(mu)).

  1. If tgt is a GrandMean, take the unweighted mean of mu. This method does not read sigma, isigma or T.
  2. If tgt is a VolatilityWeighted, solve for isigma when the caller did not pass it. Flatten mu when it has one row. Then divide the sum of isigma * mu by the sum of isigma.
  3. If tgt is a MeanSquaredError, divide the trace of sigma by the keyword T. This method does not read the values of mu or isigma. It reads only the length of mu.

Each method accepts, through args... and kwargs..., the arguments that only the other methods read. One call therefore works for all three targets.

Arguments

  • tgt: The shrinkage target type.

    • tgt::GrandMean: Fills the vector with the mean of mu.
    • tgt::VolatilityWeighted: Fills the vector with the inverse-covariance-weighted mean of mu.
    • tgt::MeanSquaredError: Fills the vector with the trace of sigma divided by T.
  • mu: The array of the sample expected returns, a vector or a matrix with one row or one column.

  • sigma: Covariance matrix assets × assets.

  • isigma: The inverse covariance matrix. The VolatilityWeighted method takes it as a positional argument. If it is nothing, that method computes sigma \ LinearAlgebra.I. The other two methods accept it in args... and do not read it.

  • T: The effective number of observations of the sample mean, from effective_observation_count. The MeanSquaredError method needs it as a keyword. The other two methods accept it in kwargs... and do not read it.

  • kwargs...: More keyword arguments. The function does not read them.

Returns

  • b::StepRangeLen: The shrinkage target vector, of length length(mu).

Related

References

  • [52] A. Meucci. Risk and Asset Allocation (Springer Berlin Heidelberg, 2005). Section 4.4, Equations 4.136, 4.141 and 4.142.
  • [54] P. Jorion. Bayes-Stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis 21, 279–292 (1986). Section IV, Equation 14.
  • [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

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).
[54]
P. Jorion. Bayes-Stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis 21, 279–292 (1986).