Matrix Processing

PortfolioOptimisers.DefaultMatrixProcessingType
struct 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 (see Posdef), or nothing to skip.
  • denoise::Union{Nothing, <:Denoise}: Denoising estimator (see Denoise), or nothing to skip.
  • detone::Union{Nothing, <:Detone}: Detoning estimator (see Detone), or nothing to skip.
  • alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm}: Optional custom matrix processing algorithm, or nothing 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

source
PortfolioOptimisers.DefaultMatrixProcessingMethod
DefaultMatrixProcessing(; 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

source
PortfolioOptimisers.NonPositiveDefiniteMatrixProcessingType
struct 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 (see Denoise), or nothing to skip.
  • detone::Union{Nothing, <:Detone}: Detoning estimator (see Detone), or nothing to skip.
  • alg::Union{Nothing, <:AbstractMatrixProcessingAlgorithm}: Optional custom matrix processing algorithm, or nothing 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

source
PortfolioOptimisers.NonPositiveDefiniteMatrixProcessingMethod
NonPositiveDefiniteMatrixProcessing(; 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

source
PortfolioOptimisers.matrix_processing!Function
matrix_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 is nothing, this is a no-op and returns nothing.
  • If mp is a DefaultMatrixProcessing object, the specified matrix processing steps are applied to sigma in-place, using the provided data matrix X.
  • If mp is a NonPositiveDefiniteMatrixProcessing object, the specified matrix processing steps without enforcing positive definiteness are applied to sigma in-place, using the provided data matrix X.

The processing pipeline consists of:

  1. Positive definiteness enforcement via posdef! (if mp.pdm is DefaultMatrixProcessing).
  2. Denoising via denoise! (if mp.denoise is not nothing).
  3. Detoning via detone! (if mp.detone is not nothing).
  4. Optional custom matrix processing algorithm via matrix_processing_algorithm! (if mp.alg is not nothing).

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 matrix sigma 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

source
PortfolioOptimisers.matrix_processingFunction
matrix_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 is nothing, this is a no-op and returns nothing.

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

source
PortfolioOptimisers.AbstractMatrixProcessingEstimatorType
AbstractMatrixProcessingEstimator <: 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

source
PortfolioOptimisers.AbstractMatrixProcessingAlgorithmType
AbstractMatrixProcessingAlgorithm <: 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

source
PortfolioOptimisers.matrix_processing_algorithm!Function
matrix_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

source