Base asset selection
What every asset selector shares
An asset selector is a preprocessing estimator that removes assets from the returns. It chooses the assets on the training window, and keeps the same assets on every later window. The selectors are on the Asset selection page. This page has the result type they all return, AssetSelectorResult, and select_assets, the one method a new selector must write. A new selector subtypes AbstractAssetSelector.
Types
PortfolioOptimisers.AbstractAssetSelector — Type
abstract type AbstractAssetSelector <: AbstractReturnsPreprocessingEstimatorAbstract supertype for returns-level preprocessing estimators that restrict the asset universe.
An asset selector decides on the training window which asset columns to keep, and that decision is its fitted state. apply_preprocessing replays the fitted universe on each later window. The selection reads the training window alone, and the selector never selects again on a test window, so a selector is safe inside cross-validation.
The whole family shares one method of fit_preprocessing and one of apply_preprocessing. That method of fit_preprocessing reduces the training window to its Coverage Universe before it calls select_assets. A selector therefore ranks only the assets that are live at every row of the window, and never an asset that is not yet listed, is delisted, or misses a quote. It needs no finiteness guard of its own, and CompleteAssetSelector keeps every column of the reduced window.
A selector drops asset columns and never an observation. MissingDataFilter drops observations, from a price window.
Interfaces
To implement a new asset selector, subtype AbstractAssetSelector with its parameters as fields of the struct, and implement the following method:
select_assets(sel::MyAssetSelector, rd::AbstractReturnsResult) -> BitVector: Return the keep-mask over the asset columns of the reduced training window.
Arguments
sel: The concrete asset selector instance.rd: The training window, reduced to its Coverage Universe.
Returns
keep::BitVector: Maskassets × 1that istruefor every asset to keep. It holds one entry per asset column ofrd, and at least one entry istrue.
Related
PortfolioOptimisers.AssetSelectorResult — Type
struct AssetSelectorResult{__T_nx} <: AbstractReturnsPreprocessingResultFitted result of any AbstractAssetSelector.
It holds the names of the assets that the selector kept on the training window. Every selector stores the same thing, so one result type serves the whole family.
Fields
nx: Names of the assets that the selector kept on the training window, in the column order of that window. This is the fitted universe.
Related
Functions
PortfolioOptimisers.select_assets — Function
select_assets(sel::AbstractAssetSelector, rd::AbstractReturnsResult) -> BitVectorReturn the keep-mask over the asset columns of rd.
A concrete AbstractAssetSelector must implement this method, and no other. fit_preprocessing calls it on the Coverage Universe of the training window, and apply_preprocessing replays the result on every later window.
rd is the returns data reduced to its Coverage Universe, so every column of it is finite and active at every row. A selector needs no finiteness guard. A score that is not finite on a column of finite returns is a defect of the score, and asset_scores refuses it.
A selector reads rd.nx and the observations × assets matrix rd.X. The reduction reads rd.pnl, and ClusterGroups gives the whole of rd to clusterise, so the family reads the fields nx, X and pnl of AbstractReturnsResult. A selector never sees a prior result.
Arguments
sel: The asset selector.rd: The training window, reduced to its Coverage Universe.
Validation
- A subtype that does not implement this method throws an
ArgumentErrorthat names the subtype.
Returns
keep::BitVector: Maskassets × 1that istruefor each asset column to keep, withlength(keep) == size(rd.X, 2).
Related
select_assets(
sel::ScoreSelector,
rd::AbstractReturnsResult
) -> BitVector
Select the assets that a ScoreSelector keeps. The method scores every asset, then it applies the rule.
fit_preprocessing first reduces the training window to its Coverage Universe. The method ranks only the live assets, and a dead column has no place in the order. asset_scores still refuses a non-finite score on a live column. That is a defect of the measure, not a gap in the data.
Algorithm
- Score every asset column of
rdwith thescoreof the selector, throughasset_scores. - Read the orientation of the score with
bigger_is_better. - Return the keep-mask that
rule_keepgives for those scores under theruleof the selector.
Arguments
sel: The score selector.rd: The returns result to use.
Returns
keep::BitVector: The maskassets × 1. It istruefor every asset that the rule admits.
Related
select_assets(
_::CompleteAssetSelector,
rd::AbstractReturnsResult
) -> BitVector
Select the assets that a CompleteAssetSelector keeps. These are all the asset columns of the reduced window.
This selector is the identity on the Coverage Universe. fit_preprocessing reduces the training window before it calls this method. Each column that this method gets is finite at every row, and active at every row of the AssetPanel. fit_preprocessing drops the other columns, and this selector is the explicit step that asks for the drop.
The reduction also reads the active mask of the panel. An asset with an old finite price in an inactive period is out of the universe. The released versions of this selector read only the finiteness, and kept that asset.
Algorithm
- Return a keep-mask of
size(rd.X, 2)trues.
Arguments
- The method takes the selector by type alone. The selector has no field, so the method reads nothing from it.
rd: The returns result to use.
Returns
keep::BitVector: The maskassets × 1. It istrueat every column of the reduced window.
Related
select_assets(
sel::RedundancySelector,
rd::AbstractReturnsResult
) -> BitVector
Select the assets that a RedundancySelector keeps. The method scores every asset when the selector has a score, then it applies the redundancy algorithm.
fit_preprocessing first reduces the training window to its Coverage Universe. The correlation, the clusters and the survivor rule then read only the live columns. A dead column is never in a group, and it never survives one.
Algorithm
- When the selector has no
score, setscorestonothingandbibtofalse. The algorithm then uses its own survivor rule. - Otherwise score every asset column of
rdwithasset_scores, and readbibfrombigger_is_betterof that score. - Return the keep-mask that
redundancy_keepadmits for thealgof the selector.
Arguments
sel: The redundancy selector.rd: The returns result to use.
Returns
keep::BitVector: The maskassets × 1. It istruefor every asset that survives.
Related
PortfolioOptimisers.keeps_observations — Method
keeps_observations(res::AssetSelectorResult) -> trueReturn true, because an asset selection keeps every observation of the window.
apply_preprocessing selects the columns of the fitted universe and leaves the observation axis as it is. So a Pipeline fold whose steps select assets still records its rows, and a realised factor_attribution of the cross-validation finds the block rows of each fold by position.
Arguments
res: The fitted asset selection.
Returns
flag::Bool:true.
Related