Matrix Processing
PortfolioOptimisers.DefaultMatrixProcessing Type
struct DefaultMatrixProcessing{T1, T2, T3, T4} <: AbstractMatrixProcessingEstimator
pdm::T1
denoise::T2
detone::T3
alg::T4
endA 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), ornothingto skip.denoise: Denoising estimator (seeDenoise), ornothingto skip.detone: Detoning estimator (seeDetone), ornothingto skip.alg: Optional custom matrix processing algorithm, ornothingto 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> DefaultMatrixProcessing()
DefaultMatrixProcessing
pdm ┼ Posdef
│ alg ┴ UnionAll: NearestCorrelationMatrix.Newton
denoise ┼ nothing
detone ┼ nothing
alg ┴ nothing
julia> 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 ┴ nothingRelated
sourcePortfolioOptimisers.matrix_processing! Function
matrix_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 tosigmausing 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 matrixsigmais 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.0926441Related
sourcePortfolioOptimisers.matrix_processing Function
matrix_processing(mp::AbstractMatrixProcessingEstimator, sigma::AbstractMatrix,
X::AbstractMatrix, args...; kwargs...)
matrix_processing(::Nothing, args...; kwargs...)Out-of-place version of matrix_processing!.
Related
sourcePortfolioOptimisers.AbstractMatrixProcessingEstimator Type
abstract type AbstractMatrixProcessingEstimator <: AbstractEstimator endAbstract 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
sourcePortfolioOptimisers.AbstractMatrixProcessingAlgorithm Type
abstract type AbstractMatrixProcessingAlgorithm <: AbstractAlgorithm endAbstract 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
sourcePortfolioOptimisers.matrix_processing_algorithm! Method
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).
Returns
nothing.
Related
sourcePortfolioOptimisers.matrix_processing_algorithm Method
matrix_processing_algorithm(::Nothing, args...; kwargs...)Same as matrix_processing_algorithm!, but meant for returning a new matrix instead of modifying it in-place.
Related
source