Handle division by zero error with mfi indicator #53
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.
For the mfi indicator:
If no trading days for the period were negative, we'd end up with a divisor of zero, causing with a divide by zero error.
The change here is to set the
money_flow_ratiotopositive_period_flows(a float) when there are no negative flows for the periodThe ratio calculation for money flows over the period is
positive_period_flows / negative_period_flows, with both flows representing the sum of the dollar value traded over the days in the period.While modifying the values, the
ifstatement also checks ifpositive_period_flowsis zero just to short circuit division (since it's unnecessary if the numerator is zero).