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: Training set indices.test_idx: Test set indices.
Constructors
WalkForwardResult(; train_idx::VecVecInt, test_idx::VecVecInt) -> WalkForwardResultKeywords correspond to the struct's fields.
Validation
!isempty(train_idx)(sufficient data to cover training + testing periods).!isempty(test_idx)(sufficient data to cover training + testing periods).length(train_idx) == length(test_idx).
Related
sourcePortfolioOptimisers.WFCVER Type
const WFCVER = Union{<:WalkForwardEstimator, <:WalkForwardResult}Alias for a walk-forward cross-validation estimator or result.
Matches either a WalkForwardEstimator or a WalkForwardResult.
Related
sourcePortfolioOptimisers.DateAdjusterEstimator Type
abstract type DateAdjusterEstimator <: AbstractEstimatorAbstract supertype for date adjustment estimators in walk-forward cross-validation.
Subtypes implement specific strategies for adjusting dates used in walk-forward splits.
Related
sourcePortfolioOptimisers.DatesUnionPeriod Type
const DatesUnionPeriod = Union{<:Dates.Period, <:Dates.CompoundPeriod}Alias for a Dates period or compound period.
Used internally to accept either simple date periods (e.g., Dates.Month(1)) or compound periods (e.g., Dates.Month(1) + Dates.Day(1)) as date offsets in walk-forward cross-validation.
Related
sourcePortfolioOptimisers.DateAdjType Type
const DateAdjType = Union{<:Function, <:DateAdjusterEstimator}Alias for a date adjustment function or estimator.
Matches either a plain Function or a DateAdjusterEstimator for adjusting dates in walk-forward cross-validation.
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: Training window size.test_size: Test window size.purged_size: Number of observations to purge between train and test sets.expand_train: Whether to expand the training window over time.reduce_test: Whether to allow the last test window to be smaller.
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: Training window size.test_size: Test window size.period: Time period for date-based walk-forward cross-validation.period_offset: Offset applied to the walk-forward period.purged_size: Number of observations to purge between train and test sets.adjuster: Function for adjusting walk-forward dates.previous: Whether to include the previous period in the training window.expand_train: Whether to expand the training window over time.reduce_test: Whether to allow the last test window to be smaller.
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
sourcePortfolioOptimisers.special_div Method
special_div(a::Integer, b::Integer)Perform integer division with a special case for zero divisor.
Returns zero if b is zero, otherwise computes div(a, b). Used internally in walk-forward date calculations to avoid division by zero.
Arguments
a: Dividend.b: Divisor.
Returns
div(a, b)or zero ifb == 0.
Related
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
sourcePortfolioOptimisers.IntPeriodDateRange Type
const IntPeriodDateRange = Union{<:Integer, <:DatesUnionPeriod}Alias for an integer or date period used to specify window sizes.
Matches either a plain integer (number of observations) or a date period (DatesUnionPeriod) for walk-forward cross-validation splits.
Related
source