Skip to content
13

Multiple Randomised Cross Validation

PortfolioOptimisers.SubsetSizeEstimator Type
julia
abstract type SubsetSizeEstimator <: AbstractEstimator

Abstract supertype for estimators that determine the size of each asset subset.

Related

source
PortfolioOptimisers.NumberSubsetsEstimator Type
julia
abstract type NumberSubsetsEstimator <: AbstractEstimator

Abstract supertype for estimators that determine the number of random subsets to draw.

Related

source
PortfolioOptimisers.WindowSizeEstimator Type
julia
abstract type WindowSizeEstimator <: AbstractEstimator

Abstract supertype for estimators that determine the rolling window size.

Related

source
PortfolioOptimisers.SubsetSizeEC Type
julia
const SubsetSizeEC

Union of SubsetSizeEstimator subtypes and plain functions that compute a subset size from a returns dataset.

source
PortfolioOptimisers.NumberSubsetsEC Type
julia
const NumberSubsetsEC

Union of NumberSubsetsEstimator subtypes and plain functions that compute the number of subsets from a returns dataset.

source
PortfolioOptimisers.WindowSizeEC Type
julia
const WindowSizeEC

Union of WindowSizeEstimator subtypes and plain functions that compute a window size from a returns dataset.

source
PortfolioOptimisers.SubsetSizeE Type
julia
const SubsetSizeE

Union of a concrete subset-size value or an estimator/function for it.

source
PortfolioOptimisers.NumberSubsetsE Type
julia
const NumberSubsetsE

Union of a concrete number-of-subsets value or an estimator/function for it.

source
PortfolioOptimisers.WindowSizeE Type
julia
const WindowSizeE

Union of a concrete window-size value or an estimator/function for it.

source
PortfolioOptimisers.MultipleRandomised Type
julia
struct MultipleRandomised{__T_cv, __T_subset_size, __T_n_subsets, __T_max_comb, __T_window_size, __T_rng, __T_seed} <: NonOptimisationSequentialCrossValidationEstimator

Cross-validation scheme that draws multiple random asset subsets and applies a walk-forward estimator to each. Each combination of a random asset subset and a set of walk-forward folds forms one path.

Fields

  • cv: Cross-validation estimator.

  • subset_size: Size of each random subset.

  • n_subsets: Number of random subsets.

  • max_comb: Maximum number of unique asset subsets.

  • window_size: Rolling window size for randomised cross-validation.

  • rng: Random number generator.

  • seed: Seed for the random number generator.

Constructors

julia
MultipleRandomised(
    cv::WalkForwardEstimator;
    subset_size::SubsetSizeE = 1,
    n_subsets::NumberSubsetsE = 2,
    max_comb::Integer = 1_000_000_000,
    window_size::Option{<:WindowSizeE} = nothing,
    rng::Random.AbstractRNG = Random.default_rng(),
    seed::Option{<:Integer} = nothing
) -> MultipleRandomised

cv is positional; remaining arguments are keyword and correspond to the struct's fields.

Validation

  • If subset_size is an Integer: subset_size >= 1.

  • If subset_size is a float: 0 < subset_size < 1.

  • If n_subsets is an Integer: n_subsets >= 2.

  • max_comb > 0 and finite.

  • If window_size is an Integer: window_size >= 2.

  • If window_size is a float: 0 < window_size < 1.

Related

source
PortfolioOptimisers.MultipleRandomisedResult Type
julia
struct MultipleRandomisedResult{__T_train_idx, __T_test_idx, __T_asset_idx, __T_path_ids} <: NonOptimisationSequentialCrossValidationResult

Stores the split result produced by MultipleRandomised. Contains the training, test, and asset index sets for every fold across all random paths, along with a path identifier for each fold.

Fields

  • train_idx: Training set indices.

  • test_idx: Test set indices.

  • asset_idx: Asset column indices per fold.

  • path_ids: Path identifiers for cross-validation splits.

Constructors

julia
MultipleRandomisedResult(;
    train_idx::VecVecInt,
    test_idx::VecVecInt,
    asset_idx::VecVecInt,
    path_ids::VecInt
) -> MultipleRandomisedResult

Keywords correspond to the struct's fields.

Validation

  • !isempty(train_idx).

  • !isempty(test_idx).

  • !isempty(asset_idx).

  • !isempty(path_ids).

  • length(train_idx) == length(test_idx) == length(asset_idx) == length(path_ids).

Related

source
PortfolioOptimisers.MRCVR Type
julia
const MRCVR = Union{<:MultipleRandomised, <:MultipleRandomisedResult}

Alias for a multiple-randomised cross-validation estimator or result.

Matches either a MultipleRandomised estimator or a MultipleRandomisedResult.

Related

source
Base.split Method
julia
Base.split(mrcv::MultipleRandomised, rd::ReturnsResult) -> MultipleRandomisedResult

Split the returns data rd by drawing multiple random asset subsets and applying the internal walk-forward estimator to each subset. Each combination of a random asset subset and a set of walk-forward folds forms one path.

Arguments

  • mrcv::MultipleRandomised: Multiple randomised cross-validation estimator.

  • rd::ReturnsResult: Returns data to split.

Returns

  • MultipleRandomisedResult: Result containing training, test, and asset indices for every fold across all random paths, together with a path identifier for each fold.

Related

source
PortfolioOptimisers.path_fit_and_predict Function
julia
path_fit_and_predict(opt, rd, train_idx, test_idx, cols; ex, id)

Fit and predict along a sequence of (train, test, asset) triples, respecting sequential constraints.

Handles sequential and parallel execution. If the optimiser requires previous weights or is time-dependent, runs sequentially and passes weights/state between periods. Otherwise, runs in parallel using the provided executor.

Arguments

  • opt::NonFiniteAllocationOptimisationEstimator: Portfolio optimisation estimator.

  • rd::ReturnsResult: Full returns data.

  • train_idx: Sequence of training index vectors.

  • test_idx: Sequence of test index vectors.

  • cols: Sequence of asset column indices for each fold.

  • ex::FLoops.Transducers.Executor: Executor for parallel processing.

  • id: Optional path identifier.

Returns

Related

source
PortfolioOptimisers.combination_by_index Function
julia
combination_by_index(idx::Integer, N::Integer, k::Integer) -> VecInt

Return the idx-th combination of k items from N total items.

Internal helper for combinatorial path generation. Converts a lexicographic combination index to the actual combination elements.

Arguments

  • idx: Combination index (1-based).

  • N: Total number of items.

  • k: Number of items in each combination.

Returns

  • Vector of k item indices.

Related

source
PortfolioOptimisers.get_window_size Function
julia
get_window_size(window_size, rd, args...)

Get the actual rolling window size for multiple-randomised cross-validation.

Resolves the window size from nothing (no windowing), an integer (direct count), a float (fraction of observations), or a callable.

Arguments

  • window_size: Window size specification (nothing, integer, float, or callable).

  • rd: Returns result or prior.

  • args...: Additional arguments.

Returns

  • Integer window size or nothing.

Related

source
PortfolioOptimisers.get_n_subsets Function
julia
get_n_subsets(n_subsets, args...)

Get the number of asset subsets for multiple-randomised cross-validation.

Resolves the number of subsets from either an integer (direct count) or a callable that computes it from the returns data.

Arguments

  • n_subsets: Integer or callable number-of-subsets specification.

  • args...: Additional arguments (returns result or prior).

Returns

  • Integer number of subsets.

Related

source
PortfolioOptimisers.sample_unique_assets Function
julia
sample_unique_assets(N, k, n_subsets; kwargs...)

Sample n_subsets unique asset subsets of size k from N assets.

Internal function used in multiple-randomised cross-validation to generate diverse asset subsets for resampling.

Arguments

  • N: Total number of assets.

  • k: Subset size.

  • n_subsets: Number of unique subsets to sample.

  • kwargs...: Additional keyword arguments (e.g., random seed).

Returns

  • Matrix of size (k, n_subsets) with asset indices.

Related

source
PortfolioOptimisers.get_subset_size Function
julia
get_subset_size(subset_size, rd, args...)

Get the actual asset subset size for multiple-randomised cross-validation.

Resolves the subset size from either an integer (direct count) or a fraction of the total assets.

Arguments

  • subset_size: Integer or float subset size specification.

  • rd: Returns result or prior.

  • args...: Additional arguments.

Returns

  • Integer subset size.

Related

source