Returns result: private API

Types

PortfolioOptimisers.AbstractReturnsResultType
abstract type AbstractReturnsResult <: AbstractResult

Abstract supertype for all returns result types.

All concrete and/or types representing the result of returns calculations should be subtypes of AbstractReturnsResult.

The asset-selector contract

select_assets and fit_preprocessing dispatch on this supertype, so any subtype reaching an AbstractAssetSelector must carry nx and an observations × assets matrix X, plus a port_opt_view that replays a selected universe. ClusterGroups widens that to {nx, X, pnl}: it reads the Feature Matrix off the carrier's AssetPanel, because preselection runs before any prior exists and no other source is reachable.

Widening the contract rather than the Pr_RR bridge is deliberate — that alias's concreteness is load-bearing at nine routing sites. The cost is that the contract is implicit: it is satisfied by ReturnsResult and enforced by nothing. PredictionReturnsResult subtypes this supertype, but its X is a portfolio return vector rather than an asset matrix — the asset axis is already collapsed away — so it satisfies neither the old contract nor the widened one, and every entry point refuses it loudly rather than measuring the wrong axis.

Related

source
PortfolioOptimisers.Prices_RRType
const Prices_RR = Union{<:AbstractReturnsResult, <:AbstractPricesResult}

Union of the two data levels cross-validation folds can be computed on: returns-level (AbstractReturnsResult) and price-level (AbstractPricesResult) data.

Fold generation only needs an observation count (cv_nobs) and a timestamp vector (cv_timestamps), so Base.split and n_splits accept either level. Price-level splitting is what lets a Pipeline be cross-validated on its input rows, keeping stateful preprocessing inside the fold.

Related

source

Functions

PortfolioOptimisers.check_names_and_returns_matrixFunction
check_names_and_returns_matrix(
    names::Union{Nothing, AbstractVector{<:AbstractString}},
    mat::Union{Nothing, AbstractMatrix{<:Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar}}},
    names_sym::Symbol,
    mat_sym::Symbol
)

Validate that asset or factor names and their corresponding returns matrix are provided and consistent.

Arguments

  • names: Asset or factor names.
  • mat: Returns matrix.
  • names_sym: Symbolic name for the names argument displayed in error messages.
  • mat_sym: Symbolic name for the matrix argument displayed in error messages.

Validation

  • allunique(names), whenever names is not nothing.

  • If either names or mat is not nothing:

    • !isnothing(names) and !isnothing(mat).
    • !isempty(names) and !isempty(mat).
    • length(names) == size(mat, 2).

Returns

  • nothing.

Related

source
PortfolioOptimisers.assert_asset_panel_suppliedFunction
assert_asset_panel_supplied(pnl::AssetPanel) -> AssetPanel
assert_asset_panel_supplied(pnl::Nothing) -> Union{}

Assert that the data carrier a FeatureDistance read holds an AssetPanel, and return it.

The carrier's pnl is optional, so a carrier built without one reaches the kernel as nothing. This is the one place that turns it into a diagnostic, and it returns the panel so the caller reads one verb rather than a check and an access.

Algorithm

The method that Julia selects is the algorithm. A panel is returned; nothing raises.

Arguments

  • pnl: The carrier's Asset Panel, or nothing.

Validation

Returns

  • pnl::AssetPanel: The Asset Panel.

Related

source