Covariance
PortfolioOptimisers.GeneralWeightedCovariance
— TypeGeneralWeightedCovariance{T1, T2} <: AbstractCovarianceEstimator
A flexible covariance estimator for PortfolioOptimisers.jl supporting arbitrary covariance estimators and optional observation weights.
GeneralWeightedCovariance
allows users to specify both the covariance estimation method and optional observation weights. This enables robust and extensible covariance estimation workflows.
Fields
ce::StatsBase.CovarianceEstimator
: Covariance estimator.w::Union{Nothing, <:AbstractWeights}
: Optional weights for each observation. Ifnothing
, the estimator is unweighted.
Constructor
GeneralWeightedCovariance(; ce::StatsBase.CovarianceEstimator = SimpleCovariance(; corrected = true),
w::Union{Nothing, <:AbstractWeights} = nothing)
Construct a GeneralWeightedCovariance
estimator with the specified covariance estimator and optional weights.
Related
PortfolioOptimisers.GeneralWeightedCovariance
— MethodGeneralWeightedCovariance(; ce::StatsBase.CovarianceEstimator = StatsBase.SimpleCovariance(; corrected = true),
w::Union{Nothing, <:AbstractWeights} = nothing)
Construct a GeneralWeightedCovariance
estimator for flexible covariance estimation with optional observation weights.
This constructor creates a GeneralWeightedCovariance
object using the specified covariance estimator and optional weights. If no weights are provided, the estimator defaults to unweighted covariance estimation. If weights are provided, they must not be empty.
Arguments
ce::StatsBase.CovarianceEstimator
: Covariance estimator to use.w::Union{Nothing, <:AbstractWeights}
: Optional observation weights. Ifnothing
, the estimator is unweighted. If provided, must be non-empty.
ReturnsResult
GeneralWeightedCovariance
: A covariance estimator configured with the specified method and optional weights.
Validation
- If
w
is provided, it must not be empty.
Examples
julia> using StatsBase
julia> gwc = GeneralWeightedCovariance()
GeneralWeightedCovariance
ce | StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
w | nothing
julia> w = Weights([0.1, 0.2, 0.7]);
julia> gwc = GeneralWeightedCovariance(; w = w)
GeneralWeightedCovariance
ce | StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
w | StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.1, 0.2, 0.7]
Related
Statistics.cov
— Methodcov(ce::GeneralWeightedCovariance, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Compute the covariance matrix using a GeneralWeightedCovariance
estimator.
This method dispatches to robust_cov
, using the specified covariance estimator and optional observation weights stored in ce
. If no weights are provided, the unweighted covariance is computed; otherwise, the weighted covariance is used.
Arguments
ce::GeneralWeightedCovariance
: Covariance estimator containing the method and optional weights.X::AbstractMatrix
: Data matrix (observations × assets).dims
: Dimension along which to compute the covariance.mean
: Optional mean vector to use for centering.kwargs...
: Additional keyword arguments passed torobust_cov
.
ReturnsResult
- Covariance matrix as computed by the estimator and optional weights.
Related
Statistics.cor
— Methodcor(ce::GeneralWeightedCovariance, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Compute the correlation matrix using a GeneralWeightedCovariance
estimator.
This method dispatches to robust_cor
, using the specified covariance estimator and optional observation weights stored in ce
. If no weights are provided, the unweighted correlation is computed; otherwise, the weighted correlation is used.
Arguments
ce::GeneralWeightedCovariance
: Covariance estimator containing the method and optional weights.X::AbstractMatrix
: Data matrix (observations × assets).dims
: Dimension along which to compute the correlation.mean
: Optional mean vector to use for centering.kwargs...
: Additional keyword arguments passed torobust_cor
.
ReturnsResult
- Correlation matrix as computed by the estimator and optional weights.
Related
PortfolioOptimisers.Covariance
— Typestruct Covariance{T1, T2, T3} <: AbstractCovarianceEstimator
me::T1
ce::T2
alg::T3
end
A flexible container type for configuring and applying joint expected returns and covariance estimation in PortfolioOptimisers.jl.
Covariance
encapsulates all components required for estimating the mean vector and covariance matrix of asset returns, including the expected returns estimator, the covariance estimator, and the moment algorithm. This enables modular and extensible workflows for portfolio optimization and risk modeling.
Fields
me::AbstractExpectedReturnsEstimator
: Expected returns estimator.ce::StatsBase.CovarianceEstimator
: Covariance estimator.alg::AbstractMomentAlgorithm
: Moment algorithm.
Constructor
Covariance(; me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(),
ce::StatsBase.CovarianceEstimator = GeneralWeightedCovariance(),
alg::AbstractMomentAlgorithm = Full())
Construct a Covariance
estimator with the specified expected returns estimator, covariance estimator, and moment algorithm.
Related
PortfolioOptimisers.Covariance
— MethodCovariance(; me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(),
ce::StatsBase.CovarianceEstimator = GeneralWeightedCovariance(),
alg::AbstractMomentAlgorithm = Full())
Construct a Covariance
estimator for joint mean and covariance estimation.
This constructor creates a Covariance
object using the specified expected returns estimator, covariance estimator, and moment algorithm. Defaults are provided for each component to enable robust and extensible estimation workflows.
Arguments
me::AbstractExpectedReturnsEstimator
: Expected returns estimator.ce::StatsBase.CovarianceEstimator
: Covariance estimator.alg::AbstractMomentAlgorithm
: Moment algorithm.
ReturnsResult
Covariance
: A configured joint mean and covariance estimator.
Examples
julia> cov_est = Covariance()
Covariance
me | SimpleExpectedReturns
| w | nothing
ce | GeneralWeightedCovariance
| ce | StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
| w | nothing
alg | Full()
Related
Statistics.cov
— Methodcov(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Compute the full covariance matrix using a Covariance
estimator.
Arguments
ce::Covariance{<:Any, <:Any, <:Full}
: Covariance estimator withFull
moment algorithm.X::AbstractMatrix
: Data matrix (observations × assets).dims::Int
: Dimension along which to compute the covariance.mean
: Optional mean vector for centering. If not provided, computed usingce.me
.kwargs...
: Additional keyword arguments passed to the underlying covariance estimator.
ReturnsResult
- Covariance matrix as computed by the estimator and moment algorithm.
Related
Covariance
AbstractCovarianceEstimator
GeneralWeightedCovariance
Full
Semi
cov(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cor(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cor(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Statistics.cov
— Methodcov(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Compute the semi covariance matrix using a Covariance
estimator.
Arguments
ce::Covariance{<:Any, <:Any, <:Semi}
: Covariance estimator withSemi
moment algorithm.X::AbstractMatrix
: Data matrix (observations × assets).dims::Int
: Dimension along which to compute the covariance.mean
: Optional mean vector for centering. If not provided, computed usingce.me
.kwargs...
: Additional keyword arguments passed to the underlying covariance estimator.
ReturnsResult
- Covariance matrix as computed by the estimator and moment algorithm.
Related
Covariance
AbstractCovarianceEstimator
GeneralWeightedCovariance
Full
Semi
cov(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cor(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cor(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Statistics.cor
— Methodcor(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Compute the full correlation matrix using a Covariance
estimator.
Arguments
ce::Covariance{<:Any, <:Any, <:Full}
: Covariance estimator withFull
moment algorithm.X::AbstractMatrix
: Data matrix (observations × assets).dims::Int
: Dimension along which to compute the correlation.mean
: Optional mean vector for centering. If not provided, computed usingce.me
.kwargs...
: Additional keyword arguments passed to the underlying correlation estimator.
ReturnsResult
- Correlation matrix as computed by the estimator and moment algorithm.
Related
Covariance
AbstractCovarianceEstimator
GeneralWeightedCovariance
Full
Semi
cov(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cov(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cor(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Statistics.cor
— Methodcov(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
Compute the semi correlation matrix using a Covariance
estimator.
Arguments
ce::Covariance{<:Any, <:Any, <:Semi}
: Covariance estimator withSemi
moment algorithm.X::AbstractMatrix
: Data matrix (observations × assets).dims::Int
: Dimension along which to compute the correlation.mean
: Optional mean vector for centering. If not provided, computed usingce.me
.kwargs...
: Additional keyword arguments passed to the underlying correlation estimator.
ReturnsResult
- Correlation matrix as computed by the estimator and moment algorithm.
Related
Covariance
AbstractCovarianceEstimator
GeneralWeightedCovariance
Full
Semi
cov(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cov(ce::Covariance{<:Any, <:Any, <:Semi}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)
cor(ce::Covariance{<:Any, <:Any, <:Full}, X::AbstractMatrix; dims::Int = 1, mean = nothing, kwargs...)