screamer.js
    Preparing search index...

    Function walkForward

    • 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.

      Parameters

      Returns WalkForwardResult