PosdefMatrix
PortfolioOptimisers.Posdef
— Typestruct Posdef{T1} <: AbstractPosdefEstimator
alg::T1
end
A 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 = NearestCorrelationMatrix.Newton)
Creates a new Posdef
with the specified algorithm.
Related
PortfolioOptimisers.Posdef
— MethodPosdef(; alg = NearestCorrelationMatrix.Newton)
Constructor for Posdef
. Defaults to the NearestCorrelationMatrix.Newton
algorithm.
Arguments
alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm}
: The algorithm used for the nearest correlation matrix projection.
Examples
julia> using LinearAlgebra
julia> est = Posdef()
Posdef
alg | UnionAll: NearestCorrelationMatrix.Newton
Related
PortfolioOptimisers.posdef!
— Functionposdef!(method::Posdef, X::AbstractMatrix)
posdef!(::Nothing, args...)
In-place projection of a matrix to the nearest positive definite (PD) matrix using the specified estimator.
- If
method
isnothing
, this is a no-op and returnsnothing
. - If
method
is aPosdef
, the algorithm specified inmethod.alg
is used to projectX
to the nearest PD matrix. IfX
is already positive definite, it is left unchanged.
For covariance matrices, the function internally converts to a correlation matrix, applies the projection, and then rescales back to covariance.
Arguments
method::Posdef
: The estimator specifying the projection algorithm.X::AbstractMatrix
: The matrix to be projected in-place.
ReturnsResult
nothing
. The input matrixX
is 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)
true
Related
PortfolioOptimisers.posdef
— Functionposdef(method::Posdef, X::AbstractMatrix)
posdef(::Nothing, args...)
Same as posdef!
, but returns a new matrix instead of modifying X
in-place.
- If
method
isnothing
, this is a no-op and returnsnothing
.
Examples
julia> using LinearAlgebra
julia> est = Posdef();
julia> X = [1.0 2.0; 0.9 1.0]; # Not PD
julia> X_pd = posdef(est, X);
julia> isposdef(X_pd)
true
julia> X_pd
2×2 Matrix{Float64}:
1.0 1.0
1.0 1.0
Related
PortfolioOptimisers.AbstractPosdefEstimator
— TypeAbstractPosdefEstimator <: AbstractEstimator
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