Feature selector

A feature selector names the panel fields that a feature matrix stacks. feature_matrix, feature_labels and LabelGroup are documented with the feature distance that reads the matrix. This page documents the stack of every field of a panel, and the method that a new kind of panel field adds to it.

A static panel stacks to assets × features. A time-varying panel stacks to assets × features × observations, with the observations on the last axis, so the matrix of one observation is one contiguous block.

PortfolioOptimisers.panel_feature_matrix — Function
panel_feature_matrix(pnl::Union{Nothing, AssetPanel{Nothing}}) -> Tuple{Nothing, Nothing}
panel_feature_matrix(pnl::AssetPanel) -> Tuple{Vector{String}, Array}

Derive the Feature Matrix an AssetPanel's Panel Fields stack into, and name its columns.

Input data that holds no panel, or a panel with no Panel Field, derives nothing. So the first method answers with two nothing values, and no consumer needs a branch of its own.

Nothing stores the result. A distance measures a Feature Matrix, so the distance builds it and drops it after the measure. The panel is the data, and the matrix is one view of it.

The column order is the Panel Field order. Within one Panel Field, its value columns come first and its observed-mask columns after. A numeric or a categorical Panel Field has one observed-mask column, and a tensor Panel Field has one per label. A static panel gives an assets × features matrix, and a time-varying one an assets × features × observations matrix.

Algorithm

The method that Julia selects decides whether there is anything to derive.

  1. Walk the Panel Fields in order. Claim each one's value columns from panel_field_labels, then its observed-mask columns from panel_field_observed_labels when it carries a mask.
  2. Allocate the matrix as zeros, assets × features, or assets × features × observations over the panel's own observation axis, in the type panel_value_eltype derives over the Panel Fields.
  3. Write each Panel Field's values with panel_field_stack! and its mask with panel_field_stack_observed!.

Arguments

  • pnl: The Asset Panel.

Returns

  • nz::Vector{String}: One name per column of the derived Feature Matrix.
  • Z::Array: The derived Feature Matrix, in the type panel_value_eltype derives over the Panel Fields it stacks.

Related

source
PortfolioOptimisers.panel_field_stack! — Function
panel_field_stack!(Z::AbstractArray, f::NumericPanelField, cols::VecInt) -> nothing
panel_field_stack!(Z::AbstractArray, f::CategoricalPanelField, cols::VecInt) -> nothing
panel_field_stack!(Z::AbstractArray, f::TensorPanelField, cols::VecInt) -> nothing

Write one Panel Field's value columns into a derived Feature Matrix.

Z is allocated as zeros, which is what makes a one-hot column correct: the categorical method writes only the 1s.

Algorithm

The method that Julia selects is the algorithm.

  1. NumericPanelField: write the values into the single column.
  2. CategoricalPanelField: write a 1 into the column its code names, for each cell.
  3. TensorPanelField: write one label slice per column.

Arguments

  • Z: The derived Feature Matrix under construction.
  • f: The Panel Field.
  • cols: The columns the Panel Field claims, in order.

Returns

  • nothing.

Related

source

The private page documents the other names of this topic.