Walk-forward selection: pick the best candidate on each training window and
trade it on the next test window.
targets holds one target series per candidate (an array of K columns, a
(T, K) NdArray, or one series), and market the engine's inputs, as in
engine(target, ...market). Folds start at t0 = train, train + test, ...
while t0 < T; fold i tests on [t0, min(t0 + test, T)) and trains on
[t0 - train, t0), or on [0, t0) with anchored. A window is scored as a
backtest of its own. NaN scores lose, ties go to the lowest column, and a
fold where every score is NaN stays flat with choice -1. The stitched target
(0 before the first test window) runs through the engine once, and stats
covers it from the first test window on.
carry is a per-step carry rate (funding, borrow), one value per row, with
the sign and timing BacktestCarry documents. With it, every candidate's
run and the stitched run pass through BacktestCarry (multiplier
carryMultiplier) before they are scored, marked with the engine's
markInput (the price for BacktestPriceTarget and
BacktestPortfolioTarget, the close for the OHLC engines, the trade price
for BacktestTradesTarget, the ask for BacktestL1Target), so output
and stats are after carry. An engine without markInput raises with
carry.
Portfolio engines (BacktestPortfolioTarget, BacktestPortfolioOHLCTarget)
take a [T, K, C] target, C candidates for K assets ([T, K] is one
candidate), and [T, K] prices. Each window is scored on the book, the pnl
summed across assets; target is [T, K], output[T, K, 4], and a
callable metric gets one candidate's [L, K, 4] window and returns one
number. carry is then [T, K]. A portfolio engine reads a NaN target as
"hold". When a test window changes the book (the first one, a switch of
candidate, or the first after a flat fold), a NaN on its first row is
restated as the new candidate's last finite target for that asset (0 when
it has none), so the window starts from that candidate's book; when the
same candidate continues, the held book carries over without a trade.
Mirrors Python's screamer.walk_forward.
Walk-forward selection: pick the best candidate on each training window and trade it on the next test window.
targetsholds one target series per candidate (an array of K columns, a (T, K)NdArray, or one series), andmarketthe engine's inputs, as inengine(target, ...market). Folds start att0 = train, train + test, ...whilet0 < T; fold i tests on[t0, min(t0 + test, T))and trains on[t0 - train, t0), or on[0, t0)withanchored. A window is scored as a backtest of its own. NaN scores lose, ties go to the lowest column, and a fold where every score is NaN stays flat with choice -1. The stitched target (0 before the first test window) runs through the engine once, andstatscovers it from the first test window on.carryis a per-step carry rate (funding, borrow), one value per row, with the sign and timingBacktestCarrydocuments. With it, every candidate's run and the stitched run pass throughBacktestCarry(multipliercarryMultiplier) before they are scored, marked with the engine'smarkInput(the price forBacktestPriceTargetandBacktestPortfolioTarget, the close for the OHLC engines, the trade price forBacktestTradesTarget, the ask forBacktestL1Target), sooutputandstatsare after carry. An engine withoutmarkInputraises withcarry.Portfolio engines (
BacktestPortfolioTarget,BacktestPortfolioOHLCTarget) take a[T, K, C]target, C candidates for K assets ([T, K]is one candidate), and[T, K]prices. Each window is scored on the book, the pnl summed across assets;targetis[T, K],output[T, K, 4], and a callable metric gets one candidate's[L, K, 4]window and returns one number.carryis then[T, K]. A portfolio engine reads a NaN target as "hold". When a test window changes the book (the first one, a switch of candidate, or the first after a flat fold), a NaN on its first row is restated as the new candidate's last finite target for that asset (0 when it has none), so the window starts from that candidate's book; when the same candidate continues, the held book carries over without a trade. Mirrors Python'sscreamer.walk_forward.