Carrier views: private API
PortfolioOptimisers.feature_row_indices — Function
feature_row_indices(pnl::Nothing, ts_new, ts_old) -> Colon
feature_row_indices(pnl::AssetPanel, ts_new, ts_old) -> Union{Colon, VecInt}Recover the positional row indices of a time-varying AssetPanel from a timestamp window.
A Panel Field holds a plain array, so its observation axis is parallel to the carrier's clock positionally rather than aligned by timestamp. Whenever a routine selects rows of X by timestamp, the surviving timestamps are matched back into the original clock to recover the rows the panel must keep. A surviving timestamp absent from that clock throws: it means the row bookkeeping has been broken (a synthesised timestamp, or an outer join that introduced a row X never had), and slicing the panel positionally from there would silently pair each asset with another period's values.
Two sites use it. At price level the clock is TimeSeries.timestamp(X) and the selection is a timestamp window. At the cross-validation assembly seam the clock is ReturnsResult.ts and the selection is a fold: fold_row_indices recovers a fold's rows from the timestamps its view of the returns already carries, which is why ts must be unique — it keys the observation axis rather than merely labelling it.
The static and absent shapes have no observation axis, so they return Colon and cost nothing.
Algorithm
The method that Julia selects is the algorithm.
pnlisnothing, or static: returnColon(). Neither has an observation axis, so there is no row to recover and the timestamps are not read.pnlis time-varying: matchts_newintots_oldwithmatched_row_indices, which throws when the selection kept no timestamp, or when a surviving timestamp is absent from the original clock.
Arguments
pnl: The Asset Panel, ornothing.ts_new: Timestamps surviving the selection.ts_old: Timestamps of the clock the panel's observation axis is parallel to.
Validation
ts_newis notnothingwhen the panel is time-varying.- Every entry of
ts_newappears ints_old.
Returns
Colonfor a static or absent panel; otherwise the row indices, as aVector{Int}.
Related
PortfolioOptimisers.matched_row_indices — Function
matched_row_indices(ts_new::Nothing, ts_old) -> Union{}
matched_row_indices(ts_new, ts_old) -> Vector{Int}Match the surviving timestamps back into the original clock, and return the rows they hold.
The body feature_row_indices shares between the time-varying feature matrix and the time-varying AssetPanel: both hold their observation axis parallel to the carrier's clock positionally, so both recover their rows the same way.
Algorithm
The method that Julia selects is the algorithm.
ts_newisnothing: throw. The selection kept no timestamp, so the rows to keep cannot be named.- Otherwise match
ts_newintots_oldwithindexin, check that every surviving timestamp was found, and return the positions as aVector{Int}.
Arguments
ts_new: Timestamps that survived the selection.ts_old: Timestamps of the clock the observation axis is parallel to.
Validation
ts_newis notnothing. Raises anArgumentError.- Every entry of
ts_newappears ints_old. Raises anArgumentError.
Returns
rows::Vector{Int}: The position each surviving timestamp holds in the original clock.
Related
PortfolioOptimisers.panel_feature_names — Function
panel_feature_names(pnl::Nothing) -> nothing
panel_feature_names(pnl::AssetPanel) -> Vector{String}Name the columns an AssetPanel derives, without building the Feature Matrix.
A consumer that needs the column names alone reads them here, and the values are not stacked to answer it.
Algorithm
The method that Julia selects is the algorithm.
pnlisnothing: returnnothing.pnlis anAssetPanel: walk its Panel Fields, appending each one's value column names and then its observed-mask column names.
Arguments
pnl: The Asset Panel, ornothing.
Returns
nz::Option{Vector{String}}: One name per derived column, ornothing.
Related
PortfolioOptimisers.panel_carrier_view — Function
panel_carrier_view(pnl::Nothing, i, j, nx) -> nothing
panel_carrier_view(pnl::AssetPanel, i, j, nx) -> AssetPanelView a carrier's AssetPanel, or return nothing when the carrier holds none.
The one-line wrapper every carrier view goes through, so the nothing case is written once rather than at each of the six sites that slice a panel.
Algorithm
The method that Julia selects is the algorithm.
pnlisnothing: returnnothing.pnlis anAssetPanel: returnport_opt_viewof it.
Arguments
pnl: The Asset Panel, ornothing.i: Observation index.j: Asset index.nx: The asset names, ornothing, handed toport_opt_viewso that a tensor Panel Field whose labels are the asset names is cut on its label axis too.
Returns
- An Asset Panel over the selected observations and assets, or
nothing.
Related