Skip to content
13

KFold

PortfolioOptimisers.KFold Type
julia
struct KFold{__T_n, __T_purged_size, __T_embargo_size} <: NonSequentialCrossValidationEstimator

Implements non-sequential k-fold cross-validation with optional purging and embargoing of training samples.

Fields

  • n: Number of folds to split the data into.

  • purged_size: Number of observations to exclude from the start/end of each train set adjacent to a test set.

  • embargo_size: Number of observations to exclude from the start of each train set after a test set.

Constructors

julia
KFold(;
    n::Integer = 5,
    purged_size::Integer = 0,
    embargo_size::Integer = 0,
) -> KFold

Keyword arguments correspond to the struct's fields.

Validation

  • n must be non-empty, greater than zero, and finite.

  • purged_size and embargo_size must be non-empty and finite.

Examples

julia
julia> KFold(; n = 5, purged_size = 7, embargo_size = 11)
KFold
             n ┼ Int64: 5
   purged_size ┼ Int64: 7
  embargo_size ┴ Int64: 11

Related

source
PortfolioOptimisers.KFoldResult Type
julia
struct KFoldResult{__T_train_idx, __T_test_idx} <: NonSequentialCrossValidationResult

Result type produced by KFold after splitting data into training and testing folds.

Stores the train and test index vectors for each fold.

Fields

  • train_idx: Vector of training index ranges for each fold.

  • test_idx: Vector of testing index ranges for each fold.

Related

source
Base.split Method
julia
Base.split(kf::KFold, rd::ReturnsResult) -> KFoldResult

Split the returns data rd into n non-overlapping folds using k-fold cross-validation with optional purging and embargoing.

Arguments

  • kf::KFold: K-fold cross-validation estimator.

  • rd::ReturnsResult: Returns data to split.

Returns

  • KFoldResult: Result containing train and test indices for each fold.

Related

source