Skip to content
6

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
julia
abstract type AbstractPosdefEstimator <: AbstractEstimator end

Abstract 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

source
PortfolioOptimisers.Posdef Type
julia
struct Posdef{T1, T2} <: AbstractPosdefEstimator
    alg::T1
    kwargs::T2
end

A 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

julia
Posdef(; alg::Any = NearestCorrelationMatrix.Newton, kwargs::NamedTuple = (;))

Keyword arguments correspond to the fields above.

Examples

julia
julia> Posdef()
Posdef
     alg ┼ UnionAll: NearestCorrelationMatrix.Newton
  kwargs ┴ @NamedTuple{}: NamedTuple()

Related

source
PortfolioOptimisers.posdef! Function
julia
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 in pdm.alg is used to project X to the nearest PD matrix. If X is already positive definite, it is left unchanged.

    • pdm::Nothing: No-op.

  • X: The matrix to be projected in-place.

Returns

  • nothing. The input matrix X is modified in-place.

Validation

  • If the matrix cannot be made positive definite, a warning is emitted.

Examples

julia
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)
true

Related

source
PortfolioOptimisers.posdef Function
julia
posdef(pdm::Posdef, X::MatNum)
posdef(::Nothing, args...)

Out-of-place version of posdef!.

Related

source