Skip to content

Commit

Permalink
Fix bug filling most recent sessions for funds
Browse files Browse the repository at this point in the history
Fixes bug where `base.fill_reindexed_daily` was forward filling
prices for the most recent sessions of a fund even if those
sessions would not be expected to have prices available given
long delays in publishing price data (which for some funds can
stretch to various days).

With fix, `base.fill_reindexed_daily` now looks at sesions prior to
the most recent whenever the most recent (or prior) session
would not be expected to have price data yet available.
  • Loading branch information
maread99 committed Oct 24, 2024
1 parent 8f22be6 commit 7fd3de1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/market_prices/prices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,20 @@ def fill_reindexed_daily(
if not na_rows.any():
return df, warnings

if na_rows.iloc[-1] and helpers.now() <= cal.session_open(df.index[-1]) + delay:
na_rows.iloc[-1] = False
if not na_rows.any():
return df, warnings
# do not fill prices for any most recent sessions for which prices would not be
# expected to be available. NB this considers more than one session as for some
# funds prices many not be available for a number of days (in which case can pass
# the corresponding delay as a very high value).
i = 1
len_df = len(df)
while i <= len_df:
if na_rows.iloc[-i] and helpers.now() <= cal.session_open(df.index[-i]) + delay:
na_rows.iloc[-i] = False
if not na_rows.any():
return df, warnings
else:
break
i += 1

# fill
adj_close = df["close"].ffill()
Expand Down

0 comments on commit 7fd3de1

Please sign in to comment.