Normal Uncertainty Sets
PortfolioOptimisers.NormalUncertaintySet Type
struct NormalUncertaintySet{__T_pe, __T_alg, __T_n_sim, __T_q, __T_rng, __T_seed, __T_ens, __T_kwargs} <: AbstractUncertaintySetEstimatorEstimator 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
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 = (;),
) -> NormalUncertaintySetKeywords correspond to the struct's fields.
Validation
n_sim > 0.0 < q < 1.
Examples
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
PortfolioOptimisers.ucs Function
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
Mean bounds use the normal complementary quantile
Where:
, : Element-wise lower/upper covariance bounds. , : Lower and upper quantile functions at level . : -element of the -th simulated Wishart covariance draw. , : Lower and upper bounds for expected returns. : Normal complementary quantile. : Estimated covariance matrix. : Number of observations. : 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
sourcePortfolioOptimisers.ucs Function
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:
The scaling
Where:
: Asymptotic covariance of the mean estimator. : Asymptotic covariance of the covariance estimator (vectorised). : Estimated covariance matrix. : Number of observations. : Identity matrix. : Commutation matrix. : Kronecker product. : Ellipsoidal uncertainty set for expected returns. : Ellipsoidal uncertainty set for covariance. , : 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
sourcePortfolioOptimisers.ucs Function
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-
The scaling
Where:
: Asymptotic covariance of the mean estimator. : Asymptotic covariance of the covariance estimator (vectorised). : Estimated covariance matrix. : Number of observations. : Identity matrix. : Commutation matrix. : Kronecker product. , : Chi-squared scaling parameters for mean and covariance ellipsoids. : -quantile of the chi-squared distribution with degrees of freedom. : Number of assets. : 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
PortfolioOptimisers.ucs Function
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
sourcePortfolioOptimisers.mu_ucs Function
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
Where:
, : Lower and upper bounds for expected returns. : Normal complementary quantile. : Estimated covariance matrix. : Number of observations. : 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
sourcePortfolioOptimisers.mu_ucs Function
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
sourcePortfolioOptimisers.mu_ucs Function
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
PortfolioOptimisers.mu_ucs Function
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
PortfolioOptimisers.sigma_ucs Function
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
Where:
, : Element-wise lower/upper covariance bounds. , : Lower and upper quantile functions at level . : -element of the -th Wishart draw. : Number of observations. : 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
sourcePortfolioOptimisers.sigma_ucs Function
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
sourcePortfolioOptimisers.sigma_ucs Function
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
PortfolioOptimisers.sigma_ucs Function
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
sourcePortfolioOptimisers.commutation_matrix Function
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)wherem, 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> 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.0PortfolioOptimisers.choose_scaling_parameter Method
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
ue:NormalUncertaintySetestimator.pr: Prior result.
Returns
- Scaling parameter value.
Related
source