Skip to content

Numerically-stable O(1) BufferList reformulations + IsApproximately test helper #2159

Description

@DaveSkender

Background

PV001 (shipped) found that the naive four-sum identity (Σy² − (Σy)²/n) for Slope.BufferList suffers catastrophic cancellation on stock-price-like inputs and fails the IsExactly bit-equality contract, so Slope.BufferList stays at its current ~3.41x deviation-form ratio for v3.0. These are the follow-up paths.

Sub-items

  • Welford/Pébay sliding-window O(1) Slope variant — numerically-stable sliding-window updates via Welford running mean + Pébay M2 deltas avoid the cancellation and may bit-match Series. Prototype against Slope.BufferList test suite; ship only if .IsExactly(series) holds.
  • Single-pass Slope with running sumY — less ambitious: eliminate the _buffer.Average() pre-pass while keeping the deviation foreach. Bit-equality not guaranteed; measure drift, then decide whether to accept under a relaxed tolerance or revert.
  • IsApproximately<T> test helper + BufferList tolerance audit — cross-cutting decision to allow finance-grade approximate comparisons in BufferList tests where bit-equality is incompatible with O(1) numerical reformulations. tests/Library/TestTools/TestAssert.cs today exposes only IsBetween and IsExactly. Add an IsApproximately(precision) helper, audit all 79 BufferList test files, and decide per-indicator whether IsExactly is load-bearing or IsApproximately(Money6) is the correct contract. Unlocks the O(1) identities above and similar cancellation-bound reformulations elsewhere.

History

Originally tracked as PV-V31-1, PV-V31-2, and PV-V31-3 in docs/plans/streaming-indicators.plan.md (now removed; full write-up in git history).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions