Orthogonal Uncertainty Sets: private API

PortfolioOptimisers.orthogonal_factor_span — Function
orthogonal_factor_span(
    ue::OrthogonalUncertaintySet,
    pr::AbstractPriorResult
) -> Tuple{Any, Any, Any}

Weighted factor span of the prior's loadings block, the geometry both sets are built from.

Algorithm

  1. Refuse when pr.rr is nothing. The set reads the loadings off the prior result, and a prior that fitted no factor model carries none.
  2. Read B, the effective loadings rr.L. The field reads back as rr.M when no Factor Family was re-based, and a re-based model is already reduced to a full-rank basis.
  3. Count nnf, the rows of B that hold an entry that is not finite, and refuse when it is not zero. A singular value decomposition of such a row gives a LAPACK error, not a span. The NaN rows that a point-in-time Asset Panel writes outside the Investable Mask never reach this step, because the optimiser's builders pass the prior reduced to that mask, and the standalone verbs reduce to it first through investable_ucs_reduction. A non-finite row here therefore belongs to an asset that the prior calls investable, whose mu and variance are finite and whose loadings are not, and the message says so.
  4. Read w, the cross-sectional weights, through orthogonality_weights, and take w_sqrt, their element-wise square root, or keep nothing.
  5. Scale the rows of B by w_sqrt, giving Bw.
  6. Take F, the thin LinearAlgebra.svd of Bw, with the singular values s.
  7. Count r, the singular values above maximum(size(Bw)) * eps * s[1]. The tolerance reads the larger dimension, so it is wider than the default of LinearAlgebra.rank, which reads the smaller one.
  8. Return rr, w_sqrt and the first r left singular vectors of F.

Step 7 counts the rank after the re-basis that step 2 reads, because the selected universe can still leave the exposures numerically dependent, and a dependent direction that survives widens the span that the penalty spares.

Arguments

  • ue: Orthogonal uncertainty set estimator.
  • pr: Prior result the optimisation is solving on.

Validation

  • !isnothing(pr.rr), else an IsNothingError naming the field and the estimator that returned no block.
  • all(isfinite, rr.L), else an IsNonFiniteError counting the assets whose loadings are not finite. Every such asset is inside the Investable Mask of pr, because the verbs that call this fit reduce to the mask first.

Returns

  • rr::AbstractLoadingsRegressionResult: The loadings block the span came from.
  • w_sqrt::Option{<:VecNum}: Element-wise square root of the metric, or nothing on a nothing metric.
  • Q::MatNum: Orthonormal basis of the weighted factor span, $N \times r_{\mathbf{B}}$.

Related

source
PortfolioOptimisers.orthogonal_mu_set — Function
orthogonal_mu_set(
    ue::OrthogonalUncertaintySet,
    pr::AbstractPriorResult,
    rr::AbstractLoadingsRegressionResult,
    w_sqrt::Union{Nothing, AbstractVector{<:Union{Number, AbstractJuMPScalar}}},
    Q::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}}
) -> Union{NormBallUncertaintySet{var"#s185", <:AbstractMatrix{var"#s166"}, Int64, MuUncertaintySetClass, Nothing} where {var"#s185"<:Number, var"#s166"<:Union{Number, AbstractJuMPScalar}}, NormBallUncertaintySet{var"#s185", var"#s1851", Int64, MuUncertaintySetClass, <:AbstractArray{var"#s166", N}} where {var"#s185"<:Number, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1851"<:AbstractMatrix{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}, N}}

Builds the mean NormBallUncertaintySet on the Orthogonal Subspace, from a span already taken.

Algorithm

  1. Form P, the orthogonal projector I - Q * Q'.
  2. Form A, the rows of P divided by w_sqrt, or P itself when w_sqrt is nothing. A is the projector read back in the asset coordinates.
  3. Take E, the symmetric eigendecomposition of A' * A.
  4. Select keep, the indices of the trailing N - size(Q, 2) eigenvectors of E. The count is exact: Q is orthonormal, so P has rank N - size(Q, 2), the metric scaling is an invertible diagonal, and LinearAlgebra.eigen on a Symmetric orders the eigenvalues from small to large. An eigenvalue tolerance can sit so close to the eigenvalue it must cut that the cut changes with the reduction order of the machine and states a subspace one dimension too wide. Step 7 of orthogonal_factor_span still reads a tolerance, because the rank of the loadings is a property of the data and not of a projector.
  5. Orthonormalise A times the selected eigenvectors with a reduced LinearAlgebra.qr, giving G, and read r, the dimension of the Orthogonal Subspace, as its column count. An empty keep gives a G with no column.
  6. When r is 0, return the set with a radius of zero, a map of one zero column, and pr.mu as its centre. The zero radius leaves the nominal mean.
  7. Take lambda, the scaling, through orthogonal_scaling.
  8. Form L, the product of G and the square root of lambda that matrix_square_root takes under ue.mtx_sqrt. The set of order 2 reads only L * L', which is G * lambda * G' for every algorithm. An indefinite lambda raises a LinearAlgebra.PosDefException, because a loadings block that a caller builds by hand can give one.
  9. Size the radius with k_norm_ball at r degrees of freedom, and return the set of order 2 with pr.mu as its centre. A set fitted on one prior and passed to another optimisation therefore carries the centre that its geometry was calibrated on.

Arguments

  • ue: Orthogonal uncertainty set estimator.
  • pr: Prior result the span came from.
  • rr: Loadings block the span came from.
  • w_sqrt: Element-wise square root of the metric, or nothing.
  • Q: Orthonormal basis of the weighted factor span.

Returns

  • ucs::NormBallUncertaintySet: Mean set on the Orthogonal Subspace, of order 2.

Related

source
PortfolioOptimisers.orthogonal_sigma_set — Function
orthogonal_sigma_set(
    ue::OrthogonalUncertaintySet,
    pr::AbstractPriorResult,
    rr::AbstractLoadingsRegressionResult,
    w_sqrt::Union{Nothing, AbstractVector{<:Union{Number, AbstractJuMPScalar}}},
    Q::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}}
) -> Union{CompactCovarianceUncertaintySet{var"#s185", var"#s1851", var"#s1852", <:AbstractMatrix{var"#s166"}, Nothing} where {var"#s185"<:Number, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1851"<:AbstractVector{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1852"<:AbstractMatrix{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}}, CompactCovarianceUncertaintySet{var"#s185", var"#s1851", var"#s1852", var"#s1853", <:AbstractMatrix{var"#s166"}} where {var"#s185"<:Number, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1851"<:AbstractVector{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1852"<:AbstractMatrix{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1853"<:AbstractMatrix{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}}}
orthogonal_sigma_set(
    ue::OrthogonalUncertaintySet,
    pr::AbstractPriorResult,
    rr::AbstractLoadingsRegressionResult,
    w_sqrt::Union{Nothing, AbstractVector{<:Union{Number, AbstractJuMPScalar}}},
    Q::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
    rd
) -> Union{CompactCovarianceUncertaintySet{var"#s185", var"#s1851", var"#s1852", <:AbstractMatrix{var"#s166"}, Nothing} where {var"#s185"<:Number, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1851"<:AbstractVector{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1852"<:AbstractMatrix{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}}, CompactCovarianceUncertaintySet{var"#s185", var"#s1851", var"#s1852", var"#s1853", <:AbstractMatrix{var"#s166"}} where {var"#s185"<:Number, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1851"<:AbstractVector{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1852"<:AbstractMatrix{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}, var"#s1853"<:AbstractMatrix{var"#s166"}, var"#s166"<:Union{Number, AbstractJuMPScalar}}}

Builds the covariance CompactCovarianceUncertaintySet on the Orthogonal Subspace, from a span already taken.

Algorithm

  1. Form C, the diagonal metric square root, as the element-wise inverse of w_sqrt, or as a vector of ones when w_sqrt is nothing.
  2. Settle kappa, the radius, with k_compact. A stated number passes through unchanged. A rule of AbstractCompactRadiusAlgorithm receives the confidence level, the metric, the prior result, the loadings block, C, Q and rd.
  3. Return the set with Q as the basis it spares and pr.sigma as the nominal covariance. A span of rank zero gives a basis with no column, which the type admits, and the penalty then reaches every direction.

The set penalises the complement of the span, the same subspace that the mean set lives in, so one decomposition serves both axes and the estimator computes it once.

Arguments

  • ue: Orthogonal uncertainty set estimator.
  • pr: Prior result the span came from.
  • rr: Loadings block the span came from.
  • w_sqrt: Element-wise square root of the metric, or nothing.
  • Q: Orthonormal basis of the weighted factor span.
  • rd: Returns data the set was fitted beside, or nothing. Only a VarianceFraction holding an optimiser reads it.

Returns

  • ucs::CompactCovarianceUncertaintySet: Covariance set that spares the weighted factor span.

Related

source