Skip to content

Fix VWMA producing NaN when rolling volume sum is zero - #206

Merged
jealous merged 1 commit into
jealous:masterfrom
heykav:fix/vwma-zero-volume-nan
Sep 28, 2026
Merged

jealous merged 1 commit into
jealous:masterfrom
heykav:fix/vwma-zero-volume-nan

Conversation

@heykav

@heykav heykav commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • _get_vwma() computes rolling_tpv / rolling_vol with no guard against rolling_vol == 0, so any window whose volume sums to zero (illiquid tickers, holiday/pre-market bars with zero recorded volume, synthetic test fixtures, etc.) produces NaN/inf for vwma_* columns.
  • This is the same divide-by-zero bug class already fixed for 11 other indicators in Fix division-by-zero producing NaN values in indicators #201 (StochRSI, Wave Trend, Williams %R, CCI, VR, DX, Choppiness Index, BOP, CMO, KER, PGO) — VWMA was missed and had no test covering the zero-volume edge case.
  • Fixes the root cause by guarding the division with np.divide(..., where=rolling_vol != 0), returning 0.0 for zero-volume windows, consistent with the established pattern.

Test plan

  • Added test_vwma_with_zero_volume covering an all-zero-volume window, asserting no NaNs and a 0.0 fallback.
  • Ran full suite: 132 passed (131 pre-existing + 1 new), including the pre-existing test_vwma (exact numeric assertions on real fixture data), confirming no behavior change for normal (non-zero-volume) inputs.
  • Standalone repro script demonstrates before/after behavior.

🤖 Generated with Claude Code

_get_vwma() divided rolling_tpv by rolling_vol unconditionally. When a
window's volume sums to zero (illiquid instruments, holiday/pre-market
bars with zero recorded volume, or any all-zero-volume window), this
produced NaN instead of falling back to 0.0, unlike every other
divide-by-possibly-zero indicator in this file (StochRSI, Wave Trend,
Williams %R, CCI, VR, DX, Choppiness Index, BOP, CMO, KER, PGO — see
fe296b8) which already guard against this exact class of bug.

Guard the division with np.divide(..., where=rolling_vol != 0) so VWMA
returns 0.0 for zero-volume windows, matching the established pattern.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jealous
jealous merged commit 67318d9 into jealous:master Sep 28, 2026
4 checks passed
@jealous

jealous commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants