WalkForward: private API

PortfolioOptimisers.AbstractFoldFitType
abstract type AbstractFoldFit <: AbstractAlgorithm

Abstract supertype of the Fold Fit selectors: how the fold loop fits each fold of a walk-forward.

A walk-forward carries one in its ff field, read by fold_fit, beside its other execution switches. nothing refits every fold from its training window, which is the released behaviour; a member selects another fit. The family is a selector-tag family like AbstractWeightDrift: a member carries no data, and a caller's own subtype extends the loop through a method of its own.

Related

source
PortfolioOptimisers.DatesUnionPeriodType
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

source
PortfolioOptimisers.special_divMethod
special_div(a::Integer, b::Integer)

Return the number of steps of size b that fit in the span 1:a.

The result is the largest k for which 1 + k * b <= a, which is div(a - 1, b) for a positive a. A walk-forward fold count uses it this way: the first window starts at the first position of the span and every later window starts b positions after the previous one, so the number of windows is special_div(a, b) + 1. The caller passes the length of the span, not the difference between its last and its first position. b must not be zero.

Arguments

  • a: Length of the span of positions at which a window may start.
  • b: Step between two window starts.

Returns

  • Integer: The number of steps after the first window, div(a - 1, b).

Related

source
PortfolioOptimisers.walk_forward_date_rangeFunction
walk_forward_date_range(ts::AbstractVector, period::DatesUnionPeriod,
                        period_offset::Option{<:DatesUnionPeriod}, adjuster::DateAdjType)

Build the date range that a DateWalkForward estimator walks over the timestamps ts.

The range runs from the first to the last timestamp with a step of period. If period_offset is not nothing, the start moves to min(ts[1], ts[1] - period_offset), the adjuster is applied, and the offset is added to every date. This shifts each date by the offset without losing the start of ts.

Arguments

  • ts: Sorted timestamp vector (cv_timestamps).
  • period: Step of the date range.
  • period_offset: Offset applied to every date of the range, or nothing.
  • adjuster: Function applied to the unshifted range, e.g. a business-day adjuster.

Returns

Related

source
PortfolioOptimisers.date_index_positionsFunction
date_index_positions(ts::AbstractVector, date_range, previous::Bool,
                     ::Type{T} = Int) where {T <: Integer}

Map every date of date_range to a position in the sorted timestamp vector ts.

A date that falls between two timestamps maps to the previous timestamp if previous is true, and to the next timestamp if previous is false. A date before ts[1] maps to the first timestamp. The mapping stops at the first date that falls after ts[end], so the result is not longer than date_range.

Arguments

  • ts: Sorted timestamp vector (cv_timestamps).
  • date_range: Date range from walk_forward_date_range.
  • previous: If true, a date between two timestamps takes the previous timestamp.
  • T: Element type of the returned vector.

Returns

  • Vector{T}: Positions in ts, in the order of date_range.

Related

source
PortfolioOptimisers.resolve_expand_trainFunction
resolve_expand_train(expand_train::Option{Bool}, ff::Option{<:AbstractFoldFit})

Derive a walk-forward's expand_train from its Fold Fit when the keyword is left unset.

nothing resolves to true under a Fold Fit and to false without one, because a Fold Fit steps rows into one estimator and cannot un-fold an observation, so an online run is expanding by construction; a bare call therefore resolves to the released false. An explicit value is returned as it is, and the inner constructor refuses the one that contradicts the switch through assert_fold_fit_expands.

Related

source
PortfolioOptimisers.assert_fold_fit_expandsFunction
assert_fold_fit_expands(expand_train::Bool, ff::Option{<:AbstractFoldFit}, window::Option{<:Integer})

Refuse expand_train = false beside a Fold Fit, by name.

A Fold Fit cannot un-fold an observation, so the loop's window only ever grows and a rolling window is not the loop's to give. The message points at the composition that gives one: Online(pe; max_history = window) caps the prior's buffer, and the read-out is a batch fit over the window. window is train_size - purged_size for an index scheme, which names the cap outright, and nothing for a date scheme, whose window is counted in periods rather than rows.

Related

source