Skip to content
13

Detone covariance

PortfolioOptimisers.DetoneCovariance Type
julia
struct DetoneCovariance{__T_ce, __T_dt, __T_pdm} <: AbstractCovarianceEstimator

A covariance estimator that applies a detoning algorithm and positive definite projection to the output of another covariance estimator. This type enables robust estimation of covariance matrices by first computing a base covariance, then applying detoning and positive definiteness corrections in sequence.

Fields

  • ce: Covariance estimator.

  • dt: Matrix detoning estimator.

  • pdm: Positive definite matrix estimator.

Constructors

julia
DetoneCovariance(;
    ce::StatsBase.CovarianceEstimator = Covariance(),
    dt::Detone = Detone(),
    pdm::Option{<:Posdef} = Posdef(),
) -> DetoneCovariance

Keywords correspond to the struct's fields.

Examples

julia
julia> DetoneCovariance()
DetoneCovariance
   ce ┼ Covariance
      │    me ┼ SimpleExpectedReturns
      │       │   w ┴ nothing
      │    ce ┼ GeneralCovariance
      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
      │       │    w ┴ nothing
      │   alg ┴ Full()
   dt ┼ Detone
      │   pdm ┼ Posdef
      │       │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
      │       │   kwargs ┴ @NamedTuple{}: NamedTuple()
      │     n ┴ Int64: 1
  pdm ┼ Posdef
      │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
      │   kwargs ┴ @NamedTuple{}: NamedTuple()

Related

source
PortfolioOptimisers.factory Method
julia
factory(ce::DetoneCovariance, w::ObsWeights) -> DetoneCovariance

Return a new DetoneCovariance estimator with observation weights w applied to the underlying covariance estimator.

Arguments

  • ce: Covariance estimator.

  • w: Observation weights vector observations × 1.

Returns

  • ce: New covariance estimator of the same type as the argument, with the new weights applied.

Examples

julia
julia> ce = DetoneCovariance();

julia> ce2 = factory(ce, StatsBase.Weights([0.2, 0.3, 0.5]));

julia> ce2.ce.me.w
3-element Weights{Float64, Float64, Vector{Float64}}:
 0.2
 0.3
 0.5

Related

source
Statistics.cov Method
julia
Statistics.cov(ce::DetoneCovariance, X::MatNum; dims = 1, kwargs...)

Compute the detoned and positive definite projected covariance matrix for the data matrix X using the specified DetoneCovariance estimator.

Arguments

  • ce: The DetoneCovariance estimator specifying the base covariance estimator, detoning algorithm, and positive definite projection.

  • X: The data matrix (observations × assets).

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the underlying covariance estimator.

Returns

  • sigma::MatNum: detoned covariance matrix.

Validation

  • dims in (1, 2).

Details

  • Computes the covariance matrix using the base estimator in ce.

  • Transposes X if dims == 2 to ensure variables are in columns.

  • Ensures the covariance matrix is mutable.

  • Applies positive definite projection using the method in ce.pdm.

  • Applies the detoning algorithm in ce.dt.

  • Returns the processed covariance matrix.

Related

source
Statistics.cor Method
julia
Statistics.cor(ce::DetoneCovariance, X::MatNum; dims = 1, kwargs...)

Compute the detoned and positive definite projected correlation matrix for the data matrix X using the specified DetoneCovariance estimator.

Arguments

  • ce: The DetoneCovariance estimator specifying the base covariance estimator, detoning algorithm, and positive definite projection.

  • X: The data matrix (observations × assets).

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to the underlying correlation estimator.

Returns

  • rho::MatNum: detoned correlation matrix.

Validation

  • dims in (1, 2).

Details

  • Computes the correlation matrix using the base estimator in ce.

  • Transposes X if dims == 2 to ensure variables are in columns.

  • Ensures the correlation matrix is mutable.

  • Applies positive definite projection using the method in ce.pdm.

  • Applies the detoning algorithm in ce.dt.

  • Returns the processed correlation matrix.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(
    ce::DetoneCovariance,
    i,
    args...
) -> Union{DetoneCovariance{var"#s179", Detone{__T_pdm, __T_n}, Nothing} where {var"#s179"<:CovarianceEstimator, __T_pdm, __T_n}, DetoneCovariance{var"#s179", Detone{__T_pdm, __T_n}, Posdef{__T_alg, __T_kwargs}} where {var"#s179"<:CovarianceEstimator, __T_pdm, __T_n, __T_alg, __T_kwargs}}

Gets the view of the covariance estimator for the i-th element(s).

Arguments

  • ce: Covariance estimator.

  • i: Index or indices to view.

Returns

  • ce: New covariance estimator of the same type as the argument, for the new view.

Related

source