mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-03 02:23:05 +00:00
fix: handle case where informative does not overlap with the main data
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user