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

  1. If amsk is nothing, return nothing.
  2. Otherwise, check that amsk is observations × assets for the layout that dims declares.
  3. Return nothing when every entry of amsk is true, and amsk otherwise.

Arguments

  • amsk: The active mask of the window, observations × assets, or nothing when every cell is active.
  • Z: Feature matrix, assets × features when dims = 1 and features × assets when dims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis: assets × features × observations when dims = 1, and features × assets × observations when dims = 2.
  • dims: Dimension along which the computation runs.

Validation

  • size(amsk) == (size(Z, 3), assets). Raises a DimensionMismatch.

Returns

  • A::Option{<:AbstractMatrix{Bool}}: The active mask, or nothing when every cell is active.

Related

source
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

  1. Lay the mask A out against Z, giving M. At dims = 1, M is the transpose of A reshaped to assets × 1 × observations. At dims = 2, it is reshaped to 1 × assets × observations.
  2. Broadcast ifelse over M and Z. Keep each cell of Z where M is true, and write zero(eltype(Z)) elsewhere.

Arguments

  • Z: Feature matrix, assets × features when dims = 1 and features × assets when dims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis: assets × features × observations when dims = 1, and features × assets × observations when dims = 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 as Z, with a zero at each unreadable cell.

Related

source
PortfolioOptimisers.feature_asset_labels — Function
feature_asset_labels(nx, i::AbstractVector{<:Integer}) -> String
feature_asset_labels(nx, E::AbstractVector{<:Tuple}) -> String

Name 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.

  1. If nx is nothing, quote i, or the pairs of E joined by commas.
  2. Otherwise, quote nx[i], or the pair of names of each pair of E joined by commas.

Arguments

  • nx: The asset names, or nothing.
  • 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

source
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

  1. If A is nothing, every cell is readable, so return nothing.
  2. Otherwise, find the assets that feature_readable does not mark, giving i.
  3. Refuse when i is not empty. The message names each asset of i with feature_asset_labels, and gives the cause and the remedy from unreadable_message.

Arguments

  • alg: The collapse algorithm.
  • A: The active mask of the window, observations × assets, or nothing when every cell is active.
  • nx: The asset names, or nothing.

Validation

  • Every asset is readable by feature_readable. Raises an ArgumentError that names each other asset and the remedy.

Returns

  • nothing.

Related

source
PortfolioOptimisers.unreadable_message — Function
unreadable_message(alg::AbstractFeatureCollapseAlgorithm) -> String

State 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.

  1. Under LastRow, the cause is the last row. The remedies are a view of the returns data and LastActiveRow.
  2. 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

source
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

  1. At dims = 1, return Z.
  2. At dims = 2, return a PermutedDimsArray of Z that swaps its two first axes. It copies nothing.

Arguments

  • Z: Feature matrix, assets × features when dims = 1 and features × assets when dims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis: assets × features × observations when dims = 1, and features × assets × observations when dims = 2.
  • dims: Dimension along which the computation runs.

Returns

  • Zd::AbstractArray{<:Number, 3}: The window, assets × features × observations.

Related

source
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$, 1 when the active mask of the feature window marks the asset active and 0 otherwise.
  • $w_{t}$: Observation weight of observation $t$.
  • $T$: Number of observations.

MedianCollapse takes the same restricted weights.

Algorithm

  1. Find the active rows of each asset, giving rows.
  2. If w is not nothing, check that the weights of the active rows of each asset sum to more than zero.
  3. Collapse each asset over its active rows with collapse_features, under the weights of those rows from nothing_scalar_array_getindex, giving zs. That function keeps the kind of the weights, and nothing weights stay nothing.
  4. Stack zs by asset, assets × features.

Arguments

  • alg: The collapse algorithm.
  • Zd: The window, assets × features × observations.
  • w: The resolved observation weights of the window, or nothing.
  • A: The active mask of the window, observations × assets.
  • nx: The asset names, or nothing.

Validation

  • The weights of the active rows of each asset sum to more than zero. Raises an ArgumentError that names each other asset.

Returns

  • Zc::Matrix{<:Number}: The collapsed features, assets × features.

Related

source
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

  1. Measure a against b with metric, giving d.
  2. If d is not NaN, or neither vector is all zero, return d.
  3. 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

source
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.

  1. For a weighted metric of Distances.jl, Distances.WeightedHamming included, keep weights[idx].
  2. For Distances.PeriodicEuclidean, keep periods[idx].
  3. For Distances.Mahalanobis and Distances.SqMahalanobis, keep the principal submatrix qmat[idx, idx], which is the quadratic form on the shared coordinates.
  4. 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 coordinates idx.

Related

source
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

MetricRescale
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 formthe ratio of the weight sums in place of $L / n$
AngularDist, Distances.CosineDist, Distances.CorrDist, Distances.Jaccard, Distances.BrayCurtis, and the three mean deviationsnone

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.

  1. For a metric of the table, return d times the factor of its row.
  2. For every other metric, refuse, and name the method to add.

Arguments

  • metric: The distance metric.
  • d: The distance of the pair on the coordinates idx.
  • idx: The coordinates of the stack that the pair shares.
  • len: The number of coordinates of the stack.

Validation

  • metric is a metric of the table. Raises an ArgumentError that names the method PortfolioOptimisers.stack_rescale to add for the type of metric.

Returns

  • d: The rescaled distance.

Related

source
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.

  1. Under AggregateDistances, return z.
  2. Under StackObservations, repeat each entry of z T times, repeat(z; inner = T). Feature k then fills the coordinates t + (k - 1) T of the stack, as stack_observations lays 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

source
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

  1. If E is empty, return D.
  2. Otherwise, return empty_pair_distance! of D under the rule pair.

Arguments

  • D: The distance matrix, assets × assets.
  • pair: The rule for an empty pair.
  • E: The empty pairs, (i, j) with i < j.
  • de: The feature distance estimator.
  • win: The window, a NamedTuple of Z, dims, A and nx.

Returns

  • D::MatNum: Distance matrix assets x assets, in the units the distance algorithm defines.

Related

source
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$, 1 when the active mask of the feature window marks the asset active and 0 otherwise.
  • $\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.

  1. Under LastRow, or when every asset is active at the last row, measure the last row.
  2. Under LastActiveRow otherwise, read the features of each asset at its last active row, giving zs, and measure the stack of zs.
  3. Under AggregateFeatures, resolve the weights with collapse_weights. Collapse each asset over its own active rows with active_collapse, giving Zc, and measure Zc.
  4. Under AggregateDistances, resolve the weights, and measure each row into Dt. Add each entry of Dt to D, and the weight of the row to the weight total S, only for a pair whose two assets are active at the row, with accumulate_active_pairs!.
  5. Then check that the weight total of each asset, on the diagonal of S, is not zero. Collect each pair with a zero total, giving E. Divide D by S, and give E to resolve_empty_pairs!.
  6. Under StackObservations, measure the whole stack, giving D. Measure each pair that shares fewer rows than the window again, with shared_stack_distance. Collect each pair with no shared row, giving E, and give E to resolve_empty_pairs!.

Arguments

  • de: Feature distance estimator.
  • win: The window, a NamedTuple of Z, dims, A and nx.

Validation

  • Under AggregateDistances, the weights of the active rows of each asset do not sum to zero. Raises an ArgumentError that names each other asset.
  • A pair with no shared active row takes the rule pair of the collapse. See empty_pair_distance!.

Returns

  • D::MatNum: Distance matrix assets x assets, in the units the distance algorithm defines.

Related

source
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

  1. For each pair (i, j) with m[i] and m[j], add wt * Dt[i, j] to D[i, j], and add wt to the weight total S[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

source
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

  1. Name the coordinates of the shared rows, t + (k - 1) T for each shared row t and each feature k, giving idx.
  2. Measure the two assets on idx with pair_distance, under the metric that stack_metric restricts to idx, giving d.
  3. Rescale d to every coordinate of the stack with stack_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

source
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.

  1. For a Tuple or a vector, compose the mask of each entry in turn.
  2. For an estimator that holds a distance estimator, such as a ClustersEstimator, forward to the estimator it holds.
  3. For a FeatureDistance with no producer, on returns data that holds a panel, take the mask of readable cells in the rows that the collapse reads, with entry_activity. Compose it with imsk through compose_readable_mask.
  4. In every other case, a producer and returns data with no panel included, return imsk unchanged.

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 a Tuple of estimators.
  • imsk: The Investable Mask of the prior, or nothing when every asset is investable.
  • rd: The returns result to use.

Validation

Returns

  • imsk::Option{BitVector}: The composed mask, or nothing when every asset stays.

Related

source
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

  1. If A is nothing, return imsk.
  2. Mark the assets that alg can read with feature_readable, giving keep. If imsk is not nothing, keep only the assets that imsk keeps too.
  3. Drop assets from keep with drop_empty_pairs!, under the rule of empty_pair_rule for alg.
  4. Check that keep keeps one asset at least.
  5. Return nothing when imsk is nothing and keep keeps every asset, and keep otherwise.

Arguments

  • alg: The collapse algorithm.
  • A: The mask of readable cells of the window, observations × assets, or nothing.
  • imsk: The Investable Mask of the prior, or nothing when every asset is investable.

Validation

Returns

  • imsk::Option{BitVector}: The composed mask, or nothing when every asset stays.

Related

source
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.

  1. If pnl is nothing, return nothing.
  2. Otherwise, resolve de.sel against pnl with select_fields. Return the mask that feature_window_mask gives for those columns.

Arguments

  • de: Feature distance estimator.
  • pnl: The Asset Panel of the returns data, or nothing.

Returns

  • A::Option{<:AbstractMatrix{Bool}}: The mask of readable cells in the rows that the collapse reads, or nothing.

Related

source
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

  1. Join the active mask of the panel with the cells of cols that hold data, from feature_data_cells, through readable_cells. This gives R.
  2. Name the rows that the collapse reads on R with readable_window_rows, giving rows.
  3. Cut R to rows with window_activity, giving A.

Arguments

  • alg: The collapse algorithm.
  • pnl: The Asset Panel.
  • cols: The resolved columns, from select_fields.

Returns

Related

source
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.

  1. If o is nothing, return amsk.
  2. If amsk is nothing, return o.
  3. Otherwise, return amsk .& o.

Arguments

  • amsk: The active mask of the panel, or nothing.
  • o: The mask of the cells that hold data, or nothing.

Returns

  • R: The mask of readable cells, or nothing when every cell is readable.

Related

source
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.

  1. Under LastActiveRow, with a matrix R of a time-varying panel, name the rows with last_active_rows on R.
  2. In every other case, a static panel and R === nothing included, name the rows with collapse_rows.

Arguments

  • alg: The collapse algorithm.
  • pnl: The Asset Panel.
  • R: The mask of readable cells, observations × assets on a time-varying panel, one entry per asset on a static panel, or nothing.

Returns

  • rows: A range of observations, or Colon(). It is the value of the rows keyword of feature_matrix.

Related

source
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.

  1. If A is nothing, every row is active, so return Colon().
  2. Otherwise, find the last true row of each asset, or nobs for an asset with none. The earliest of these rows is r0.
  3. Return r0:nobs.

Arguments

  • A: The mask, observations × assets, or nothing.

Returns

  • rows::Union{UnitRange{Int}, Colon}: The rows r0:nobs, or Colon().

Related

source
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

  1. If amsk is nothing, return nothing.
  2. Otherwise, check the size of amsk, and return amsk.

Arguments

  • amsk: The mask of the static Feature Matrix, 1 × assets, or nothing.
  • Z: Feature matrix, assets × features when dims = 1 and features × assets when dims = 2. It can also be a 3-D array of time-varying features, whose last axis is always the observation axis: assets × features × observations when dims = 1, and features × assets × observations when dims = 2.
  • dims: Dimension along which the computation runs.

Validation

  • size(amsk) == (1, assets), where dims names the asset axis of Z. Raises a DimensionMismatch.

Returns

  • A::Option{<:AbstractMatrix{Bool}}: amsk.

Related

source
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.

  1. Under AggregateDistances and StackObservations, return the pair field.
  2. 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, or nothing.

Related

source
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

  1. Find the kept assets, giving k.
  2. For each j of k, and then each i of k with i < j, return (i, j) when no row of A marks both assets active.
  3. 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, or nothing.

Related

source