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::Union{Nothing, <:Posdef}
: Positive definite matrix estimator (seePosdef
), ornothing
to skip.denoise::Union{Nothing, <:Denoise}
: Denoising estimator (seeDenoise
), ornothing
to skip.detone::Union{Nothing, <:Detone}
: Detoning estimator (seeDetone
), ornothing
to skip.alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm}
: Optional custom matrix processing algorithm, ornothing
to skip.
Constructor
DefaultMatrixProcessing(; pdm = Posdef(), denoise = nothing, detone = nothing, alg = nothing)
Keyword arguments correspond to the fields above. The constructor infers types and sets defaults for robust matrix processing.
Related
PortfolioOptimisers.DefaultMatrixProcessing
— MethodDefaultMatrixProcessing(; pdm = Posdef(), denoise = nothing, detone = nothing, alg = nothing)
Construct a DefaultMatrixProcessing
object, configuring all steps for matrix processing in PortfolioOptimisers.jl.
Arguments
pdm::Union{Nothing, <:Posdef}
: Positive definite matrix estimator.denoise::Union{Nothing, <:Denoise}
: Denoising estimator.detone::Union{Nothing, <:Detone}
: Detoning estimator.alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm}
: Optional custom matrix processing algorithm.
ReturnsResult
DefaultMatrixProcessing
: A configured matrix processing estimator.
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::Union{Nothing, <:Denoise}
: Denoising estimator (seeDenoise
), ornothing
to skip.detone::Union{Nothing, <:Detone}
: Detoning estimator (seeDetone
), ornothing
to skip.alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm}
: Optional custom matrix processing algorithm, ornothing
to skip.
Constructor
NonPositiveDefiniteMatrixProcessing(; denoise = nothing, detone = nothing, alg = nothing)
Keyword arguments correspond to the fields above. The constructor infers types and sets defaults for robust matrix processing without positive definite enforcement.
Related
PortfolioOptimisers.NonPositiveDefiniteMatrixProcessing
— MethodNonPositiveDefiniteMatrixProcessing(; denoise = nothing, detone = nothing, alg = nothing)
Construct a NonPositiveDefiniteMatrixProcessing
object, configuring matrix processing steps without positive definite enforcement.
Arguments
denoise::Union{Nothing, <:Denoise} = nothing
: Denoising estimator.detone::Union{Nothing, <:Detone} = nothing
: Detoning estimator.alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm} = nothing
: Optional custom matrix processing algorithm.
ReturnsResult
NonPositiveDefiniteMatrixProcessing
: A configured matrix processing estimator.
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::DefaultMatrixProcessing, sigma::AbstractMatrix, X::AbstractMatrix, args...; kwargs...)
matrix_processing!(mp::NonPosdefMatrixProcessing, sigma::AbstractMatrix, X::AbstractMatrix, args...; kwargs...)
matrix_processing!(::Nothing, args...; kwargs...)
In-place processing of a covariance or correlation matrix.
- If
mp
isnothing
, this is a no-op and returnsnothing
. - If
mp
is aDefaultMatrixProcessing
object, the specified matrix processing steps are applied tosigma
in-place, using the provided data matrixX
. - If
mp
is aNonPositiveDefiniteMatrixProcessing
object, the specified matrix processing steps without enforcing positive definiteness are applied tosigma
in-place, using the provided data matrixX
.
The processing pipeline consists of:
- Positive definiteness enforcement via
posdef!
(ifmp.pdm
isDefaultMatrixProcessing
). - Denoising via
denoise!
(ifmp.denoise
is notnothing
). - Detoning via
detone!
(ifmp.detone
is notnothing
). - Optional custom matrix processing algorithm via
matrix_processing_algorithm!
(ifmp.alg
is notnothing
).
Arguments
mp::Union{Nothing, <:AbstractMatrixProcessingEstimator}
: Matrix processing estimator specifying the pipeline.sigma::AbstractMatrix
: Covariance or correlation matrix to be processed (modified in-place).X::AbstractMatrix
: 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.
ReturnsResult
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::DefaultMatrixProcessing, sigma::AbstractMatrix, X::AbstractMatrix, args...; kwargs...)
matrix_processing(mp::NonPosdefMatrixProcessing, sigma::AbstractMatrix, X::AbstractMatrix, args...; kwargs...)
matrix_processing(::Nothing, args...; kwargs...)
Same as matrix_processing!
, but returns a new matrix instead of modifying sigma
in-place.
- If
mp
isnothing
, this is a no-op and returnsnothing
.
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> sigma_ds = matrix_processing(DefaultMatrixProcessing(; denoise = Denoise()), sigma, X)
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> sigma_dt = matrix_processing(DefaultMatrixProcessing(; detone = Detone()), sigma, X)
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.AbstractMatrixProcessingEstimator
— TypeAbstractMatrixProcessingEstimator <: AbstractEstimator
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
— TypeAbstractMatrixProcessingAlgorithm <: AbstractAlgorithm
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!
— Functionmatrix_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).
ReturnsResult
nothing
.
Related
PortfolioOptimisers.matrix_processing_algorithm
— Functionmatrix_processing_algorithm(::Nothing, args...; kwargs...)
Same as matrix_processing_algorithm!
, but meant for returning a new matrix instead of modifying it in-place.
Related