WalkForward
PortfolioOptimisers.WalkForwardEstimator Type
abstract type WalkForwardEstimator <: SequentialCrossValidationEstimatorAbstract supertype for all walk-forward cross-validation estimators in PortfolioOptimisers.jl.
Walk-forward estimators split time series data into sequential training and testing windows, advancing the test window forward at each step. Subtypes implement index-based or date-based walk-forward schemes.
Related
sourcePortfolioOptimisers.WalkForwardResult Type
struct WalkForwardResult{__T_train_idx, __T_test_idx} <: SequentialCrossValidationResultResult type produced by WalkForwardEstimator subtypes after splitting time series data.
Stores the train and test index vectors for each fold of the walk-forward cross-validation.
Fields
train_idx: Vector of training index ranges for each fold.test_idx: Vector of testing index ranges for each fold.
Related
sourcePortfolioOptimisers.IndexWalkForward Type
struct IndexWalkForward{__T_train_size, __T_test_size, __T_purged_size, __T_expand_train, __T_reduce_test} <: WalkForwardEstimatorImplements index-based walk-forward cross-validation for time series, supporting purging and flexible train/test windowing.
Fields
train_size: Number of observations in each training set.test_size: Number of observations in each test set.purged_size: Number of observations to exclude from the end of each train set adjacent to a test set.expand_train: If true, training set always starts from the beginning; otherwise, uses a rolling window.reduce_test: If true, reduces the last test set to fit remaining data; otherwise, drops incomplete test sets.
Constructors
IndexWalkForward(
train_size::Integer,
test_size::Integer;
purged_size::Integer = 0,
expand_train::Bool = false,
reduce_test::Bool = false,
) -> IndexWalkForwardPositional and keyword arguments correspond to the struct's fields.
Validation
train_size,test_size, andpurged_sizemust be non-empty, non-negative, and finite.Ensures
train_size + purged_size < TwhereTis the total number of observations.
Examples
julia> IndexWalkForward(100, 20; purged_size = 5, expand_train = true, reduce_test = false)
IndexWalkForward
train_size ┼ Int64: 100
test_size ┼ Int64: 20
purged_size ┼ Int64: 5
expand_train ┼ Bool: true
reduce_test ┴ Bool: falseRelated
sourceBase.split Method
Base.split(iwf::IndexWalkForward, rd::ReturnsResult) -> WalkForwardResultSplit the returns data rd into sequential walk-forward folds using integer observation indices. Each fold advances the test window by test_size observations.
Arguments
iwf::IndexWalkForward: Index-based walk-forward cross-validation estimator.rd::ReturnsResult: Returns data to split.
Returns
WalkForwardResult: Result containing train and test index ranges for each fold.
Related
sourcePortfolioOptimisers.DateWalkForward Type
struct DateWalkForward{__T_train_size, __T_test_size, __T_period, __T_period_offset, __T_purged_size, __T_adjuster, __T_previous, __T_expand_train, __T_reduce_test} <: WalkForwardEstimatorImplements date-based walk-forward cross-validation for time series, supporting flexible windowing, purging, and custom date adjustment.
Fields
train_size: Number of periods or length of training window (integer or date period).test_size: Number of observations in each test set.period: Step size for each split.period_offset: Optional offset to shift the split dates.purged_size: Number of observations to exclude from the end of each train set adjacent to a test set.adjuster: Function or estimator to adjust the date range (e.g., for business days).previous: If true, allows test indices to use previous available date if exact match not found, else use the next available date.expand_train: If true, training set always starts from the beginning; otherwise, uses a rolling window.reduce_test: If true, reduces the last test set to fit remaining data; otherwise, drops incomplete test sets.
Constructors
DateWalkForward(
train_size::IntPeriodDateRange,
test_size::Integer;
period::DatesUnionPeriod = Dates.Day(1),
period_offset::Option{<:DatesUnionPeriod} = nothing,
purged_size::Integer = 0,
adjuster::DateAdjType = identity,
previous::Bool = false,
expand_train::Bool = false,
reduce_test::Bool = false,
) -> DateWalkForwardPositional and keyword arguments correspond to the struct's fields.
Validation
test_sizeandpurged_sizemust be non-empty, non-negative, and finite.If
train_sizeis an integer, it must be non-empty, non-negative, and finite.
Examples
julia> DateWalkForward(252, 21; period = Dates.Day(1), purged_size = 5, expand_train = true)
DateWalkForward
train_size ┼ Int64: 252
test_size ┼ Int64: 21
period ┼ Dates.Day: Dates.Day(1)
period_offset ┼ nothing
purged_size ┼ Int64: 5
adjuster ┼ typeof(identity): identity
previous ┼ Bool: false
expand_train ┼ Bool: true
reduce_test ┴ Bool: falseRelated
sourceBase.split Method
Base.split(dwf::DateWalkForward{<:Integer}, rd::ReturnsResult) -> WalkForwardResultSplit the returns data rd into sequential walk-forward folds using date-aligned indices, where train_size is specified as an integer number of date-range steps.
The timestamp vector rd.ts must not be nothing. Training and test windows are aligned to the period date range and advanced by test_size steps at a time.
Arguments
dwf::DateWalkForward{<:Integer}: Date-based walk-forward estimator with an integertrain_size.rd::ReturnsResult: Returns data containing the matrixXand timestamp vectorts.
Returns
WalkForwardResult: Result containing train and test index ranges for each fold.
Related
sourceBase.split Method
Base.split(dwf::DateWalkForward{<:Any}, rd::ReturnsResult) -> WalkForwardResultSplit the returns data rd into sequential walk-forward folds using date-aligned indices, where train_size is specified as a date Period (e.g., Dates.Month(6)).
The timestamp vector rd.ts must not be nothing. Training windows are defined by subtracting train_size from the split date, allowing calendar-based window lengths.
Arguments
dwf::DateWalkForward{<:Any}: Date-based walk-forward estimator with aPeriodtrain_size.rd::ReturnsResult: Returns data containing the matrixXand timestamp vectorts.
Returns
WalkForwardResult: Result containing train and test index ranges for each fold.
Related
sourcePortfolioOptimisers.n_splits Function
n_splits(cv, rd::ReturnsResult)
n_splits(cv)Return the number of cross-validation splits (folds) that would be produced by cv for the given returns data rd.
Arguments
cv: A cross-validation estimator or result (e.g.KFold,IndexWalkForward,DateWalkForward,CombinatorialCrossValidation,MultipleRandomised, or their corresponding result types).rd::ReturnsResult: Returns data used to determine the number of splits.
Returns
Integer: The number of folds.
Related
sourcen_splits(dwf::DateWalkForward{<:Integer}, rd::ReturnsResult) -> IntegerReturn the number of walk-forward folds that would be produced by dwf for the given returns data rd when the training window size is specified as an integer number of date-range steps.
Arguments
dwf::DateWalkForward{<:Integer}: Date-based walk-forward estimator with an integertrain_size.rd::ReturnsResult: Returns data containing a timestamp vectorts.
Returns
Integer: The number of folds.
Related
sourcen_splits(dwf::DateWalkForward{<:Any}, rd::ReturnsResult) -> IntegerReturn the number of walk-forward folds that would be produced by dwf for the given returns data rd when the training window size is specified as a date Period.
Arguments
dwf::DateWalkForward{<:Any}: Date-based walk-forward estimator with aPeriodtrain_size.rd::ReturnsResult: Returns data containing a timestamp vectorts.
Returns
Integer: The number of folds.
Related
sourcePortfolioOptimisers.n_splits Method
n_splits(dwf::DateWalkForward{<:Integer}, rd::ReturnsResult) -> IntegerReturn the number of walk-forward folds that would be produced by dwf for the given returns data rd when the training window size is specified as an integer number of date-range steps.
Arguments
dwf::DateWalkForward{<:Integer}: Date-based walk-forward estimator with an integertrain_size.rd::ReturnsResult: Returns data containing a timestamp vectorts.
Returns
Integer: The number of folds.
Related
sourcePortfolioOptimisers.n_splits Method
n_splits(dwf::DateWalkForward{<:Any}, rd::ReturnsResult) -> IntegerReturn the number of walk-forward folds that would be produced by dwf for the given returns data rd when the training window size is specified as a date Period.
Arguments
dwf::DateWalkForward{<:Any}: Date-based walk-forward estimator with aPeriodtrain_size.rd::ReturnsResult: Returns data containing a timestamp vectorts.
Returns
Integer: The number of folds.
Related
source