fix: handle case where informative does not overlap with the main data

This commit is contained in:
Matthias
2025-10-12 09:51:31 +02:00
parent 876875cff2
commit 93b87696c6

View File

@@ -98,14 +98,15 @@ def merge_informative_pair(
# We can fill these with the last available informative candle before the start date
# while still avoiding lookahead bias - as only past data is used.
first_valid_idx = dataframe[date_merge].first_valid_index()
first_valid_date_merge = dataframe.at[first_valid_idx, date_merge]
matching_informative_raws = informative[
informative[date_merge] < first_valid_date_merge
]
if not matching_informative_raws.empty:
dataframe.loc[: first_valid_idx - 1] = dataframe.loc[: first_valid_idx - 1].fillna(
matching_informative_raws.iloc[-1]
)
if first_valid_idx:
first_valid_date_merge = dataframe.at[first_valid_idx, date_merge]
matching_informative_raws = informative[
informative[date_merge] < first_valid_date_merge
]
if not matching_informative_raws.empty:
dataframe.loc[: first_valid_idx - 1] = dataframe.loc[
: first_valid_idx - 1
].fillna(matching_informative_raws.iloc[-1])
else:
dataframe = pd.merge(
dataframe, informative, left_on="date", right_on=date_merge, how="left"