Randomised search cross validation

PortfolioOptimisers.RandomisedSearchCrossValidationType
struct RandomisedSearchCrossValidation{__T_p, __T_cv, __T_r, __T_scorer, __T_ex, __T_n_iter, __T_rng, __T_seed, __T_train_score, __T_kwargs} <: AbstractSearchCrossValidationEstimator

Randomised search cross-validation estimator for portfolio optimisation. Samples parameter sets from distributions or vectors, applies cross-validation splits, fits and scores each configuration, and selects the optimal parameters using the provided scoring strategy.

Fields

  • p: Hyperparameter search grid.
  • cv: Cross-validation estimator.
  • r: Risk measure or vector of risk measures.
  • scorer: Scoring function. Given the orientation-normalised score matrix (rows = CV splits, columns = parameter sets), it returns the column index of the best parameter set. The matrix is normalised so that higher is always better, whatever the risk measure, so a scorer selects the largest aggregate score (see CrossValidationSearchScorer).
  • ex: Parallel execution strategy.
  • n_iter: Number of random iterations.
  • rng: Random number generator.
  • seed: Seed for the random number generator.
  • train_score: Whether to also compute the training set score.
  • kwargs: Additional keyword arguments.

Constructors

RandomisedSearchCrossValidation(    p::Union{AbstractVector{<:Pair{<:GSCVKey, <:RSCVVal}},             AbstractVector{<:AbstractVector{<:Pair{<:GSCVKey,                                                    <:RSCVVal}}},             AbstractDict{<:GSCVKey, <:RSCVVal},             AbstractVector{<:AbstractDict{<:GSCVKey,                                           <:RSCVVal}}};    cv::CrossValidationEstimator = KFold(),    r::AbstractBaseRiskMeasure = ConditionalValueatRisk(),    scorer::CrossValSearchScorer = HighestMeanScore(),    ex::FLoops.Transducers.Executor = FLoops.ThreadedEx(),    n_iter::Integer = 10,    rng::Random.AbstractRNG = Random.default_rng(),    seed::Option{<:Integer} = nothing,    train_score::Bool = false,    kwargs::NamedTuple = (;),) -> RandomisedSearchCrossValidation

Positional and keyword arguments correspond to the struct's fields.

Validation

  • !isempty(p).
  • If p is a vector of parameter sets: each element must not be empty.
  • All keys in p must be of type GSCVKey (i.e. String, Symbol, or Integer).
  • All values in p must be of type RSCVVal (i.e. an AbstractVector or Distributions.Distribution).
  • n_iter > 0 and finite.

Examples

julia> RandomisedSearchCrossValidation(Dict("alpha" => [0.1, 0.2, 0.3],                                            "beta" => Normal(1.0, 0.5)))RandomisedSearchCrossValidation            p ┼ Dict{String, Any}: Dict{String, Any}("alpha" => [0.1, 0.2, 0.3], "beta" => Distributions.Normal{Float64}(μ=1.0, σ=0.5))           cv ┼ KFold              │                   n ┼ Int64: 5              │         purged_size ┼ Int64: 0              │        embargo_size ┼ Int64: 0              │                  wd ┼ nothing              │                  fa ┼ nothing              │   store_weight_path ┼ Bool: false              │              strict ┴ Bool: false            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()       n_iter ┼ Int64: 10          rng ┼ Random.TaskLocalRNG: Random.TaskLocalRNG()         seed ┼ nothing  train_score ┼ Bool: false       kwargs ┴ @NamedTuple{}: NamedTuple()

Related

References

  • [119] J. Bergstra and Y. Bengio. Random search for hyper-parameter optimization. Journal of Machine Learning Research 13, 281–305 (2012).
source
PortfolioOptimisers.search_cross_validationMethod
search_cross_validation(opt::NonFiniteAllocationOptimisationEstimator,
                       rscv::RandomisedSearchCrossValidation,
                       rd::ReturnsResult)

Performs randomised search cross-validation for portfolio optimisation estimators. Samples parameter sets from distributions or vectors, 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.
  • rscv: Randomised search cross-validation estimator specifying parameter grid, CV splitter, risk measure, scorer, execution strategy, number of iterations, RNG, 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

  • Samples parameter sets from vectors or distributions.
  • Applies cross-validation splits to the returns data.
  • Fits the estimator for each sampled 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

source

References

[119]
J. Bergstra and Y. Bengio. Random search for hyper-parameter optimization. Journal of Machine Learning Research 13, 281–305 (2012).