From ca9bb5d08cdce9deea358b7716deefe0b669497a Mon Sep 17 00:00:00 2001 From: ValueRaider Date: Mon, 13 May 2024 20:49:57 +0100 Subject: [PATCH] Price repair: reduce sensitivity to extreme-low Low prices Switch to median from mean when scanning for sudden changes, reduces sensitivitity to extreme outliers --- yfinance/scrapers/history.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/yfinance/scrapers/history.py b/yfinance/scrapers/history.py index b5b302280..4a668e31c 100644 --- a/yfinance/scrapers/history.py +++ b/yfinance/scrapers/history.py @@ -1317,10 +1317,12 @@ def _fix_prices_sudden_change(self, df, interval, tz_exchange, change, correct_v # average change _1d_change_minx = np.average(_1d_change_x, axis=1) else: - # change nearest to 1.0 - diff = np.abs(_1d_change_x - 1.0) - j_indices = np.argmin(diff, axis=1) - _1d_change_minx = _1d_change_x[np.arange(n), j_indices] + # # change nearest to 1.0 + # diff = np.abs(_1d_change_x - 1.0) + # j_indices = np.argmin(diff, axis=1) + # _1d_change_minx = _1d_change_x[np.arange(n), j_indices] + # Still sensitive to extreme-low low. Try median: + _1d_change_minx = np.median(_1d_change_x, axis=1) f_na = np.isnan(_1d_change_minx) if f_na.any(): # Possible if data was too old for reconstruction.