Skip to content

Commit

Permalink
Price repair: reduce sensitivity to extreme-low Low prices
Browse files Browse the repository at this point in the history
Tweak sudden change detection, to use prices' median not mean, reduce sensitivity to noise.
  • Loading branch information
ValueRaider committed May 13, 2024
1 parent 9ffbaeb commit 7ede47a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions yfinance/scrapers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7ede47a

Please sign in to comment.