WalkForward
PortfolioOptimisers.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
PortfolioOptimisers.IndexWalkForward — Type
struct IndexWalkForward{__T_train_size, __T_test_size, __T_purged_size, __T_expand_train, __T_reduce_test, __T_wd, __T_pws, __T_fa, __T_store_weight_path, __T_strict} <: WalkForwardEstimatorImplements index-based walk-forward cross-validation for time series, supporting purging and flexible train/test windowing.
purged_size drops the last purged_size rows of each training window. This opens a gap of that many observations before the test window, and removes the training rows whose labels reach into the test period. The test windows do not move, so a purge costs training rows rather than test coverage.
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. An Online Scheme sets ittrue, because a fold cannot un-fold an observation.
reduce_test: Whether to allow the last test window to be smaller.
wd: Weight drift the fold's return series is read under, ornothingto read it at the target weights of the fold.
pws: Previous-weights source the fold loop threads into the next fold, ornothingto followwd: the target weights of the previous fold whenwdisnothing, and its drifted weights whenwdis set. The table ofAbstractPreviousWeightsSourcegives the four settings ofwdandpws.
fa: Fee amortisation algorithm the fold's realised series charges the two fixed fee terms on, ornothingto inherit the clock the fee itself states. It overridesFees.fafor that series alone, and it reaches the fit not at all.
store_weight_path: Iftrue, the fold stores the weight path it computed; iffalse, a reader rebuilds it on demand.
strict: Iftrue, a Held Gap raises anArgumentError; iffalse, it warns and the pair contributes zero. A Held Gap is an (observation, asset) pair at which the fold's weight is non-zero and the asset's return is missing, which is what a delisting inside a test window makes.
Constructors
IndexWalkForward( train_size::Integer, test_size::Integer; purged_size::Integer = 0, expand_train::Bool = false, reduce_test::Bool = false, wd::Option{<:AbstractWeightDrift} = nothing, pws::Option{<:AbstractPreviousWeightsSource} = nothing, fa::Option{<:AbstractFeeAmortisation} = nothing, store_weight_path::Bool = false, strict::Bool = false,) -> IndexWalkForwardPositional and keyword arguments correspond to the struct's fields.
Online form
The scheme refits every fold from its training window. Its online form, under which the fold loop warms one estimator up on the first training window and then folds each fold's new observations into it, is the Online Scheme OnlineIndexWalkForward builds: the same keywords minus expand_train, which it sets true, because a fold cannot un-fold an observation.
Weight drift and previous weights
Each switch is nothing by default. An unset pws follows wd, so wd alone gives a consistent pair of the series and the previous weights.
wd is the Weight Drift of the scheme. nothing reads a fold's return series as X * w net of fees, at the target weights of that fold. A SelfFinancingDrift reads the series as the wealth ratio of the drifted holdings instead. store_weight_path makes the fold store the weight path it computed, which a reader otherwise rebuilds on demand. strict decides what a Held Gap does: an asset that delists inside a test window carries a non-zero weight and a missing return, and the fold zeroes that pair and warns, or refuses with an ArgumentError under strict.
pws is the Previous-Weights Source. A TargetWeights threads the target weights of the previous fold into the next one. A DriftedWeights threads the weights held after the last observation of the previous fold instead, so a turnover, a tracking or a fee estimator measures the trades a fund places rather than the change in the decision. A fold enumeration of this scheme is a timeline, so the source has a previous fold to read.
nothing follows wd, through resolve_previous_weights_source: the target weights when wd is nothing, and the drifted weights when wd is set. If the series drifts, the fund holds the drifted weights at the end of the fold, so the next trade starts there. An explicit pws overrides the rule. wd with pws = TargetWeights() drifts the series and still measures the change in the decision, which separates the turnover of the decision from the turnover the fund executes. The table of AbstractPreviousWeightsSource gives the four settings of wd and pws.
Fee clock
fa is the clock the fold's realised series charges the two fixed fee terms on, and it overrides the fa of the fee itself. nothing inherits that fee's clock, which is the library's original behaviour. A FirstObservationFees charges the two terms on the first observation of the fold, and an AmortisedFees spreads them over the fold. The field reaches the fit not at all, so the optimiser keeps pricing the fee the way its own objective must.
Validation
train_sizeandpurged_sizemust be non-empty, non-negative, and finite.test_sizemust be non-empty, greater than zero, and finite.purged_size < train_size, because the purge is taken out of the training window.
The rule train_size < T, where T is the number of observations, belongs to the data rather than to the estimator, so Base.split checks it.
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: false wd ┼ nothing pws ┼ nothing fa ┼ nothing store_weight_path ┼ Bool: false strict ┴ Bool: falseRelated
cross_val_predictsearch_cross_validationWalkForwardEstimatorWalkForwardResultOnlineIndexWalkForwardn_splits
References
PortfolioOptimisers.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, __T_wd, __T_pws, __T_fa, __T_store_weight_path, __T_strict} <: WalkForwardEstimatorImplements date-based walk-forward cross-validation for time series, supporting flexible windowing, purging, and custom date adjustment.
purged_size drops the last purged_size rows of each training window. This opens a gap of that many observations before the test window, and removes the training rows whose labels reach into the test period. The test window itself is not shortened, so purged_size must be smaller than the training window.
A range of ZonedDateTime timestamps of TimeZones.jl steps by period under the rules of TimeZones.jl. A calendar period, such as Dates.Day(1) or Dates.Month(1), keeps the wall-clock time across a change to or from daylight saving time. A fixed period, such as Dates.Hour(24), adds an absolute duration, so the wall-clock time of the range moves by one hour at the change. Then each date of the range after the change is one hour away from its observation. For daily observations at noon, a range date falls at 13:00 after the change to daylight saving time, and previous = false maps it to the observation of the next day. Use a calendar period for zoned timestamps.
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: A date of the period grid that falls between two timestamps maps to the earlier timestamp iftrue, and to the later timestamp iffalse.
expand_train: Whether to expand the training window over time. An Online Scheme sets ittrue, because a fold cannot un-fold an observation.
reduce_test: Whether to allow the last test window to be smaller.
wd: Weight drift the fold's return series is read under, ornothingto read it at the target weights of the fold.
pws: Previous-weights source the fold loop threads into the next fold, ornothingto followwd: the target weights of the previous fold whenwdisnothing, and its drifted weights whenwdis set. The table ofAbstractPreviousWeightsSourcegives the four settings ofwdandpws.
fa: Fee amortisation algorithm the fold's realised series charges the two fixed fee terms on, ornothingto inherit the clock the fee itself states. It overridesFees.fafor that series alone, and it reaches the fit not at all.
store_weight_path: Iftrue, the fold stores the weight path it computed; iffalse, a reader rebuilds it on demand.
strict: Iftrue, a Held Gap raises anArgumentError; iffalse, it warns and the pair contributes zero. A Held Gap is an (observation, asset) pair at which the fold's weight is non-zero and the asset's return is missing, which is what a delisting inside a test window makes.
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, wd::Option{<:AbstractWeightDrift} = nothing, pws::Option{<:AbstractPreviousWeightsSource} = nothing, fa::Option{<:AbstractFeeAmortisation} = nothing, store_weight_path::Bool = false, strict::Bool = false,) -> DateWalkForwardPositional and keyword arguments correspond to the struct's fields.
Online form
The scheme refits every fold from its training window. Its online form, under which the fold loop warms one estimator up on the first training window and then folds each fold's new observations into it, is the Online Scheme OnlineDateWalkForward builds: the same keywords minus expand_train, which it sets true, because a fold cannot un-fold an observation.
Weight drift and previous weights
Each switch is nothing by default. An unset pws follows wd, so wd alone gives a consistent pair of the series and the previous weights.
wd is the Weight Drift of the scheme. nothing reads a fold's return series as X * w net of fees, at the target weights of that fold. A SelfFinancingDrift reads the series as the wealth ratio of the drifted holdings instead. store_weight_path makes the fold store the weight path it computed, which a reader otherwise rebuilds on demand. strict decides what a Held Gap does: an asset that delists inside a test window carries a non-zero weight and a missing return, and the fold zeroes that pair and warns, or refuses with an ArgumentError under strict.
pws is the Previous-Weights Source. A TargetWeights threads the target weights of the previous fold into the next one. A DriftedWeights threads the weights held after the last observation of the previous fold instead, so a turnover, a tracking or a fee estimator measures the trades a fund places rather than the change in the decision. A fold enumeration of this scheme is a timeline, so the source has a previous fold to read.
nothing follows wd, through resolve_previous_weights_source: the target weights when wd is nothing, and the drifted weights when wd is set. If the series drifts, the fund holds the drifted weights at the end of the fold, so the next trade starts there. An explicit pws overrides the rule. wd with pws = TargetWeights() drifts the series and still measures the change in the decision, which separates the turnover of the decision from the turnover the fund executes. The table of AbstractPreviousWeightsSource gives the four settings of wd and pws.
Fee clock
fa is the clock the fold's realised series charges the two fixed fee terms on, and it overrides the fa of the fee itself. nothing inherits that fee's clock, which is the library's original behaviour. A FirstObservationFees charges the two terms on the first observation of the fold, and an AmortisedFees spreads them over the fold. The field reaches the fit not at all, so the optimiser keeps pricing the fee the way its own objective must.
Validation
test_sizemust be non-empty, greater than zero, and finite.purged_sizemust be non-empty, non-negative, and finite.- If
train_sizeis an integer, it must be non-empty, greater than zero, and finite. A training window of zero dates holds no observation. - If
train_sizeis a period, it must be positive, throughassert_positive_period. A training window of a zero or a negative period holds no observation. periodmust be positive, throughassert_positive_period. A zero step gives no date range, and a negative step gives an empty one.Base.split(dwf::DateWalkForward, rd::Prices_RR)andn_splitsthrow anIsEmptyErrorif a fold of the data has a training window that is empty after the purge. They drop a fold whose test window holds no observation, which happens when many dates of the range map to one timestamp, for example the two days of a weekend under a dailyperiodover business-day data.
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: false wd ┼ nothing pws ┼ nothing fa ┼ nothing store_weight_path ┼ Bool: false strict ┴ Bool: falseRelated
cross_val_predictsearch_cross_validationWalkForwardEstimatorWalkForwardResultOnlineDateWalkForwardn_splits
References
PortfolioOptimisers.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. A subtype reaches a DateWalkForward through its adjuster field, whose type bound is DateAdjType. The default adjuster is identity, which keeps every date of the range.
Interfaces
To implement a new date adjuster, subtype DateAdjusterEstimator and make an instance callable as below.
Call
(a::MyDateAdjuster)(dates::AbstractVector{<:Dates.TimeType}) -> AbstractVector{<:Dates.TimeType}: The dates that the test windows of the split align to.
Arguments
a: The date adjuster.dates: The date rangeti:period:tf, from the first to the last timestamp of the data, with theperiodof theDateWalkForward. The callerwalk_forward_date_rangewidenstiandtfby theperiod_offsetbefore the call.
Returns
dates::AbstractVector{<:Dates.TimeType}: The adjusted dates. They must stay sorted in increasing order, becausedate_index_positionsreads them in order and stops at the first date after the last timestamp. The caller adds theperiod_offsetto each date after the call, and runs no other check.
Examples
A date adjuster that moves a date on a weekend to the next Monday.
julia> struct NextWeekday <: PortfolioOptimisers.DateAdjusterEstimator endjulia> function (::NextWeekday)(dates) return unique!([Dates.dayofweek(d) > 5 ? d + Dates.Day(8 - Dates.dayofweek(d)) : d for d in dates]) endjulia> NextWeekday()(Dates.Date(2024, 1, 5):Dates.Day(1):Dates.Date(2024, 1, 8))2-element Vector{Date}: 2024-01-05 2024-01-08julia> DateWalkForward(252, 21; adjuster = NextWeekday()).adjusterNextWeekday()Related
PortfolioOptimisers.HindsightSplit — Type
struct HindsightSplit{__T_start, __T_prefix, __T_wd, __T_pws, __T_fa, __T_store_weight_path, __T_strict} <: WalkForwardEstimatorA cross-validator whose training set contains its test row by design: fold t trains on the rows through t, or on row t alone, and tests on row t.
HindsightSplit is the Hindsight Comparator rule of log_wealth_regret taken per row. An estimator run through it with cross_val_predict reads the row it is scored on before it is scored on it, which no causal scheme may do and which this scheme does by declaration, so that the run yields the per-row comparators dynamic regret is stated against. Under prefix = true fold t trains on rows 1:t: MeanRisk under LogarithmicReturn and MaximumReturn, or BestConstantRebalancedPortfolio, is then be-the-leader, the best constant rebalanced portfolio over the rows through t played on row t. Under prefix = false fold t trains on row t alone: the top-1 ScoreSelector under RankRule(; best = 1) and MeanReturn(; flag = true) composed with EqualWeighted in a Pipeline is then the per-period minimiser, one-hot on the row's best asset, whose terminal wealth is $\prod_t \max_i x_{t,i}$ over the price relatives $x$. A $K$-switch comparator is any piecewise-constant path the caller builds. The test window is one row, and every row from start to the last is a fold, so the scheme's rows are those of an IndexWalkForward(start - 1, 1) over the same data, and the two prediction results share the timestamps the regret verb demands.
The scheme is a walk-forward in every other respect: its folds are a timeline, it carries the Weight Drift, the Previous-Weights Source, the Fee Clock and the two flags of IndexWalkForward, and fold_evaluation reads them. Its online form is OnlineHindsightSplit, the prefix split under which the training windows are nested and the loop steps; the row-alone split has none.
A fold can train on one row: every fold of the row-alone split does, and so does the first fold of the prefix split at start = 1. The corrected covariance of one row is NaN, so a JuMP estimator under the default EmpiricalPrior throws there, in the Posdef step of its MatrixProcessing. A comparator whose programme reads no covariance, such as MeanRisk under LogarithmicReturn and MaximumReturn, fits one row under a prior that takes the uncorrected covariance and skips that step, EmpiricalPrior(; ce = PortfolioOptimisersCovariance(; ce = Covariance(; ce = GeneralCovariance(; ce = StatsBase.SimpleCovariance())), mp = MatrixProcessing(; pdm = nothing))). The covariance of one row is then the zero matrix, and the log-optimal programme does not read it. BestConstantRebalancedPortfolio fits no prior and needs none of this.
Fields
start:start: First row scored. Every row from it to the last is a fold, so a scheme over the rows of anIndexWalkForward(train_size, 1)setsstart = train_size + 1.
prefix:prefix: Iftrue, foldttrains on rows1:t, the prefix through its test row; iffalse, on rowtalone.
wd: Weight drift the fold's return series is read under, ornothingto read it at the target weights of the fold.
pws: Previous-weights source the fold loop threads into the next fold, ornothingto followwd: the target weights of the previous fold whenwdisnothing, and its drifted weights whenwdis set. The table ofAbstractPreviousWeightsSourcegives the four settings ofwdandpws.
fa: Fee amortisation algorithm the fold's realised series charges the two fixed fee terms on, ornothingto inherit the clock the fee itself states. It overridesFees.fafor that series alone, and it reaches the fit not at all.
store_weight_path: Iftrue, the fold stores the weight path it computed; iffalse, a reader rebuilds it on demand.
strict: Iftrue, a Held Gap raises anArgumentError; iffalse, it warns and the pair contributes zero. A Held Gap is an (observation, asset) pair at which the fold's weight is non-zero and the asset's return is missing, which is what a delisting inside a test window makes.
Constructors
HindsightSplit(; start::Integer = 1, prefix::Bool = true, wd::Option{<:AbstractWeightDrift} = nothing, pws::Option{<:AbstractPreviousWeightsSource} = nothing, fa::Option{<:AbstractFeeAmortisation} = nothing, store_weight_path::Bool = false, strict::Bool = false,) -> HindsightSplitKeyword arguments correspond to the struct's fields.
Validation
start >= 1.
The rule start <= T, where T is the number of observations, belongs to the data rather than to the estimator, so Base.split checks it.
Examples
julia> HindsightSplit(; start = 21, prefix = false)HindsightSplit start ┼ Int64: 21 prefix ┼ Bool: false wd ┼ nothing pws ┼ nothing fa ┼ nothing store_weight_path ┼ Bool: false strict ┴ Bool: falseRelated
PortfolioOptimisers.OnlineIndexWalkForward — Function
OnlineIndexWalkForward(
train_size::Integer,
test_size::Integer;
purged_size::Integer = 0,
reduce_test::Bool = false,
wd::Option{<:AbstractWeightDrift} = nothing,
pws::Option{<:AbstractPreviousWeightsSource} = nothing,
fa::Option{<:AbstractFeeAmortisation} = nothing,
store_weight_path::Bool = false,
strict::Bool = false,
) -> Online{<:IndexWalkForward}Build the Online Scheme of an IndexWalkForward: the scheme wrapped in Online, under which the fold loop fits each fold by the online step instead of a refit.
The keywords are the scheme's, minus expand_train, which is set true: a fold cannot un-fold an observation, so an online run is expanding by construction, and the mismatch a rolling window would be cannot be written. A rolling window computed online is the estimator's to declare, through Online(pe; max_history = train_size - purged_size) on the prior. This constructor is the only way to build the wrapped scheme; Online(cv) by hand is refused with an error that names it.
Under the Online Scheme the loop takes its online arm, online_folds. It resolves every Online wrapper in the estimator through update_online_estimator, folds the first training window in with partial_fit!, and then, per fold, folds only the rows the training window has gained since the last fold and reads the estimator out through optimise(opt). The estimator is threaded from fold to fold, so fold i never re-reads the rows fold i - 1 read, and the run reaches the weights of the batch expanding-window scheme, IndexWalkForward(train_size, test_size; purged_size, expand_train = true), fold for fold.
The loop starts cold: an estimator carrying a partial-fit state at entry is refused with an error that names it, and a TimeDependent schedule on a field that carries a state — the prior, or the optimiser itself — is refused at warm-up, because a schedule replaces the value a state is threaded through. A schedule on any other field composes with no rule.
Examples
julia> OnlineIndexWalkForward(100, 20; purged_size = 5)Online est ┼ IndexWalkForward │ train_size ┼ Int64: 100 │ test_size ┼ Int64: 20 │ purged_size ┼ Int64: 5 │ expand_train ┼ Bool: true │ reduce_test ┼ Bool: false │ wd ┼ nothing │ pws ┼ nothing │ fa ┼ nothing │ store_weight_path ┼ Bool: false │ strict ┴ Bool: false max_history ┴ nothingRelated
PortfolioOptimisers.OnlineDateWalkForward — Function
OnlineDateWalkForward(
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,
reduce_test::Bool = false,
wd::Option{<:AbstractWeightDrift} = nothing,
pws::Option{<:AbstractPreviousWeightsSource} = nothing,
fa::Option{<:AbstractFeeAmortisation} = nothing,
store_weight_path::Bool = false,
strict::Bool = false,
) -> Online{<:DateWalkForward}Build the Online Scheme of a DateWalkForward: the scheme wrapped in Online, under which the fold loop fits each fold by the online step instead of a refit.
The keywords are the scheme's, minus expand_train, which is set true: a fold cannot un-fold an observation, so an online run is expanding by construction, and the mismatch a rolling window would be cannot be written. A rolling window computed online is the estimator's to declare, through Online(pe; max_history = …) on the prior, with the cap the window's rows count to. This constructor is the only way to build the wrapped scheme; Online(cv) by hand is refused with an error that names it. What the loop does under it is what OnlineIndexWalkForward describes, over the folds the date scheme cuts.
Examples
julia> OnlineDateWalkForward(252, 21; purged_size = 5)Online est ┼ 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: false │ wd ┼ nothing │ pws ┼ nothing │ fa ┼ nothing │ store_weight_path ┼ Bool: false │ strict ┴ Bool: false max_history ┴ nothingRelated
PortfolioOptimisers.OnlineHindsightSplit — Function
OnlineHindsightSplit(;
start::Integer = 1,
wd::Option{<:AbstractWeightDrift} = nothing,
pws::Option{<:AbstractPreviousWeightsSource} = nothing,
fa::Option{<:AbstractFeeAmortisation} = nothing,
store_weight_path::Bool = false,
strict::Bool = false,
) -> Online{<:HindsightSplit}Build the Online Scheme of a HindsightSplit: the prefix split wrapped in Online, under which the fold loop fits each fold by the online step instead of a refit.
The keywords are the scheme's, minus prefix, which is set true: fold t then trains on rows 1:t and tests on row t, and those training windows are nested prefixes, so the loop warms up on 1:start, folds row t, makes the call with no data, and scores row t, exactly as it does under OnlineIndexWalkForward. The row-alone split, prefix = false, is a window of one row that a fold cannot un-fold, so it has no online form and cannot be written here. The call with no data after rows 1:t equals the batch fit over 1:t, so the comparators this scheme yields are the batch ones fold for fold; the step is faster than the refit only where the estimator's batch fit is itself a row recursion, and a comparator whose step is a solve, or a fixed point over every row it holds, runs no faster.
Examples
julia> OnlineHindsightSplit(; start = 21)Online est ┼ HindsightSplit │ start ┼ Int64: 21 │ prefix ┼ Bool: true │ wd ┼ nothing │ pws ┼ nothing │ fa ┼ nothing │ store_weight_path ┼ Bool: false │ strict ┴ Bool: false max_history ┴ nothingRelated
Base.split — Method
Base.split(iwf::IndexWalkForward, rd::Prices_RR) -> 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: Returns-level or price-level data to split (Prices_RR).
Validation
train_size < T, whereTis the number of observations inrd.
Returns
WalkForwardResult: Result containing train and test index ranges for each fold.
Related
Base.split — Method
Base.split(dwf::DateWalkForward, rd::Prices_RR) -> WalkForwardResultSplit the returns data rd into sequential walk-forward folds using date-aligned indices.
The test windows are aligned to the period date range and advance by test_size dates at a time. An Integer train_size is a number of dates of the range. A Period train_size (e.g. Dates.Month(6)) is subtracted from the first date of each test window, which gives a calendar length to the training window. A fold whose test window holds no observation is dropped, which happens when many dates of the range map to one timestamp. date_walk_forward_bounds computes the folds.
Arguments
dwf::DateWalkForward: Date-based walk-forward estimator.rd: Returns-level or price-level data with timestamps (Prices_RR).
Validation
- The timestamp vector (
cv_timestamps) must not benothing. - Every fold must have a training window that is not empty after
expand_trainandpurged_size, else anIsEmptyErroris thrown. - The data must hold at least one fold, else
WalkForwardResultthrows anIsEmptyError.
Returns
WalkForwardResult: Result containing train and test index ranges for each fold.
Related
Base.split — Method
Base.split(hs::HindsightSplit, rd::Prices_RR) -> WalkForwardResultSplit the returns data rd into one fold per row from start to the last: fold t tests on row t and trains on rows 1:t under prefix = true, on row t alone otherwise.
Arguments
hs::HindsightSplit: Hindsight splitter.rd: Returns-level or price-level data to split (Prices_RR).
Validation
start <= T, whereTis the number of observations inrd.
Returns
WalkForwardResult: Result containing train and test index ranges for each fold.
Related
PortfolioOptimisers.n_splits — Function
n_splits(cv, rd::Prices_RR)
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: Returns-level or price-level data used to determine the number of splits (Prices_RR).
Validation
- For an
IndexWalkForward,train_size < T, whereTis the number of observations inrd. This is the ruleBase.splitchecks, so the count and the split agree on data too short to test.
Returns
Integer: The number of folds.
Related
n_splits(dwf::DateWalkForward, rd::Prices_RR) -> IntegerReturn the number of walk-forward folds that dwf produces for the returns data rd.
The count reads the same fold bounds as Base.split(dwf::DateWalkForward, rd::Prices_RR), so it equals the number of folds that split returns. It throws where a fold has an empty training window, as split does. Where the data holds no fold, it returns zero, and split throws an IsEmptyError.
Arguments
dwf::DateWalkForward: Date-based walk-forward estimator.rd: Returns-level or price-level data with timestamps (Prices_RR).
Returns
Integer: The number of folds.
Related
PortfolioOptimisers.n_splits — Method
n_splits(dwf::DateWalkForward, rd::Prices_RR) -> IntegerReturn the number of walk-forward folds that dwf produces for the returns data rd.
The count reads the same fold bounds as Base.split(dwf::DateWalkForward, rd::Prices_RR), so it equals the number of folds that split returns. It throws where a fold has an empty training window, as split does. Where the data holds no fold, it returns zero, and split throws an IsEmptyError.
Arguments
dwf::DateWalkForward: Date-based walk-forward estimator.rd: Returns-level or price-level data with timestamps (Prices_RR).
Returns
Integer: The number of folds.
Related
Base.split — Method
Base.split(o::Online{<:WalkForwardEstimator}, rd::Prices_RR) -> WalkForwardResult
n_splits(o::Online{<:WalkForwardEstimator}, rd::Prices_RR) -> Integer
fold_evaluation(o::Online{<:WalkForwardEstimator})
folds_are_stepped(o::Online{<:WalkForwardEstimator}) -> BoolThe scheme verbs of an Online Scheme.
The fold enumeration is the wrapped walk-forward's and does not change, and neither do its evaluation switches, so split, n_splits and fold_evaluation forward to o.est. What changes is how each fold is fitted, and folds_are_stepped is where the wrapped form answers true: the fold loop reads it off the type and takes its online arm.
Related
References
- [12]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
- [225]
- M. López de Prado. Advances in Financial Machine Learning (John Wiley & Sons, Hoboken, NJ, 2018).