Feature distance active rows

PortfolioOptimisers.feature_readable — Function
feature_readable(alg, A::AbstractMatrix{Bool}) -> BitVector

Mark the assets that a collapse can read in a window, from the active mask of the window.

Algorithm

The method that Julia selects is the algorithm.

  1. Under LastRow, an asset is readable when it is active at the last row.
  2. Under every other collapse, an asset is readable when it is active at one row of the window at least.

Arguments

  • alg: The collapse algorithm.
  • A: The active mask of the window, observations × assets.

Returns

  • r::BitVector: One entry per asset, true where the collapse can read the asset.

Related

source
PortfolioOptimisers.empty_pair_distance! — Function
empty_pair_distance!(D::MatNum, pair::AbstractEmptyPairAlgorithm, E, de::FeatureDistance, win)

Give the distance of each pair of assets in E, which share no active row, by the rule pair.

Algorithm

The method that Julia selects is the algorithm.

  1. Under RefusePair, refuse. Name each pair and the two other rules.
  2. Under DropFewerRows, refuse, because the rule drops an asset at the entry of a fit, and a direct call has none. Name each pair and the remedy.
  3. Under FeatureFallback, resolve the weights of the rule with collapse_weights. Collapse each asset over its own active rows with active_collapse, under the collapse and the weights of the rule, giving Zf.
  4. Then lay out the two rows of Zf of each pair as the collapse of de reads one asset, with fallback_features. Write their pair_distance to D[i, j] and D[j, i].

Arguments

  • D: The distance matrix, assets × assets, written in place at each pair of E.
  • 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.

Validation

Returns

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

Related

source
PortfolioOptimisers.drop_empty_pairs! — Function
drop_empty_pairs!(keep::BitVector, pair, A::AbstractMatrix{Bool}) -> BitVector

Drop, under DropFewerRows, one asset of each pair with no shared active row, until no pair of the kept assets is empty.

Each pass drops the asset with fewer active rows in the window from the first empty pair. On a tie it drops j, the asset that comes later in the universe. Every other rule keeps keep unchanged. RefusePair refuses in the kernel, and FeatureFallback measures the pair there.

Algorithm

The method that Julia selects is the algorithm.

  1. Under every rule but DropFewerRows, return keep.
  2. Under DropFewerRows, count the active rows of each asset in A, giving n.
  3. Find the first empty pair (i, j) of the kept assets with first_empty_pair, giving p.
  4. While p is not nothing, drop j from keep when n[j] <= n[i], and i otherwise. Then find the next empty pair.
  5. Return keep.

Arguments

  • keep: The assets kept so far, changed in place.
  • pair: The rule for an empty pair, or nothing for a collapse that reads no pair.
  • A: The active mask of the window, observations × assets.

Returns

  • keep::BitVector: The kept assets.

Related

source