Grid search cross validation
PortfolioOptimisers.GridSearchCrossValidation Type
struct GridSearchCrossValidation{__T_p, __T_cv, __T_r, __T_scorer, __T_ex, __T_train_score, __T_kwargs} <: AbstractSearchCrossValidationEstimatorPerforms grid search cross-validation for portfolio optimisation estimators. Iterates over parameter grids, applies cross-validation splits, and scores each configuration to select the optimal parameters.
Fields
p: Hyperparameter search grid.cv: Cross-validation estimator.r: Risk measure or vector of risk measures.scorer: Scoring function.ex: Parallel execution strategy.train_score: Whether to also compute the training set score.kwargs: Additional keyword arguments.
Constructors
GridSearchCrossValidation(
p::MultiGSCVValType_VecMultiGSCVValType;
cv::CrossValidationEstimator = KFold(),
r::AbstractBaseRiskMeasure = ConditionalValueatRisk(),
scorer::CrossValSearchScorer = HighestMeanScore(),
ex::FLoops.Transducers.Executor = FLoops.ThreadedEx(),
train_score::Bool = false,
kwargs::NamedTuple = (;),
) -> GridSearchCrossValidationPositional and keyword arguments correspond to fields above.
Validation
!isempty(p).If
pis a vector of parameter sets: each element must not be empty.All keys in
pmust be of typeGSCVKey(i.e.String,Symbol, orInteger).
Examples
julia> GridSearchCrossValidation(Dict("alpha" => [0.1, 0.2], "beta" => [1.0, 2.0]))
GridSearchCrossValidation
p ┼ Dict{String, Vector{Float64}}: Dict("alpha" => [0.1, 0.2], "beta" => [1.0, 2.0])
cv ┼ KFold
│ n ┼ Int64: 5
│ purged_size ┼ Int64: 0
│ embargo_size ┴ Int64: 0
r ┼ ConditionalValueatRisk
│ settings ┼ RiskMeasureSettings
│ │ scale ┼ Float64: 1.0
│ │ ub ┼ nothing
│ │ rke ┴ Bool: true
│ alpha ┼ Float64: 0.05
│ w ┴ nothing
scorer ┼ HighestMeanScore()
ex ┼ Transducers.ThreadedEx{@NamedTuple{}}: Transducers.ThreadedEx()
train_score ┼ Bool: false
kwargs ┴ @NamedTuple{}: NamedTuple()Related
PortfolioOptimisers.search_cross_validation Method
search_cross_validation(opt::NonFiniteAllocationOptimisationEstimator,
gscv::GridSearchCrossValidation,
rd::ReturnsResult)Performs grid search cross-validation for portfolio optimisation estimators. Iterates over parameter grids, applies cross-validation splits, fits and scores each configuration, and selects the optimal parameters using the provided scoring strategy.
Arguments
opt: Portfolio optimisation estimator to be tuned.gscv: Grid search cross-validation estimator specifying parameter grid, CV splitter, risk measure, scorer, execution strategy, and options.rd: Returns result containing asset returns data.
Returns
SearchCrossValidationResult: Result type containing the optimal estimator, test and train scores, parameter grid, and selected index.
Details
Iterates over all parameter combinations in the grid.
Applies cross-validation splits to the returns data.
Fits the estimator for each parameter set and split.
Scores each configuration using the specified risk measure and scoring function.
Selects the optimal parameter set based on cross-validation scores.
Returns a result object encapsulating the optimal estimator and score matrices.
Related
PortfolioOptimisers.search_cross_validation Method
search_cross_validation(opt::NonFiniteAllocationOptimisationEstimator,
gscv::GridSearchCrossValidation{<:Any, <:CombinatorialCrossValidation},
rd::ReturnsResult)Grid search cross-validation over a CombinatorialCrossValidation scheme.
Unlike the contiguous schemes (which score one fold per row), combinatorial cross-validation recombines its disjoint test groups into full-length backtest paths. Scoring a single split in isolation would mix groups belonging to different paths, so this method scores per-path instead: for each candidate the whole scheme is run through fit_and_predict (splits fitted, groups recombined by sort_predictions! into a PopulationPredictionResult), and expected_risk yields one score per path. The score matrix is therefore n_paths × n_candidates; the scorer selects across candidates exactly as for the other schemes. The randomised form delegates here through its grid.
train_scores (only when gscv.train_score) keeps every per-fold in-sample score rather than collapsing to one number per path: it is a Vector of n_paths matrices, one per path, each folds_in_path × n_candidates. (Test scores stay one-per-path because a path's out-of-sample returns pool into a single series, whereas its folds train on distinct in-sample windows.)
Related
sourcePortfolioOptimisers.lens_val_grid Method
lens_val_grid(estval)Build a grid of (lens, value) pairs from a parameter specification.
Converts the input vector of key => values pairs into a grid of Accessors.jl lens and value combinations for grid search cross-validation.
Arguments
estval: Vector ofString => AbstractVectorpairs mapping parameter key paths to their candidate values.
Returns
- Grid of (lens, value) combinations.
Related
source