Base search cross validation
PortfolioOptimisers.SearchCV Type
const SearchCV = Union{<:KFold, <:KFoldResult, <:WalkForwardEstimator, <:WalkForwardResult}Cross-validations compatible with search-based hyperparameter tuning.
sourcePortfolioOptimisers.AbstractSearchCrossValidationEstimator Type
abstract type AbstractSearchCrossValidationEstimator <: AbstractEstimatorAbstract supertype for all search-based cross-validation estimators in PortfolioOptimisers.jl.
Subtypes implement hyperparameter search strategies (e.g. grid search, randomised search) that use cross-validation to select the best estimator configuration.
Related
sourcePortfolioOptimisers.CrossValidationSearchScorer Type
abstract type CrossValidationSearchScorer <: AbstractEstimatorDefines 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.
Arguments
scores: Matrix of scores, where each column corresponds to a parameter set and each row to a cross-validation split.
Returns
Int: Index of the optimal parameter set.
Examples
julia> struct MyScore <: PortfolioOptimisers.CrossValidationSearchScorer end
julia> (s::MyScore)(X::Matrix{Float64}) = argmin(dropdims(mean(X; dims = 1); dims = 1))
julia> scores = [0.5 0.6; 0.7 0.8];
julia> scorer = MyScore()
MyScore()
julia> scorer(scores)
1Related Types
sourcePortfolioOptimisers.CrossValSearchScorer Type
const CrossValSearchScorer = Union{<:CrossValidationSearchScorer, <:Function}Union type for search cross-validation scoring strategies. Accepts either a subtype of CrossValidationSearchScorer or a plain function that accepts a matrix and returns an integer.
PortfolioOptimisers.HighestMeanScore Type
struct HighestMeanScore <: CrossValidationSearchScorerA 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)
2Related
sourcePortfolioOptimisers.AbstractSearchCrossValidationResult Type
abstract type AbstractSearchCrossValidationResult <: AbstractResultAbstract 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.
PortfolioOptimisers.AbstractSearchCrossValidationAlgorithm Type
abstract type AbstractSearchCrossValidationAlgorithm <: AbstractAlgorithmAbstract supertype for all search-based cross-validation algorithm types.
Subtypes define the strategy used to select the best hyperparameter combination from the search results (e.g. selecting by highest mean score).
Related
sourcePortfolioOptimisers.SearchCrossValidationResult Type
struct SearchCrossValidationResult{__T_opt, __T_test_scores, __T_train_scores, __T_lens_grid, __T_val_grid, __T_idx} <: AbstractSearchCrossValidationResultResult 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 instance after search.test_scores: Matrix of test scores for each parameter set and CV split.train_scores: Matrix of training scores for each parameter set and CV split (ornothingif not recorded).lens_grid: Vector of lens objects for parameter access.val_grid: Vector of parameter values for each configuration.idx: Index of the selected optimal parameter set.
Examples
Related
PortfolioOptimisers.fit_and_score Function
fit_and_score(opt::NonFiniteAllocationOptimisationEstimator,
scv::AbstractSearchCrossValidationEstimator,
rd::ReturnsResult,
train_idx::VecInt,
test_idx::VecInt)Fits a portfolio optimisation estimator on training data, scores it on test and train splits, and returns the scores for search-based cross-validation routines.
Arguments
opt: Portfolio optimisation estimator to fit.scv: Search cross-validation estimator specifying risk measure and options.rd: Returns result containing asset returns data.train_idx: Indices for training split.test_idx: Indices for test split.
Returns
test_score::Number: Test score.train_score::Option{<:Number}: Train score.
Details
Fits the estimator on training data.
Predicts on test data using the fitted estimator.
Computes risk scores for test and train splits.
Applies sign convention based on risk measure direction.
Returns scores for use in search cross-validation.
Related
Examples
sourcePortfolioOptimisers.parse_lens Function
parse_lens(key::AbstractString)Parse a hyperparameter key string into an Accessors.jl lens.
Converts a dotted string path (e.g., "opt.pe.ce") into a composable lens for getting and setting nested fields of an estimator object.
Arguments
key: Dotted field path string.
Returns
- Composed Accessors.jl lens.
Related
sourcePortfolioOptimisers._expr_to_lens Function
_expr_to_lens(ex::Symbol)Convert a bare symbol into a PropertyLens for field access.
Base case for the lens-building recursion: a bare symbol maps directly to an Accessors.PropertyLens.
Arguments
ex::Symbol: A field name symbol.
Returns
Accessors.PropertyLensfor the symbol.
Related
sourcePortfolioOptimisers._eval_index Function
_eval_index(x)Evaluate a literal index node in the AST without runtime eval.
Converts integer, symbol, or vector expression AST nodes to concrete index values for use in Accessors.IndexLens.
Arguments
x::Integer: An integer index.x::Symbol: A symbolic index.ex::Expr: A vector expression (:vecthead).
Returns
- The evaluated index value.
Related
sourcePortfolioOptimisers._expr_to_lens_chain Function
_expr_to_lens_chain(ex)Convert a Julia expression to a chain of lens accessors.
Internal helper for parsing hyperparameter key strings into composable Accessors.jl lenses.
Arguments
ex: Julia expression representing a field access chain.
Returns
- Composed lens.
Related
source