Base search cross validation

PortfolioOptimisers.HighestMeanScoreType
struct HighestMeanScore <: CrossValidationSearchScorer

A CrossValidationSearchScorer that selects the parameter set with the highest mean score across cross-validation splits.

When called with a score matrix (rows = CV splits, columns = parameter sets), it returns the column index with the largest mean score.

Examples

julia> scorer = PortfolioOptimisers.HighestMeanScore();julia> scores = [0.5 0.8; 0.6 0.7];julia> scorer(scores)2

Related

source
PortfolioOptimisers.SearchCrossValidationResultType
struct SearchCrossValidationResult{__T_opt, __T_test_scores, __T_train_scores, __T_lens_grid, __T_val_grid, __T_idx} <: AbstractSearchCrossValidationResult

Result type for search-based cross-validation routines. Stores the optimal estimator, score matrices, parameter grid, and selected index for hyperparameter search.

Fields

  • opt: Optimal estimator found by cross-validation.
  • test_scores: Test set scores.
  • train_scores: Training set scores.
  • lens_grid: Grid lengths for each parameter.
  • val_grid: Grid values for each parameter.
  • idx: Index of the optimal parameter configuration.

Related

source
PortfolioOptimisers.AbstractSearchCrossValidationResultType
abstract type AbstractSearchCrossValidationResult <: AbstractResult

Abstract result type for search-based cross-validation routines. Serves as the parent for all result types produced by search cross-validation algorithms, encapsulating optimal estimator, score matrices, parameter grid, and selected index.

Interfaces

  • Subtypes must store the optimal estimator, test and train scores, parameter grid, and selected index.
source
PortfolioOptimisers.CrossValidationSearchScorerType
abstract type CrossValidationSearchScorer <: AbstractEstimator

Defines the interface for scoring strategies used in search cross-validation. Implementations select the optimal parameter set based on cross-validation scores.

Interfaces

  • (::CrossValidationSearchScorer)(scores::AbstractMatrix): Returns the index of the optimal parameter set — the column with the best (highest) aggregate score.

Arguments

  • scores: Matrix of scores, where each column corresponds to a parameter set and each row to a cross-validation split. The matrix is orientation-normalised: risk-measure scores are negated so that higher is always better, whatever measure r is. A scorer therefore returns the index of the column with the best (highest) aggregate score.

Returns

  • Int: Index of the optimal parameter set, as a position in the matrix the scorer received.

A scorer never sees a failed candidate

finite_candidate_index hands the scorer the columns whose every entry is finite, and maps the index back to the parameter grid itself. A scorer therefore reads a matrix of finite numbers alone, and it may compute anything on it — a mean, a spread, a rank — without a candidate that failed a fold winning. The matrix a scorer receives is a view of the score matrix, and its column count can be smaller than the grid, so a scorer must return a position in that view and must not index the grid itself.

Examples

julia> struct MyScore <: PortfolioOptimisers.CrossValidationSearchScorer endjulia> (s::MyScore)(X::Matrix{Float64}) = argmax(dropdims(mean(X; dims = 1); dims = 1))julia> scores = [0.5 0.6; 0.7 0.8];julia> scorer = MyScore()MyScore()julia> scorer(scores)2

Related

source