Skip to content

Bug: ADX division by zero when di_plus + di_minus == 0 — inf propagates through ewm #55

Description

@bradsmithmba

Summary

The ADX formula divides by di_plus + di_minus with no guard. At the start of a series before directional movement accumulates, both values are zero, producing inf. The subsequent ewm call propagates inf through the entire ADX series. fillna(0) does not remove inf, so it enters the feature tensor.

Evidence

src/features/regime_features.py line 128:

dx = 100 * np.abs(di_plus - di_minus) / (di_plus + di_minus)

No zero-division guard. di_plus and di_minus are both zero on the first period bars.

Fix

denom = di_plus + di_minus
dx = np.where(denom > 0, 100 * np.abs(di_plus - di_minus) / denom, 0.0)

Then proceed with pd.Series(dx).ewm(...).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions