PosdefMatrix
PortfolioOptimisers.Posdef Type
struct Posdef{T1} <: AbstractPosdefEstimator
alg::T1
endA concrete estimator type for projecting a matrix to the nearest positive definite (PD) matrix, typically used for covariance or correlation matrices.
Fields
alg: The algorithm used for the nearest correlation matrix projection.
Constructor
Posdef(; alg::Any = NearestCorrelationMatrix.Newton)Keyword arguments correspond to the fields above.
Examples
julia> using LinearAlgebra
julia> Posdef()
Posdef
alg ┴ UnionAll: NearestCorrelationMatrix.NewtonRelated
sourcePortfolioOptimisers.posdef! Function
posdef!(pdm::Posdef, X::AbstractMatrix)
posdef!(::Nothing, args...)In-place projection of a matrix to the nearest positive definite (PD) matrix using the specified estimator.
For covariance matrices, the function internally converts to a correlation matrix, applies the algorithm, and then rescales back to covariance.
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()
Posdef
alg ┴ UnionAll: NearestCorrelationMatrix.Newton
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
sourcePortfolioOptimisers.posdef Function
posdef(pdm::Posdef, X::AbstractMatrix)
posdef(::Nothing, args...)Out-of-place version of posdef!.
Related
sourcePortfolioOptimisers.AbstractPosdefEstimator Type
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