Positive definite matrix projection
All co-moment matrices are supposed to be positive definite. However, non-positive definite matrices can arise due to collinearity, having fewer observations than observables, and floating point inacuracies. Non-positive definite matrices have zero or negative eigenvalues.
Zero eigenvalues imply collinearity between assets, which means the system is underdetermined and therefore a linear or quadratic system involving the matrix does not have a unique solution.
Negative eigenvalues imply numerical stability issues, which usually arise from poorly conditioned systems, which for covariance and correlation matrices arise from high collinearity.
In order to obtain unique results and improve numerical stability, these non-positive definite matrices can be projected to the nearest positive definite matrix. This keeps the underlying relationships as intact as possible, while ensuring they have the appropriate numerical characteristics.
These types and functions let us do so.
PortfolioOptimisers.AbstractPosdefEstimator Type
abstract type AbstractPosdefEstimator <: AbstractEstimator endAbstract supertype for all positive definite matrix estimator types in PortfolioOptimisers.jl.
All concrete types that implement positive definite matrix projection or estimation (e.g., for covariance or correlation matrices) should subtype AbstractPosdefEstimator. This enables a consistent interface for positive definite matrix estimation routines throughout the package.
Related
sourcePortfolioOptimisers.Posdef Type
struct Posdef{T1, T2} <: AbstractPosdefEstimator
alg::T1
kwargs::T2
endA concrete estimator type for projecting a matrix to the nearest positive definite matrix, typically used for co-moment matrices.
Posdef encapsulates all parameters required for positive definite matrix projection in posdef! and posdef to perform the nearest positive definite projection according to the estimator.
Fields
alg: The algorithm used for the nearest correlation matrix projection.kwargs: A named tuple of keyword arguments to be passed to the algorithm.
Constructor
Posdef(; alg::Any = NearestCorrelationMatrix.Newton, kwargs::NamedTuple = (;))Keyword arguments correspond to the fields above.
Examples
julia> Posdef()
Posdef
alg ┼ UnionAll: NearestCorrelationMatrix.Newton
kwargs ┴ @NamedTuple{}: NamedTuple()Related
sourcePortfolioOptimisers.posdef! Function
posdef!(pdm::Posdef, X::MatNum)
posdef!(::Nothing, args...)In-place projection of a matrix to the nearest positive definite matrix using the specified estimator.
For matrices without unit diagonal, the function converts them into correlation matrices i.e. matrices with unit diagonal, applies the algorithm, and rescales them back.
Arguments
pdm: The estimator specifying the positive definite projection algorithm.pdm::Posdef: The algorithm specified inpdm.algis used to projectXto the nearest PD matrix. IfXis already positive definite, it is left unchanged.pdm::Nothing: No-op.
X: The matrix to be projected in-place.
Returns
nothing. The input matrixXis modified in-place.
Validation
- If the matrix cannot be made positive definite, a warning is emitted.
Examples
julia> using LinearAlgebra
julia> est = Posdef();
julia> X = [1.0 0.9; 0.9 1.0];
julia> X[1, 2] = 2.0; # Not PD
julia> posdef!(est, X)
julia> X
2×2 Matrix{Float64}:
1.0 1.0
1.0 1.0
julia> isposdef(X)
trueRelated
source