PortfolioOptimisersCovariance: private API
PortfolioOptimisers.find_uncorrelated_indices — Function
find_uncorrelated_indices(X::MatNum;
ce::StatsBase.CovarianceEstimator = PortfolioOptimisersCovariance(),
t::Number = 0.95, absolute::Bool = false,
measure::Num_VecToScaM = MeanValue(),
scores::Option{<:VecNum} = nothing)Find indices of a maximally uncorrelated subset of assets from a data matrix.
This function identifies a subset of asset columns in X such that no two assets in the subset have a pairwise (absolute) correlation exceeding the threshold t. When two assets are too correlated, the one with the higher drop score is removed. The function returns the indices of the remaining uncorrelated assets.
By default the drop score is each asset's summary correlation to every other asset, so the asset that is redundant with the most of the universe goes first. Supplying scores replaces that criterion — higher means "drop me" — which is how RedundancySelector makes the survivor of each correlated pair the better-scoring asset under a risk measure.
Internal machinery — the caller-facing form is RedundancySelector with a PairwiseCorrelation algorithm.
Algorithm
- Compute the correlation matrix
rhowithce, and take its absolute value whenabsoluteistrue. - When
scoresisnothing, collapse each column ofrhowithmeasureintosummary_rho, the default drop score. Otherwise takesummary_rhofromscores. - Read the strict lower triangle of
rhointotril_idx, giving each pair once. - Keep the pairs whose correlation is at least
t, and sort them from the most to the least correlated. - Walk that list. For a pair whose two assets are both still present, remove the one with the higher drop score. When the two scores are equal, remove both — the library's "if we cannot tell them apart, trust neither" tie policy, which is why two identical columns leave no survivor.
- Return the indices that step 5 did not remove, in ascending order.
Step 5 skips a pair whose assets are already removed, so the result depends on the order step 4 fixes.
Arguments
X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.ce: Covariance estimator.t: Correlation threshold above which two assets are considered too correlated.absolute: Iftrue, the absolute value of the correlation is used for comparison.measure: Summary measure applied to each column of the correlation matrix (e.g., mean) to produce the default drop score. Ignored whenscoresis given.scores: Per-asset drop scores; the asset with the higher score is removed from a correlated pair.
Validation
- If
scoresis notnothing,length(scores) == size(X, 2), else aDimensionMismatchis raised.
Returns
idx::Vector{Int}: Indices of assets that form a maximally uncorrelated subset.
Related
PortfolioOptimisers.gap_fill_value — Method
gap_fill_value(ce::PortfolioOptimisersCovariance) -> NumberAnswer what ce.ce answers, because the composite forwards the sample and the mask untouched.
The composite adds matrix processing to an inner estimator and reads no cell of the sample itself, so a gap is the inner estimator's to keep or to lose. A composite wrapping a gap-aware estimator is therefore gap-aware, and one wrapping a plain estimator is not.
Arguments
ce: Composite covariance estimator with post-processing.
Returns
fv::Number:gap_fill_valueofce.ce.
Related
PortfolioOptimisers.show_fields — Method
show_fields(
_::PortfolioOptimisersCovariance
) -> Tuple{Symbol, Symbol}
Renders every field of a PortfolioOptimisersCovariance except cache.
The state a cache holds is the running detail of an incremental fit, not the configuration a reader looks the type up for, and it prints under the estimator at every site that renders one. Set set_show_nothing_fields!(:PortfolioOptimisersCovariance, true) to render it.
Arguments
::PortfolioOptimisersCovariance: Covariance estimator, read for its type alone.
Returns
fields::Tuple: The field names to render, which is(:ce, :mp).
Related
PortfolioOptimisers.supports_partial_fit — Method
supports_partial_fit(
ce::PortfolioOptimisersCovariance
) -> Any
PortfolioOptimisersCovariance method of supports_partial_fit.
The composite folds by composition, so it folds exactly when both of its halves allow it: the inner estimator must fold, and mp must carry no sample-reading alg. A composite a wrapper has given a buffer folds whatever those two say, which is the default and is what makes an mp.alg reachable online at all.
Arguments
ce: Covariance estimator.
Returns
folds::Bool:truewhenpartial_fit!folds this composite.
Related