Skip to content
13

Normal Uncertainty Sets

PortfolioOptimisers.NormalUncertaintySet Type
julia
struct NormalUncertaintySet{__T_pe, __T_alg, __T_n_sim, __T_q, __T_rng, __T_seed, __T_ens, __T_kwargs} <: AbstractUncertaintySetEstimator

Estimator for box or ellipsoidal uncertainty sets under the assumption of normally distributed returns in portfolio optimisation.

Fields

  • pe: Prior estimator.

  • alg: Uncertainty set algorithm.

  • n_sim: Number of simulation samples.

  • q: Quantile parameter for uncertainty set computation.

  • rng: Random number generator.

  • seed: Seed for the random number generator.

  • ens: Effective sample size.

  • kwargs: Additional keyword arguments.

Constructors

julia
NormalUncertaintySet(;
    pe::AbstractLowOrderPriorEstimator = EmpiricalPrior(),
    alg::AbstractUncertaintySetAlgorithm = BoxUncertaintySetAlgorithm(),
    n_sim::Integer = 3_000,
    q::Number = 0.05,
    rng::Random.AbstractRNG = Random.default_rng(),
    seed::Option{<:Integer} = nothing,
    ens::Option{<:Number} = nothing,
    kwargs::NamedTuple = (;),
) -> NormalUncertaintySet

Keywords correspond to the struct's fields.

Validation

  • n_sim > 0.

  • 0 < q < 1.

Examples

julia
julia> NormalUncertaintySet()
NormalUncertaintySet
      pe ┼ EmpiricalPrior
         │        ce ┼ PortfolioOptimisersCovariance
         │           │   ce ┼ Covariance
         │           │      │    me ┼ SimpleExpectedReturns
         │           │      │       │   w ┴ nothing
         │           │      │    ce ┼ GeneralCovariance
         │           │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
         │           │      │       │    w ┴ nothing
         │           │      │   alg ┴ Full()
         │           │   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)
         │        me ┼ SimpleExpectedReturns
         │           │   w ┴ nothing
         │   horizon ┴ nothing
     alg ┼ BoxUncertaintySetAlgorithm()
   n_sim ┼ Int64: 3000
       q ┼ Float64: 0.05
     rng ┼ Random.TaskLocalRNG: Random.TaskLocalRNG()
    seed ┼ nothing
     ens ┼ nothing
  kwargs ┴ @NamedTuple{}: NamedTuple()

Related

source
PortfolioOptimisers.ucs Function
julia
ucs(ue::NormalUncertaintySet{<:Any, <:BoxUncertaintySetAlgorithm, <:Any, <:Any, <:Any},
    X::MatNum,
    F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs box uncertainty sets for mean and covariance statistics under the assumption of normally distributed returns.

Mathematical definition

Simulates M covariance matrices Σ^(m)Wishart(T,Σ^/T) and computes element-wise quantile bounds:

(Σlb)ij=Qq/2(Σ^ij(m)),(Σub)ij=Q1q/2(Σ^ij(m)).

Mean bounds use the normal complementary quantile zq/2=Φ1(1q/2):

μlb=0,μub,i=2zq/2(Σ^/T)ii.

Where:

  • (Σlb)ij, (Σub)ij: Element-wise lower/upper covariance bounds.

  • Qq/2, Q1q/2: Lower and upper quantile functions at level q/2.

  • Σ^ij(m): (i,j)-element of the m-th simulated Wishart covariance draw.

  • μlb, μub,i: Lower and upper bounds for expected returns.

  • zq/2=Φ1(1q/2): Normal complementary quantile.

  • Σ^: Estimated covariance matrix.

  • T: Number of observations.

  • q: Significance level.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::BoxUncertaintySet: Expected returns uncertainty set.

  • sigma_ucs::BoxUncertaintySet: Covariance uncertainty sets.

Details

  • Computes prior statistics using the provided prior estimator.

  • Simulates covariance matrices using the Wishart distribution.

  • Computes lower and upper bounds for covariance using quantiles of simulated values.

  • Computes upper bound for mean using the normal quantile and simulated covariance.

  • Returns both sets as a tuple.

Related

source
PortfolioOptimisers.ucs Function
julia
ucs(ue::NormalUncertaintySet{<:Any,
                             <:EllipsoidalUncertaintySetAlgorithm{<:NormalKUncertaintyAlgorithm, <:Any},
                             <:Any, <:Any, <:Any},
    X::MatNum,
    F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs ellipsoidal uncertainty sets for expected returns and covariance statistics under the assumption of normally distributed returns.

Mathematical definition

Ellipsoidal sets centred at the prior estimates with asymptotic covariances:

Σμ=Σ^/T,ΣΣ=T(I+K)(ΣμΣμ).

The scaling k is fitted empirically from simulated samples μ^(m)N(μ^,Σ^) and Σ^(m)Wishart(T,Σμ):

Eμ={μ:(μμ^)Σμ1(μμ^)kμ2}.EΣ={Σ:ΣΣ1/2vec(ΣΣ^)2kΣ}.

Where:

  • Σμ: Asymptotic covariance of the mean estimator.

  • ΣΣ: Asymptotic covariance of the covariance estimator (vectorised).

  • Σ^: Estimated covariance matrix.

  • T: Number of observations.

  • I: Identity matrix.

  • K: Commutation matrix.

  • : Kronecker product.

  • Eμ: Ellipsoidal uncertainty set for expected returns.

  • EΣ: Ellipsoidal uncertainty set for covariance.

  • kμ, kΣ: Empirically fitted scaling parameters.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::EllipsoidalUncertaintySet: Expected returns uncertainty set.

  • sigma_ucs::EllipsoidalUncertaintySet: Covariance uncertainty sets.

Details

  • Computes prior statistics using the provided prior estimator.

  • Simulates mean and covariance using multivariate normal and Wishart distributions.

  • Constructs commutation matrix for covariance vectorization.

  • Computes scaling parameters for mean and covariance using the specified ellipsoidal algorithm.

  • Returns both sets as a tuple.

Related

source
PortfolioOptimisers.ucs Function
julia
ucs(ue::NormalUncertaintySet{<:Any,
                             <:EllipsoidalUncertaintySetAlgorithm{<:ChiSqKUncertaintyAlgorithm, <:Any},
                             <:Any, <:Any, <:Any},
    X::MatNum,
    F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs ellipsoidal uncertainty sets for expected returns and covariance statistics using the chi-squared scaling algorithm under the assumption of normally distributed returns.

Mathematical definition

Asymptotic covariances are the same as the normal-k variant:

Σμ=Σ^/T,ΣΣ=T(I+K)(ΣμΣμ).

The scaling k is the chi-squared quantile:

kμ=χN,1q2,kΣ=χN2,1q2.

Where:

  • Σμ: Asymptotic covariance of the mean estimator.

  • ΣΣ: Asymptotic covariance of the covariance estimator (vectorised).

  • Σ^: Estimated covariance matrix.

  • T: Number of observations.

  • I: Identity matrix.

  • K: Commutation matrix.

  • : Kronecker product.

  • kμ, kΣ: Chi-squared scaling parameters for mean and covariance ellipsoids.

  • χN,1q2: (1q)-quantile of the chi-squared distribution with N degrees of freedom.

  • N: Number of assets.

  • q: Significance level.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::EllipsoidalUncertaintySet: Expected returns uncertainty set.

  • sigma_ucs::EllipsoidalUncertaintySet: Covariance uncertainty sets.

Details

  • Computes prior statistics using the provided prior estimator.

  • Constructs commutation matrix for covariance vectorization.

  • Computes scaling parameters for mean and covariance using the chi-squared scaling algorithm.

  • Applies diagonal processing if specified in the algorithm.

  • Returns both sets as a tuple.

Related

source
PortfolioOptimisers.ucs Function
julia
ucs(ue::NormalUncertaintySet{<:Any, <:EllipsoidalUncertaintySetAlgorithm{<:Any, <:Any},
                             <:Any, <:Any, <:Any}, X::MatNum,
    F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs ellipsoidal uncertainty sets for expected returns and covariance statistics under the assumption of normally distributed returns, using a generic ellipsoidal algorithm.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::EllipsoidalUncertaintySet: Expected returns uncertainty set.

  • sigma_ucs::EllipsoidalUncertaintySet: Covariance uncertainty sets.

Details

  • Computes prior statistics using the provided prior estimator.

  • Constructs commutation matrix for covariance vectorization.

  • Computes scaling parameters for mean and covariance using the provided ellipsoidal algorithm.

  • Applies diagonal processing if specified in the algorithm.

  • Returns both sets as a tuple.

Related

source
PortfolioOptimisers.mu_ucs Function
julia
mu_ucs(ue::NormalUncertaintySet{<:Any, <:BoxUncertaintySetAlgorithm, <:Any, <:Any, <:Any},
       X::MatNum,
       F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs a box uncertainty set for expected returns under the assumption of normally distributed returns.

Mathematical definition

μlb=0,μub,i=2Φ1(1q2)(Σ^/T)ii.

Where:

  • μlb, μub,i: Lower and upper bounds for expected returns.

  • Φ1(1q/2): Normal complementary quantile.

  • Σ^: Estimated covariance matrix.

  • T: Number of observations.

  • q: Significance level.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::BoxUncertaintySet: Expected returns uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Computes the upper bound for mean using the normal quantile and simulated covariance.

  • Sets the lower bound for mean to zero.

  • Ignores additional arguments and keyword arguments except those passed to the prior estimator.

Related

source
PortfolioOptimisers.mu_ucs Function
julia
mu_ucs(ue::NormalUncertaintySet{<:Any,
                                <:EllipsoidalUncertaintySetAlgorithm{<:NormalKUncertaintyAlgorithm, <:Any},
                                <:Any, <:Any, <:Any},
       X::MatNum,
       F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs an ellipsoidal uncertainty set for expected returns under the assumption of normally distributed returns, using a normal scaling algorithm.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::EllipsoidalUncertaintySet: Expected returns uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Simulates mean vectors using the multivariate normal distribution.

  • Applies diagonal processing to the covariance if specified in the algorithm.

  • Computes the scaling parameter for the ellipsoidal using the normal scaling algorithm.

  • Returns an ellipsoidal uncertainty set for the mean.

Related

source
PortfolioOptimisers.mu_ucs Function
julia
mu_ucs(ue::NormalUncertaintySet{<:Any,
                                <:EllipsoidalUncertaintySetAlgorithm{<:ChiSqKUncertaintyAlgorithm, <:Any},
                                <:Any, <:Any, <:Any},
       X::MatNum,
       F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs an ellipsoidal uncertainty set for expected returns under the assumption of normally distributed returns, using a chi-squared scaling algorithm.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::EllipsoidalUncertaintySet: Expected returns uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Processes the covariance matrix for positive definiteness.

  • Applies diagonal processing to the covariance if specified in the algorithm.

  • Computes the scaling parameter for the ellipsoidal using the chi-squared scaling algorithm.

  • Returns an ellipsoidal uncertainty set for the mean.

Related

source
PortfolioOptimisers.mu_ucs Function
julia
mu_ucs(ue::NormalUncertaintySet{<:Any,
                                <:EllipsoidalUncertaintySetAlgorithm{<:ChiSqKUncertaintyAlgorithm, <:Any},
                                <:Any, <:Any, <:Any},
       X::MatNum,
       F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs an ellipsoidal uncertainty set for expected returns under the assumption of normally distributed returns, using a chi-squared scaling algorithm.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • mu_ucs::EllipsoidalUncertaintySet: Expected returns uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Processes the covariance matrix for positive definiteness.

  • Applies diagonal processing to the covariance if specified in the algorithm.

  • Computes the scaling parameter for the ellipsoidal using the chi-squared scaling algorithm.

  • Returns an ellipsoidal uncertainty set for the mean.

Related

source
PortfolioOptimisers.sigma_ucs Function
julia
sigma_ucs(ue::NormalUncertaintySet{<:Any, <:BoxUncertaintySetAlgorithm, <:Any, <:Any, <:Any},
          X::MatNum,
          F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs a box uncertainty set for covariance under the assumption of normally distributed returns.

Mathematical definition

Simulates M matrices Σ^(m)Wishart(T,Σ^/T) and takes element-wise quantiles:

(Σlb)ij=Qq/2(Σ^ij(m)),(Σub)ij=Q1q/2(Σ^ij(m)).

Where:

  • (Σlb)ij, (Σub)ij: Element-wise lower/upper covariance bounds.

  • Qq/2, Q1q/2: Lower and upper quantile functions at level q/2.

  • Σ^ij(m): (i,j)-element of the m-th Wishart draw.

  • T: Number of observations.

  • q: Significance level.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • sigma_ucs::BoxUncertaintySet: Covariance uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Simulates covariance matrices using the Wishart distribution.

  • Computes lower and upper bounds for covariance using quantiles of simulated values.

  • Ensures positive definiteness of the bounds.

  • Ignores additional arguments and keyword arguments except those passed to the prior estimator.

Related

source
PortfolioOptimisers.sigma_ucs Function
julia
sigma_ucs(ue::NormalUncertaintySet{<:Any,
                                   <:EllipsoidalUncertaintySetAlgorithm{<:NormalKUncertaintyAlgorithm, <:Any},
                                   <:Any, <:Any, <:Any},
          X::MatNum,
          F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs an ellipsoidal uncertainty set for covariance under the assumption of normally distributed returns, using a normal scaling algorithm.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • sigma_ucs::EllipsoidalUncertaintySet: Covariance uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Simulates covariance matrices using the Wishart distribution.

  • Constructs commutation matrix for covariance vectorization.

  • Computes the scaling parameter for the ellipsoidal using the normal scaling algorithm.

  • Applies diagonal processing to the covariance if specified in the algorithm.

  • Returns an ellipsoidal uncertainty set for covariance.

Related

source
PortfolioOptimisers.sigma_ucs Function
julia
sigma_ucs(ue::NormalUncertaintySet{<:Any,
                                   <:EllipsoidalUncertaintySetAlgorithm{<:ChiSqKUncertaintyAlgorithm, <:Any},
                                   <:Any, <:Any, <:Any},
          X::MatNum,
          F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs an ellipsoidal uncertainty set for covariance under the assumption of normally distributed returns, using a chi-squared scaling algorithm.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • sigma_ucs::EllipsoidalUncertaintySet: Covariance uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Processes the covariance matrix for positive definiteness.

  • Constructs commutation matrix for covariance vectorization.

  • Computes the scaling parameter for the ellipsoidal using the chi-squared scaling algorithm.

  • Applies diagonal processing to the covariance if specified in the algorithm.

  • Returns an ellipsoidal uncertainty set for covariance.

Related

source
PortfolioOptimisers.sigma_ucs Function
julia
sigma_ucs(ue::NormalUncertaintySet{<:Any,
                                   <:EllipsoidalUncertaintySetAlgorithm{<:Any, <:Any},
                                   <:Any, <:Any, <:Any}, X::MatNum,
          F::Option{<:MatNum} = nothing; dims::Int = 1, kwargs...)

Constructs an ellipsoidal uncertainty set for covariance under the assumption of normally distributed returns, using a generic ellipsoidal algorithm.

Arguments

  • ue: Normal uncertainty set estimator.

  • X: Data matrix.

  • F: Optional factor matrix. Used by the prior estimator.

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the prior estimator.

Returns

  • sigma_ucs::EllipsoidalUncertaintySet: Covariance uncertainty set.

Details

  • Computes prior statistics using the provided prior estimator.

  • Processes the covariance matrix for positive definiteness.

  • Constructs commutation matrix for covariance vectorization.

  • Computes the scaling parameter for the ellipsoidal using the provided ellipsoidal algorithm.

  • Applies diagonal processing to the covariance if specified in the algorithm.

  • Returns an ellipsoidal uncertainty set for covariance.

Related

source
PortfolioOptimisers.commutation_matrix Function
julia
commutation_matrix(X::MatNum)

Constructs the commutation matrix for a given matrix.

Arguments

  • X: Input matrix. Used to determine the dimensions of the commutation matrix.

Returns

  • cX::SparseArrays.SparseMatrixCSC{<:Number, <:Integer}: Returns a sparse commutation matrix of size (m*n, m*n) where m, n = size(X).

Details

  • The commutation matrix is used to vectorize and permute matrix elements.

  • It is constructed by reshaping and transposing the indices of the input matrix.

  • The output is a sparse matrix for efficiency.

Examples

julia
julia> PortfolioOptimisers.commutation_matrix(rand(2, 2))
4×4 SparseArrays.SparseMatrixCSC{Float64, Int64} with 4 stored entries:
 1.0
   1.0
   1.0
   1.0

julia> PortfolioOptimisers.commutation_matrix(rand(2, 3))
6×6 SparseArrays.SparseMatrixCSC{Float64, Int64} with 6 stored entries:
 1.0
   1.0
   1.0
   1.0
   1.0
   1.0

julia> PortfolioOptimisers.commutation_matrix(rand(3, 2))
6×6 SparseArrays.SparseMatrixCSC{Float64, Int64} with 6 stored entries:
 1.0
   1.0
   1.0
   1.0
   1.0
   1.0
source
PortfolioOptimisers.choose_scaling_parameter Method
julia
choose_scaling_parameter(ue, pr)

Select the scaling parameter for a normal uncertainty set from the prior result.

Internal helper that extracts the appropriate scaling parameter from ue given the prior result pr. Dispatches on the uncertainty set and prior types.

Arguments

Returns

  • Scaling parameter value.

Related

source