Skip to content

Bug: OBV loop propagates NaN silently when yfinance volume contains NaN #60

Description

@bradsmithmba

Summary

VolumeFeatures.calculate_obv runs a Python loop accumulating OBV. yfinance frequently returns NaN for the most recent bar's volume. One NaN in the loop causes all subsequent OBV values to become NaN. handle_missing_data (ffill) then fills the entire NaN tail with the last valid OBV value, which may be weeks old.

Evidence

src/features/regime_features.py lines 403-413: no NaN guard in the OBV accumulation loop.
handle_missing_data is called at line 419, after the loop — after NaN has already propagated.

Fix

Guard at the start of the loop: vol = volume.fillna(0) before OBV accumulation (zero volume for unknown bars is the conventional treatment).

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