Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-325

Walk-Forward Fold Count

Problem

Count how many non-overlapping walk-forward folds fit in a series of n observations, given an initial training size and a test horizon h. Each fold trains on the observations available so far and tests the next h points, so the count is (n - initial) // h.

Return 0 when h is not positive, when n is not positive, or when the initial size is negative or exceeds n.

Hint

Walk-forward evaluation uses every point exactly once as a test target.

Test cases

case 1
in: [10,4,2]
expected: 3
case 2
in: [10,5,1]
expected: 5
case 3
in: [5,5,2]
expected: 0
case 4
in: [10,4,0]
expected: 0
Starter codePython
def walk_forward_fold_count(n, initial, h):
    # Your code here
    pass

4 test cases · run your code against them in the editor