Feature distance active rows: private API
PortfolioOptimisers.active_window — Function
active_window(amsk, Z::Arr3Num, dims::Integer)Check the active mask of a window against the window, and give it only when a cell of it is inactive.
The active mask marks, for each observation of the window and each asset, whether the asset is in the universe. A window with no inactive cell reads as nothing, so the collapse takes the path that reads every row, and its result is the one it gives with no mask.
Algorithm
- If
amskisnothing, returnnothing. - Otherwise, check that
amskisobservations × assetsfor the layout thatdimsdeclares. - Return
nothingwhen every entry ofamskistrue, andamskotherwise.
Arguments
amsk: The active mask of the window,observations × assets, ornothingwhen every cell is active.Z: Feature matrix,assets × featureswhendims = 1andfeatures × assetswhendims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis:assets × features × observationswhendims = 1, andfeatures × assets × observationswhendims = 2.dims: Dimension along which the computation runs.
Validation
size(amsk) == (size(Z, 3), assets). Raises aDimensionMismatch.
Returns
A::Option{<:AbstractMatrix{Bool}}: The active mask, ornothingwhen every cell is active.
Related
PortfolioOptimisers.blank_unreadable — Function
blank_unreadable(Z::Arr3Num, A::AbstractMatrix{Bool}, dims::Integer)Give a copy of a window of time-varying features with a zero at each cell that the mask A marks unreadable.
A collapse reads each asset, or each pair of assets, only at its own readable rows, so the value of an unreadable cell must reach neither the distance nor a refusal. distance checks this copy with assert_feature_matrix and collapses it. A NaN, or a value outside the domain of the metric, at an unreadable cell then refuses nothing. No result of a collapse reads it either. StackObservations measures the whole stack, and then replaces the distance of each pair that holds an unreadable cell. AggregateDistances measures every asset at each row, and keeps only the pairs whose two assets are active at the row. The zero is the value that feature_window writes at a placeholder, and that the panel collapse of a meta-optimiser writes at an inactive cell. The copy keeps the element type of Z.
Algorithm
- Lay the mask
Aout againstZ, givingM. Atdims = 1,Mis the transpose ofAreshaped toassets × 1 × observations. Atdims = 2, it is reshaped to1 × assets × observations. - Broadcast
ifelseoverMandZ. Keep each cell ofZwhereMistrue, and writezero(eltype(Z))elsewhere.
Arguments
Z: Feature matrix,assets × featureswhendims = 1andfeatures × assetswhendims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis:assets × features × observationswhendims = 1, andfeatures × assets × observationswhendims = 2.A: The mask of readable cells of the window,observations × assets.dims: Dimension along which the computation runs.
Returns
Zr::Array: The window, the same size and element type asZ, with a zero at each unreadable cell.
Related
PortfolioOptimisers.feature_asset_labels — Function
feature_asset_labels(nx, i::AbstractVector{<:Integer}) -> String
feature_asset_labels(nx, E::AbstractVector{<:Tuple}) -> StringName the assets at the positions i, or the pairs of positions E, for a refusal. The text quotes the names when nx holds them, and the positions otherwise.
Algorithm
The method that Julia selects is the algorithm.
- If
nxisnothing, quotei, or the pairs ofEjoined by commas. - Otherwise, quote
nx[i], or the pair of names of each pair ofEjoined by commas.
Arguments
nx: The asset names, ornothing.i: The positions of the assets.E: The pairs of positions,(i, j).
Returns
s::String: The phrase that names the assets, for the message of a refusal.
Related
PortfolioOptimisers.assert_feature_readable — Function
assert_feature_readable(alg, A, nx)Refuse a window in which the collapse has no value to read for an asset, and name each such asset.
Inside a fit, feature_readable_mask drops such an asset at the entry of the optimiser, so the collapse never meets it. A direct call of distance, cor_and_dist or clusterise has no entry of a fit, so it refuses here.
Algorithm
- If
Aisnothing, every cell is readable, so returnnothing. - Otherwise, find the assets that
feature_readabledoes not mark, givingi. - Refuse when
iis not empty. The message names each asset ofiwithfeature_asset_labels, and gives the cause and the remedy fromunreadable_message.
Arguments
alg: The collapse algorithm.A: The active mask of the window,observations × assets, ornothingwhen every cell is active.nx: The asset names, ornothing.
Validation
- Every asset is readable by
feature_readable. Raises anArgumentErrorthat names each other asset and the remedy.
Returns
nothing.
Related
PortfolioOptimisers.unreadable_message — Function
unreadable_message(alg::AbstractFeatureCollapseAlgorithm) -> StringState why a collapse has no value to read for an asset, and the remedy, for the refusal of assert_feature_readable. LastRow reads the last row alone, so it names LastActiveRow as a remedy too.
Algorithm
The method that Julia selects is the algorithm.
- Under
LastRow, the cause is the last row. The remedies are a view of the returns data andLastActiveRow. - Under every other collapse, the cause is a window with no readable row. The remedy is a view of the returns data.
Arguments
alg: The collapse algorithm.
Returns
s::String: The cause and the remedy.
Related
PortfolioOptimisers.asset_major — Function
asset_major(Z::Arr3Num, dims::Integer)Give a window of time-varying features in the layout assets × features × observations, whichever of the two first axes dims says the assets occupy.
Algorithm
- At
dims = 1, returnZ. - At
dims = 2, return aPermutedDimsArrayofZthat swaps its two first axes. It copies nothing.
Arguments
Z: Feature matrix,assets × featureswhendims = 1andfeatures × assetswhendims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis:assets × features × observationswhendims = 1, andfeatures × assets × observationswhendims = 2.dims: Dimension along which the computation runs.
Returns
Zd::AbstractArray{<:Number, 3}: The window,assets × features × observations.
Related
PortfolioOptimisers.active_collapse — Function
active_collapse(alg::AbstractCollapseAlgorithm, Zd::Arr3Num, w, A, nx)Collapse each asset's features over its own active rows, with the weights of those rows.
The caller resolves the weights once against the whole window, with collapse_weights. Each asset keeps the entries of its active rows, and the collapse divides by their sum, so an inactive cell has no weight.
Mathematical definition
\[\begin{align} \bar{z}_{i,\,k} &= \dfrac{\sum\limits_{t=1}^{T} w_{t} a_{t,\,i} z_{t,\,i,\,k}}{\sum\limits_{t=1}^{T} w_{t} a_{t,\,i}}\,, \end{align}\]
Where:
- $\bar{z}_{i,\,k}$: Collapsed feature $k$ of asset $i$, the aggregate of $z_{t,\,i,\,k}$ over the observation axis.
- $z_{t,\,i,\,k}$: Value of feature $k$ of asset $i$ at observation $t$, one entry of the feature window.
- $a_{t,\,i}$: Window activity of asset $i$ at observation $t$,
1when the active mask of the feature window marks the asset active and0otherwise. - $w_{t}$: Observation weight of observation $t$.
- $T$: Number of observations.
MedianCollapse takes the same restricted weights.
Algorithm
- Find the active rows of each asset, giving
rows. - If
wis notnothing, check that the weights of the active rows of each asset sum to more than zero. - Collapse each asset over its active rows with
collapse_features, under the weights of those rows fromnothing_scalar_array_getindex, givingzs. That function keeps the kind of the weights, andnothingweights staynothing. - Stack
zsby asset,assets × features.
Arguments
alg: The collapse algorithm.Zd: The window,assets × features × observations.w: The resolved observation weights of the window, ornothing.A: The active mask of the window,observations × assets.nx: The asset names, ornothing.
Validation
- The weights of the active rows of each asset sum to more than zero. Raises an
ArgumentErrorthat names each other asset.
Returns
Zc::Matrix{<:Number}: The collapsed features,assets × features.
Related
PortfolioOptimisers.pair_distance — Function
pair_distance(metric::Distances.SemiMetric, a::AbstractVector, b::AbstractVector)Measure one pair of feature vectors, and apply the zero-feature-vector convention of patch_zero_feature_vectors! to the result.
Algorithm
- Measure
aagainstbwithmetric, givingd. - If
dis notNaN, or neither vector is all zero, returnd. - Otherwise, return zero when both vectors are all zero, and one when only one of them is.
Arguments
metric: The distance metric.a,b: The feature vectors of the two assets.
Returns
d::Number: The distance of the pair.
Related
PortfolioOptimisers.stack_metric — Function
stack_metric(metric::Distances.SemiMetric, idx::AbstractVector{<:Integer})Restrict a metric to the coordinates idx of a stack. A metric whose parameters hold one entry per coordinate keeps the entries of those coordinates. The function returns every other metric unchanged.
A metric that another package defines, with parameters that hold one entry per coordinate, needs a method of this function too. Without it, the metric measures the shared coordinates with all its parameters, and it raises its own error before stack_rescale can refuse.
Algorithm
The method that Julia selects is the algorithm.
- For a weighted metric of Distances.jl,
Distances.WeightedHammingincluded, keepweights[idx]. - For
Distances.PeriodicEuclidean, keepperiods[idx]. - For
Distances.MahalanobisandDistances.SqMahalanobis, keep the principal submatrixqmat[idx, idx], which is the quadratic form on the shared coordinates. - For every other metric, return
metric.
Arguments
metric: The distance metric.idx: The coordinates of the stack that a pair shares.
Returns
metric::Distances.SemiMetric: The metric on the coordinatesidx.
Related
PortfolioOptimisers.stack_rescale — Function
stack_rescale(metric::Distances.SemiMetric, d::Number, idx::AbstractVector{<:Integer}, len::Integer)Rescale the distance d of a pair, measured on the coordinates idx of a stack, to all len coordinates of the stack.
StackObservations measures a pair on the rows at which both assets are active. A metric that sums over the coordinates then sums over fewer of them, and gives a smaller distance than the whole window would. The rescale makes the sum an estimate of the sum over the whole window.
Mathematical definition
| Metric | Rescale |
|---|---|
Distances.Cityblock, Distances.TotalVariation, Distances.SqEuclidean, Distances.ChiSqDist | $d \cdot L / n$ |
Distances.Euclidean | $d \cdot \sqrt{L / n}$ |
Distances.Minkowski | $d \cdot (L / n)^{1/p}$ |
| A weighted form | the ratio of the weight sums in place of $L / n$ |
AngularDist, Distances.CosineDist, Distances.CorrDist, Distances.Jaccard, Distances.BrayCurtis, and the three mean deviations | none |
Where $L$ is len and $n$ is the length of idx. The coordinates of one row carry the features of one observation, so $L / n$ is $T$ over the count of shared rows. A weighted form takes $W / W_{n}$, where $W$ is the sum of its weights and $W_{n}$ is the sum of its weights at idx.
Algorithm
The method that Julia selects is the algorithm.
- For a metric of the table, return
dtimes the factor of its row. - For every other metric, refuse, and name the method to add.
Arguments
metric: The distance metric.d: The distance of the pair on the coordinatesidx.idx: The coordinates of the stack that the pair shares.len: The number of coordinates of the stack.
Validation
metricis a metric of the table. Raises anArgumentErrorthat names the methodPortfolioOptimisers.stack_rescaleto add for the type ofmetric.
Returns
d: The rescaled distance.
Related
PortfolioOptimisers.fallback_features — Function
fallback_features(alg::AbstractFeatureCollapseAlgorithm, z::AbstractVector, T::Integer)Lay out the collapsed features of an asset as the collapse reads one asset. AggregateDistances reads the features of one row, z itself. StackObservations reads the stack of every row, so z fills each of the T rows.
Algorithm
The method that Julia selects is the algorithm.
- Under
AggregateDistances, returnz. - Under
StackObservations, repeat each entry ofzTtimes,repeat(z; inner = T). Featurekthen fills the coordinatest + (k - 1) Tof the stack, asstack_observationslays them out.
Arguments
alg: The collapse algorithm of the estimator.z: The collapsed features of one asset.T: The number of observations of the window.
Returns
zf::AbstractVector: The features of the asset, as the collapse reads them.
Related
PortfolioOptimisers.resolve_empty_pairs! — Function
resolve_empty_pairs!(D::MatNum, pair::AbstractEmptyPairAlgorithm, E, de::FeatureDistance, win)Give the empty pairs E to empty_pair_distance!, or return D unchanged when no pair is empty.
Algorithm
- If
Eis empty, returnD. - Otherwise, return
empty_pair_distance!ofDunder the rulepair.
Arguments
D: The distance matrix,assets × assets.pair: The rule for an empty pair.E: The empty pairs,(i, j)withi < j.de: The feature distance estimator.win: The window, aNamedTupleofZ,dims,Aandnx.
Returns
D::MatNum: Distance matrixassets x assets, in the units the distance algorithm defines.
Related
PortfolioOptimisers.active_feature_distance — Function
active_feature_distance(de::FeatureDistance, win::NamedTuple)Turn a window of time-varying features that holds an inactive cell into a distance matrix, reading each asset or each pair at its own active rows.
win holds the window Z, its layout dims, its active mask A and the asset names nx. Z holds a zero at each cell that A marks false, from blank_unreadable, so no step of a collapse reads the stored value of such a cell. distance calls this function only when a cell of the window is inactive, and only after assert_feature_readable checked that the collapse can read each asset. A window with no inactive cell takes the path of feature_distance, so its result does not change.
Under AggregateDistances and StackObservations, an entry can be a weighted mean or a rescaled distance. So float_if_integer turns an integer result type of the metric, such as the count of Distances.Hamming, into a floating point type. The matrix of a Rational window stays exact.
Mathematical definition
Under LastActiveRow, the collapse reads each asset at its last active row.
\[\begin{align} \tau_{i} &= \max\left\{t : a_{t,\,i} = 1\right\}\,,\\ D_{i,\,j} &= m\left(\boldsymbol{z}_{\tau_{i},\,i},\, \boldsymbol{z}_{\tau_{j},\,j}\right)\,. \end{align}\]
Where:
- $D_{i,\,j}$: The distance between assets $i$ and $j$.
- $a_{t,\,i}$: Window activity of asset $i$ at observation $t$,
1when the active mask of the feature window marks the asset active and0otherwise. - $\tau_{i}$: Last active row of asset $i$ in the window.
- $\boldsymbol{z}_{t,\,i}$: Feature vector of asset $i$ at observation $t$.
- $m$: Distance metric,
de.metric.
Under AggregateFeatures, $D_{i,\,j}$ is the metric of the collapsed vectors that active_collapse defines. AggregateDistances and StackObservations each state their own form for a window with an inactive cell.
Algorithm
The type of de.alg selects one of four methods.
- Under
LastRow, or when every asset is active at the last row, measure the last row. - Under
LastActiveRowotherwise, read the features of each asset at its last active row, givingzs, and measure the stack ofzs. - Under
AggregateFeatures, resolve the weights withcollapse_weights. Collapse each asset over its own active rows withactive_collapse, givingZc, and measureZc. - Under
AggregateDistances, resolve the weights, and measure each row intoDt. Add each entry ofDttoD, and the weight of the row to the weight totalS, only for a pair whose two assets are active at the row, withaccumulate_active_pairs!. - Then check that the weight total of each asset, on the diagonal of
S, is not zero. Collect each pair with a zero total, givingE. DivideDbyS, and giveEtoresolve_empty_pairs!. - Under
StackObservations, measure the whole stack, givingD. Measure each pair that shares fewer rows than the window again, withshared_stack_distance. Collect each pair with no shared row, givingE, and giveEtoresolve_empty_pairs!.
Arguments
de: Feature distance estimator.win: The window, aNamedTupleofZ,dims,Aandnx.
Validation
- Under
AggregateDistances, the weights of the active rows of each asset do not sum to zero. Raises anArgumentErrorthat names each other asset. - A pair with no shared active row takes the rule
pairof the collapse. Seeempty_pair_distance!.
Returns
D::MatNum: Distance matrixassets x assets, in the units the distance algorithm defines.
Related
PortfolioOptimisers.accumulate_active_pairs! — Function
accumulate_active_pairs!(D::MatNum, S::MatNum, Dt::MatNum, wt::Number, m::AbstractVector{Bool})Add one row of AggregateDistances to its accumulators, for each pair whose two assets are both active at the row, as m marks them.
Algorithm
- For each pair
(i, j)withm[i]andm[j], addwt * Dt[i, j]toD[i, j], and addwtto the weight totalS[i, j].
Arguments
D: The sum of the weighted distances,assets × assets, changed in place.S: The weight total of each pair,assets × assets, changed in place.Dt: The distance matrix of the row.wt: The weight of the row.m: The active mask of the row, one entry per asset.
Returns
nothing.
Related
PortfolioOptimisers.shared_stack_distance — Function
shared_stack_distance(metric::Distances.SemiMetric, Zs::MatNum, (i, j), rows::AbstractVector, T::Integer)Measure the pair (i, j) of a stack Zs, assets × (observations · features), on the coordinates of its shared active rows, and rescale the distance to the whole window of T rows.
Algorithm
- Name the coordinates of the shared rows,
t + (k - 1) Tfor each shared rowtand each featurek, givingidx. - Measure the two assets on
idxwithpair_distance, under the metric thatstack_metricrestricts toidx, givingd. - Rescale
dto every coordinate of the stack withstack_rescale.
Arguments
metric: The distance metric.Zs: The stack,assets × (observations · features).(i, j): The pair of assets.rows: The rows at which both assets are active.T: The number of observations of the window.
Returns
d::Number: The rescaled distance of the pair.
Related
PortfolioOptimisers.feature_readable_mask — Function
feature_readable_mask(x, imsk::Option{<:BitVector}, rd) -> Option{BitVector}Compose the Investable Mask of a prior with the assets that each FeatureDistance inside x can read, at the entry of a fit.
A fit reduces its prior, its optimiser and its returns data to the Investable Mask once, at its entry, with investable_reduction. An asset that the prior admits can still have no value that a FeatureDistance of the fit can read in the window of its Asset Panel. A cell is readable where the asset is active and every value column of the Feature Selector holds data, observed or filled. LastRow reads nothing for an asset whose last cell is not readable, and every collapse reads nothing for an asset with no readable row. A static panel has one row, so an asset with a placeholder has none. This function drops such an asset from the mask before the reduction. The asset then departs as a non-investable asset. The reduction announces it, the fit gives it a zero weight, and the Non-Investable Axis lists it. Under DropFewerRows, the function also drops the asset with fewer active rows from each pair with no shared active row, until no pair is empty.
A default prior keeps only the Coverage Universe, the assets that are active at every row of its window. So under a default prior, this function drops only an asset with a placeholder.
Every fit that clusters or builds a phylogeny calls it: HierarchicalRiskParity, HierarchicalEqualRiskContribution, SchurComplementHierarchicalRiskParity, NestedClustered, and a JuMPOptimiser through its phylogeny and centrality estimators. Stacking and SubsetResampling cluster only inside their inner optimisers, and each of those calls it at its own entry.
Algorithm
The method that Julia selects is the algorithm.
- For a
Tupleor a vector, compose the mask of each entry in turn. - For an estimator that holds a distance estimator, such as a
ClustersEstimator, forward to the estimator it holds. - For a
FeatureDistancewith no producer, on returns data that holds a panel, take the mask of readable cells in the rows that the collapse reads, withentry_activity. Compose it withimskthroughcompose_readable_mask. - In every other case, a producer and returns data with no panel included, return
imskunchanged.
A panel whose every cell is readable takes step 3, and it gives a mask equal to imsk.
Arguments
x: An estimator, a vector or aTupleof estimators.imsk: The Investable Mask of the prior, ornothingwhen every asset is investable.rd: The returns result to use.
Validation
- At least one asset stays. Raises an
IsEmptyError.
Returns
imsk::Option{BitVector}: The composed mask, ornothingwhen every asset stays.
Related
PortfolioOptimisers.compose_readable_mask — Function
compose_readable_mask(alg::AbstractFeatureCollapseAlgorithm, A, imsk::Option{<:BitVector})Compose the Investable Mask imsk with the assets that the collapse alg can read in a window whose active mask is A. This is step 3 of feature_readable_mask. A window with no active mask, A === nothing, keeps imsk.
Algorithm
- If
Aisnothing, returnimsk. - Mark the assets that
algcan read withfeature_readable, givingkeep. Ifimskis notnothing, keep only the assets thatimskkeeps too. - Drop assets from
keepwithdrop_empty_pairs!, under the rule ofempty_pair_ruleforalg. - Check that
keepkeeps one asset at least. - Return
nothingwhenimskisnothingandkeepkeeps every asset, andkeepotherwise.
Arguments
alg: The collapse algorithm.A: The mask of readable cells of the window,observations × assets, ornothing.imsk: The Investable Mask of the prior, ornothingwhen every asset is investable.
Validation
- At least one asset stays. Raises an
IsEmptyError.
Returns
imsk::Option{BitVector}: The composed mask, ornothingwhen every asset stays.
Related
PortfolioOptimisers.entry_activity — Function
entry_activity(de::FeatureDistance, pnl)Give the mask of the cells that de can read in the window of the panel pnl, with feature_window_mask, for the entry of a fit. Returns data with no panel gives nothing.
Algorithm
The method that Julia selects is the algorithm.
- If
pnlisnothing, returnnothing. - Otherwise, resolve
de.selagainstpnlwithselect_fields. Return the mask thatfeature_window_maskgives for those columns.
Arguments
de: Feature distance estimator.pnl: The Asset Panel of the returns data, ornothing.
Returns
A::Option{<:AbstractMatrix{Bool}}: The mask of readable cells in the rows that the collapse reads, ornothing.
Related
PortfolioOptimisers.feature_window_mask — Function
feature_window_mask(alg, pnl::AssetPanel, cols::AbstractVector{Tuple{Int, Int, Symbol}}) -> (rows, A)Name the rows that a collapse reads, and cut the mask of the cells it can read to them.
A cell is readable where the asset is active and every value column of cols holds data. A cell that holds the placeholder of a blank that no fill reached holds no data. So a collapse reads it as it reads an inactive cell, and reads each asset and each pair at its own readable rows. The rows come from this mask, so LastActiveRow reads the last readable row of each asset.
Algorithm
- Join the active mask of the panel with the cells of
colsthat hold data, fromfeature_data_cells, throughreadable_cells. This givesR. - Name the rows that the collapse reads on
Rwithreadable_window_rows, givingrows. - Cut
Rtorowswithwindow_activity, givingA.
Arguments
alg: The collapse algorithm.pnl: The Asset Panel.cols: The resolved columns, fromselect_fields.
Returns
rows: Therowskeyword offeature_matrix.A::Option{<:AbstractMatrix{Bool}}: The mask of readable cells in those rows, seewindow_activity.
Related
PortfolioOptimisers.readable_cells — Function
readable_cells(amsk, o)Join the active mask amsk of a panel with the mask o of its cells that hold data. A cell is readable where both are true. Either mask can be nothing, which marks every cell true.
Algorithm
The method that Julia selects is the algorithm.
- If
oisnothing, returnamsk. - If
amskisnothing, returno. - Otherwise, return
amsk .& o.
Arguments
amsk: The active mask of the panel, ornothing.o: The mask of the cells that hold data, ornothing.
Returns
R: The mask of readable cells, ornothingwhen every cell is readable.
Related
PortfolioOptimisers.readable_window_rows — Function
readable_window_rows(alg, pnl::AssetPanel, R)Name the rows that a collapse reads on the mask R of readable cells. LastActiveRow reads the rows of R, so it reads an asset whose last active cell holds a placeholder at its last readable row.
Algorithm
The method that Julia selects is the algorithm.
- Under
LastActiveRow, with a matrixRof a time-varying panel, name the rows withlast_active_rowsonR. - In every other case, a static panel and
R === nothingincluded, name the rows withcollapse_rows.
Arguments
alg: The collapse algorithm.pnl: The Asset Panel.R: The mask of readable cells,observations × assetson a time-varying panel, one entry per asset on a static panel, ornothing.
Returns
rows: A range of observations, orColon(). It is the value of therowskeyword offeature_matrix.
Related
PortfolioOptimisers.last_active_rows — Function
last_active_rows(A)Name the rows from the earliest last true row of an asset in the mask A, observations × assets, to the last row. These rows hold the last true row of every asset that has one.
Algorithm
The method that Julia selects is the algorithm.
- If
Aisnothing, every row is active, so returnColon(). - Otherwise, find the last
truerow of each asset, ornobsfor an asset with none. The earliest of these rows isr0. - Return
r0:nobs.
Arguments
A: The mask,observations × assets, ornothing.
Returns
rows::Union{UnitRange{Int}, Colon}: The rowsr0:nobs, orColon().
Related
PortfolioOptimisers.static_window — Function
static_window(amsk, Z::MatNum, dims::Integer)Check the one-row mask of a static Feature Matrix against the matrix. A static matrix has one row of cells, so its mask is 1 × assets, and nothing marks every asset readable.
Algorithm
- If
amskisnothing, returnnothing. - Otherwise, check the size of
amsk, and returnamsk.
Arguments
amsk: The mask of the static Feature Matrix,1 × assets, ornothing.Z: Feature matrix,assets × featureswhendims = 1andfeatures × assetswhendims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis:assets × features × observationswhendims = 1, andfeatures × assets × observationswhendims = 2.dims: Dimension along which the computation runs.
Validation
size(amsk) == (1, assets), wheredimsnames the asset axis ofZ. Raises aDimensionMismatch.
Returns
A::Option{<:AbstractMatrix{Bool}}:amsk.
Related
PortfolioOptimisers.empty_pair_rule — Function
empty_pair_rule(alg::AbstractFeatureCollapseAlgorithm)Give the rule that a collapse holds for a pair with no shared active row.
Algorithm
The method that Julia selects is the algorithm.
- Under
AggregateDistancesandStackObservations, return thepairfield. - Under every other collapse, which reads no pair, return
nothing.
Arguments
alg: The collapse algorithm.
Returns
pair::Option{<:AbstractEmptyPairAlgorithm}: The rule for an empty pair, ornothing.
Related
PortfolioOptimisers.first_empty_pair — Function
first_empty_pair(keep::BitVector, A::AbstractMatrix{Bool})Find the first pair (i, j) of kept assets, with i < j, that shares no active row of A, or nothing when no pair is empty.
Algorithm
- Find the kept assets, giving
k. - For each
jofk, and then eachiofkwithi < j, return(i, j)when no row ofAmarks both assets active. - Return
nothing.
Arguments
keep: The kept assets.A: The active mask of the window,observations × assets.
Returns
p::Option{Tuple{Int, Int}}: The first empty pair, ornothing.
Related