Skip to content

Commit

Permalink
Merge pull request #1920 from ranaroussi/feature/price-repair-fx
Browse files Browse the repository at this point in the history
Don't price-repair FX volume=0, is normal
  • Loading branch information
ValueRaider committed Apr 28, 2024
2 parents bb47cd4 + 2dcbe34 commit 84ba6d7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions yfinance/scrapers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,9 +1014,13 @@ def _fix_zeroes(self, df, interval, tz_exchange, prepost):
df2 = df2[~f_zero_or_nan_ignore]
f_prices_bad = (df2[price_cols] == 0.0) | df2[price_cols].isna()

f_high_low_good = (~df2["High"].isna().to_numpy()) & (~df2["Low"].isna().to_numpy())
f_change = df2["High"].to_numpy() != df2["Low"].to_numpy()
f_vol_bad = (df2["Volume"] == 0).to_numpy() & f_high_low_good & f_change
if self.ticker.endswith("=X"):
# FX, volume always 0
f_vol_bad = None
else:
f_high_low_good = (~df2["High"].isna().to_numpy()) & (~df2["Low"].isna().to_numpy())
f_vol_bad = (df2["Volume"] == 0).to_numpy() & f_high_low_good & f_change

# If stock split occurred, then trading must have happened.
# I should probably rename the function, because prices aren't zero ...
Expand All @@ -1029,7 +1033,9 @@ def _fix_zeroes(self, df, interval, tz_exchange, prepost):

# Check whether worth attempting repair
f_prices_bad = f_prices_bad.to_numpy()
f_bad_rows = f_prices_bad.any(axis=1) | f_vol_bad
f_bad_rows = f_prices_bad.any(axis=1)
if f_vol_bad is not None:
f_bad_rows = f_bad_rows | f_vol_bad
if not f_bad_rows.any():
logger.info("price-repair-missing: No price=0 errors to repair")
if "Repaired?" not in df.columns:
Expand Down

0 comments on commit 84ba6d7

Please sign in to comment.