Matrix Processing
PortfolioOptimisers.DefaultMatrixProcessing
— Typestruct DefaultMatrixProcessing{T1, T2, T3, T4} <: AbstractMatrixProcessingEstimator
pdm::T1
denoise::T2
detone::T3
alg::T4
end
A flexible container type for configuring and applying matrix processing routines in PortfolioOptimisers.jl.
DefaultMatrixProcessing
encapsulates all steps required for processing covariance or correlation matrices, including positive definiteness enforcement, denoising, detoning, and optional custom matrix processing algorithms. It is the standard estimator type for matrix processing pipelines and supports a variety of estimator and algorithm types.
Fields
pdm
: Positive definite matrix estimator (seePosdef
), ornothing
to skip.denoise
: Denoising estimator (seeDenoise
), ornothing
to skip.detone
: Detoning estimator (seeDetone
), ornothing
to skip.alg
: Optional custom matrix processing algorithm, ornothing
to skip.
Constructor
DefaultMatrixProcessing(; pdm::Union{Nothing, <:Posdef} = Posdef(),
denoise::Union{Nothing, <:Denoise} = nothing,
detone::Union{Nothing, <:Detone} = nothing,
alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm} = nothing)
Keyword arguments correspond to the fields above.
Examples
julia> mp = DefaultMatrixProcessing()
DefaultMatrixProcessing
pdm | Posdef
| alg | UnionAll: NearestCorrelationMatrix.Newton
denoise | nothing
detone | nothing
alg | nothing
julia> mp = DefaultMatrixProcessing(; denoise = Denoise(), detone = Detone(; n = 2))
DefaultMatrixProcessing
pdm | Posdef
| alg | UnionAll: NearestCorrelationMatrix.Newton
denoise | Denoise
| alg | ShrunkDenoise
| | alpha | Float64: 0.0
| args | Tuple{}: ()
| kwargs | @NamedTuple{}: NamedTuple()
| kernel | typeof(AverageShiftedHistograms.Kernels.gaussian): AverageShiftedHistograms.Kernels.gaussian
| m | Int64: 10
| n | Int64: 1000
detone | Detone
| n | Int64: 2
alg | nothing
Related
PortfolioOptimisers.NonPositiveDefiniteMatrixProcessing
— Typestruct NonPositiveDefiniteMatrixProcessing{T1, T2, T3} <: AbstractMatrixProcessingEstimator
denoise::T1
detone::T2
alg::T3
end
A container type for matrix processing pipelines that do not enforce positive definiteness in PortfolioOptimisers.jl.
NonPositiveDefiniteMatrixProcessing
is intended for workflows where positive definiteness is not required or is handled externally. It supports denoising, detoning, and optional custom matrix processing algorithms, but skips positive definite projection.
Fields
denoise
: Denoising estimator (seeDenoise
), ornothing
to skip.detone
: Detoning estimator (seeDetone
), ornothing
to skip.alg
: Optional custom matrix processing algorithm, ornothing
to skip.
Constructor
NonPositiveDefiniteMatrixProcessing(; denoise::Union{Nothing, <:Denoise} = nothing,
detone::Union{Nothing, <:Detone} = nothing,
alg::Union{Nothing,
<:AbstractMatrixProcessingAlgorithm} = nothing)
Keyword arguments correspond to the fields above.
Examples
julia> mp = NonPositiveDefiniteMatrixProcessing()
NonPositiveDefiniteMatrixProcessing
denoise | nothing
detone | nothing
alg | nothing
julia> mp = NonPositiveDefiniteMatrixProcessing(; denoise = Denoise(), detone = Detone(; n = 2))
NonPositiveDefiniteMatrixProcessing
denoise | Denoise
| alg | ShrunkDenoise
| | alpha | Float64: 0.0
| args | Tuple{}: ()
| kwargs | @NamedTuple{}: NamedTuple()
| kernel | typeof(AverageShiftedHistograms.Kernels.gaussian): AverageShiftedHistograms.Kernels.gaussian
| m | Int64: 10
| n | Int64: 1000
detone | Detone
| n | Int64: 2
alg | nothing
Related
PortfolioOptimisers.matrix_processing!
— Functionmatrix_processing!(mp::AbstractMatrixProcessingEstimator, sigma::AbstractMatrix,
X::AbstractMatrix, args...; kwargs...)
matrix_processing!(::Nothing, args...; kwargs...)
In-place processing of a covariance or correlation matrix.
The processing pipeline consists of:
- Positive definiteness enforcement via
posdef!
. - Denoising via
denoise!
. - Detoning via
detone!
. - Optional custom matrix processing algorithm via
matrix_processing_algorithm!
.
Arguments
mp::AbstractMatrixProcessingEstimator
: Matrix processing estimator specifying the pipeline.mp::DefaultMatrixProcessing
: The specified matrix processing steps are applied tosigma
using the provided data matrixX
.mp::NonPositiveDefiniteMatrixProcessing
: The specified matrix processing steps without enforcing positive definiteness are applied tosigma
using the provided data matrixX
.mp::Nothing
: No-op.
sigma
: Covariance or correlation matrix to be processed (modified in-place).X
: Data matrix (observations × assets) used for denoising and detoning.args...
: Additional positional arguments passed to custom algorithms.kwargs...
: Additional keyword arguments passed to custom algorithms.
Returns
nothing
. The input matrixsigma
is modified in-place.
Examples
julia> using StableRNGs, Statistics
julia> rng = StableRNG(123456789);
julia> X = rand(rng, 10, 5);
julia> sigma = cov(X)
5×5 Matrix{Float64}:
0.132026 0.0022567 0.0198243 0.00359832 -0.00743829
0.0022567 0.0514194 -0.0131242 0.004123 0.0312379
0.0198243 -0.0131242 0.0843837 -0.0325342 -0.00609624
0.00359832 0.004123 -0.0325342 0.0424332 0.0152574
-0.00743829 0.0312379 -0.00609624 0.0152574 0.0926441
julia> matrix_processing!(DefaultMatrixProcessing(; denoise = Denoise()), sigma, X)
julia> sigma
5×5 Matrix{Float64}:
0.132026 0.0 0.0 0.0 0.0
0.0 0.0514194 0.0 0.0 0.0
0.0 0.0 0.0843837 0.0 0.0
0.0 0.0 0.0 0.0424332 0.0
0.0 0.0 0.0 0.0 0.0926441
julia> sigma = cov(X)
5×5 Matrix{Float64}:
0.132026 0.0022567 0.0198243 0.00359832 -0.00743829
0.0022567 0.0514194 -0.0131242 0.004123 0.0312379
0.0198243 -0.0131242 0.0843837 -0.0325342 -0.00609624
0.00359832 0.004123 -0.0325342 0.0424332 0.0152574
-0.00743829 0.0312379 -0.00609624 0.0152574 0.0926441
julia> matrix_processing!(DefaultMatrixProcessing(; detone = Detone()), sigma, X)
julia> sigma
5×5 Matrix{Float64}:
0.132026 0.0124802 0.0117303 0.0176194 0.0042142
0.0124802 0.0514194 0.0273105 -0.0290864 0.0088165
0.0117303 0.0273105 0.0843837 -0.00279296 0.0619156
0.0176194 -0.0290864 -0.00279296 0.0424332 -0.0242252
0.0042142 0.0088165 0.0619156 -0.0242252 0.0926441
Related
PortfolioOptimisers.matrix_processing
— Functionmatrix_processing(mp::AbstractMatrixProcessingEstimator, sigma::AbstractMatrix,
X::AbstractMatrix, args...; kwargs...)
matrix_processing(::Nothing, args...; kwargs...)
Out-of-place version of matrix_processing!
.
Related
PortfolioOptimisers.AbstractMatrixProcessingEstimator
— Typeabstract type AbstractMatrixProcessingEstimator <: AbstractEstimator end
Abstract supertype for all matrix processing estimator types in PortfolioOptimisers.jl.
All concrete types that implement matrix processing routines—such as covariance matrix cleaning, denoising, or detoning—should subtype AbstractMatrixProcessingEstimator
. This enables a consistent interface for matrix processing estimators throughout the package.
Related
PortfolioOptimisers.AbstractMatrixProcessingAlgorithm
— Typeabstract type AbstractMatrixProcessingAlgorithm <: AbstractAlgorithm end
Abstract supertype for all matrix processing algorithm types in PortfolioOptimisers.jl.
All concrete types that implement a specific matrix processing algorithm (e.g., custom cleaning or transformation routines) should subtype AbstractMatrixProcessingAlgorithm
. This enables flexible extension and dispatch of matrix processing routines.
Related
PortfolioOptimisers.matrix_processing_algorithm!
— Methodmatrix_processing_algorithm!(::Nothing, args...; kwargs...)
No-op fallback for matrix processing algorithm routines.
These methods are called internally when no matrix processing algorithm is specified (i.e., when the algorithm argument is nothing
). They perform no operation and return nothing
, ensuring that the matrix processing pipeline can safely skip optional algorithmic steps.
Arguments
::Nothing
: Indicates that no algorithm is provided.args...
: Additional positional arguments (ignored).kwargs...
: Additional keyword arguments (ignored).
Returns
nothing
.
Related
PortfolioOptimisers.matrix_processing_algorithm
— Methodmatrix_processing_algorithm(::Nothing, args...; kwargs...)
Same as matrix_processing_algorithm!
, but meant for returning a new matrix instead of modifying it in-place.
Related