Skip to content

Commit a965eec

Browse files
committed
Fixes for PR #2958
1 parent c732994 commit a965eec

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

‎yfinance/scrapers/history.py‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,7 +3315,7 @@ def denoise_volume(vol):
33153315
if interval in ['1mo', '3mo']:
33163316
largest_volChg_pct *= 2
33173317
# volChg_pct is a windowed median, so threshold can (and needs to be) more relaxed
3318-
threshold_volUnitChg = 1+ (split_max-1 + largest_volChg_pct) * 0.333
3318+
threshold_volUnitChg = 1+ (split_max-1 + largest_volChg_pct) * 0.2
33193319
logger.debug(f"largest_volChg_pct = {largest_volChg_pct:.4f}, threshold_volUnitChg = {threshold_volUnitChg:.2f}", extra=log_extras)
33203320

33213321
f_up_ndims = len(f_up.shape)
@@ -3755,13 +3755,13 @@ def map_signals_to_ranges(f, f_up, f_down):
37553755
# For very short ranges, add on adjacent ranges so that
37563756
# the 2x volume arrays have good lengths.
37573757
vol_during = vol[r[0]:r[1]]
3758-
vol_outside = []
3758+
vol_outside = np.array([])
37593759
if i==0 and r[0] > 0:
37603760
vol_outside = vol[max(0,r[0]-10) : r[0]]
37613761
elif i==len(ranges)-1 and r[1] < len(vol):
37623762
vol_outside = vol[r[1] : min(r[1]+10, len(vol))]
3763-
for step in range(1, (len(ranges)+1)//2):
3764-
if len(vol_outside) > 10 and len(vol_during) > 10:
3763+
for step in range(1, len(ranges)):
3764+
if np.sum(vol_outside>0) > 10 and np.sum(vol_during>0) > 10:
37653765
# Have enough to compare
37663766
break
37673767
i2 = i-step
@@ -3770,17 +3770,17 @@ def map_signals_to_ranges(f, f_up, f_down):
37703770
i3b = i3-1
37713771
if i2 >= 0:
37723772
r2 = ranges[i2]
3773-
if len(vol_during) < 10:
3773+
if np.sum(vol_during>0) < 10:
37743774
vol_during = np.append(vol[r2[0]:r2[1]], vol_during)
3775-
if len(vol_outside) < 10:
3775+
if np.sum(vol_outside>0) < 10:
37763776
if i2n < len(ranges):
37773777
r2n = ranges[i2n]
37783778
vol_outside = np.append(vol[r2[1]:r2n[0]], vol_outside)
37793779
if i3 < len(ranges):
37803780
r3 = ranges[i3]
3781-
if len(vol_during) < 10:
3781+
if np.sum(vol_during>0) < 10:
37823782
vol_during = np.append(vol[r3[0]:r3[1]], vol_during)
3783-
if len(vol_outside) < 10:
3783+
if np.sum(vol_outside>0) < 10:
37843784
if i3b >= 0:
37853785
r3b = ranges[i3b]
37863786
vol_outside = np.append(vol[r3b[1]:r3[0]], vol_outside)
@@ -3792,29 +3792,29 @@ def map_signals_to_ranges(f, f_up, f_down):
37923792
# No volume to check, but this should be incredibly rare.
37933793
pass
37943794
else:
3795-
boundary_vol_change = np.mean(volDuring_denoised) / np.mean(volOutside_denoised)
3796-
if not unit_switch:
3797-
# Stock-split - expect to see big volume changes
3798-
if boundary_vol_change < 1.0/threshold_volUnitChg and f_up[r[0]]:
3799-
# Good
3800-
pass
3801-
elif boundary_vol_change > threshold_volUnitChg and f_down[r[0]]:
3802-
# Good
3803-
pass
3804-
else:
3805-
# Bad
3806-
continue
3807-
else:
3808-
# Unit switch - expect normal volume
3809-
if boundary_vol_change < 1.0/threshold_volUnitChg and f_up[r[0]]:
3810-
# Bad
3811-
continue
3812-
elif boundary_vol_change > threshold_volUnitChg and f_down[r[0]]:
3813-
# Bad
3814-
continue
3815-
else:
3816-
# Good
3817-
pass
3795+
boundary_vol_change = np.mean(volDuring_denoised) / np.mean(volOutside_denoised)
3796+
if not unit_switch:
3797+
# Stock-split - expect to see big volume changes
3798+
if boundary_vol_change < 1.0/threshold_volUnitChg and f_up[r[0]]:
3799+
# Good
3800+
pass
3801+
elif boundary_vol_change > threshold_volUnitChg and f_down[r[0]]:
3802+
# Good
3803+
pass
3804+
else:
3805+
# Bad
3806+
continue
3807+
else:
3808+
# Unit switch - expect normal volume
3809+
if boundary_vol_change < 1.0/threshold_volUnitChg and f_up[r[0]]:
3810+
# Bad
3811+
continue
3812+
elif boundary_vol_change > threshold_volUnitChg and f_down[r[0]]:
3813+
# Bad
3814+
continue
3815+
else:
3816+
# Good
3817+
pass
38183818

38193819
for i in range(len(ranges)):
38203820
r = ranges[i]

0 commit comments

Comments
 (0)