Skip to content

Commit

Permalink
Merge pull request #55 from ValueRaider/fix/financials-nonsense-dates…
Browse files Browse the repository at this point in the history
…-from-Yahoo

Handle nonsense financials dates from Yahoo that survived pruning
  • Loading branch information
ValueRaider authored Apr 16, 2024
2 parents c63da6a + 6240413 commit 52edbf7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions yfinance_cache/yfc_financials_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,19 @@ def _get_interval_from_table(self, tbl):

interval = None
intervals = [(dates[i-1] - dates[i]).days for i in range(1,len(dates))]
intervals = np.array(intervals)
sdm_thresold = 0.1
if len(intervals) == 1:
interval = intervals[0]
else:
avg = mean(intervals)
sdm = stdev(intervals) / avg
# First, discard impossibly small intervals:
f_too_small = intervals < 60
if f_too_small.any():
intervals = intervals[~f_too_small]
avg = np.mean(intervals)
sdm = np.std(intervals) / avg
if sdm > sdm_thresold:
# Discard large outliers
intervals = np.array(intervals)
intervals = intervals[intervals<avg]
if len(intervals) == 1:
interval = intervals[0]
Expand Down Expand Up @@ -1167,6 +1171,11 @@ def _check_release_dates(self, releases, finType, period, refresh):
# else:
# interval_td = self._get_interval(finType, refresh)

# Ignore releases with no date:
# - can happen with nonsense financials dates from Yahoo that
# even my prune function couldn't safely remove
releases = [r for r in releases if r.release_date is not None]

for i0 in range(len(releases)-1):
r0 = releases[i0]
r0rd = r0.release_date
Expand Down

0 comments on commit 52edbf7

Please sign in to comment.