Repository navigation
Fix VWMA producing NaN when rolling volume sum is zero - #206
Merged
Merged
Conversation
_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>
Owner
|
Thanks for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_get_vwma()computesrolling_tpv / rolling_volwith no guard againstrolling_vol == 0, so any window whose volume sums to zero (illiquid tickers, holiday/pre-market bars with zero recorded volume, synthetic test fixtures, etc.) producesNaN/infforvwma_*columns.np.divide(..., where=rolling_vol != 0), returning0.0for zero-volume windows, consistent with the established pattern.Test plan
test_vwma_with_zero_volumecovering an all-zero-volume window, asserting no NaNs and a0.0fallback.test_vwma(exact numeric assertions on real fixture data), confirming no behavior change for normal (non-zero-volume) inputs.🤖 Generated with Claude Code