Skip to content

Commit 93b8769

Browse files
committed
fix: handle case where informative does not overlap with the main data
1 parent 876875c commit 93b8769

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

freqtrade/strategy/strategy_helper.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ def merge_informative_pair(
9898
# We can fill these with the last available informative candle before the start date
9999
# while still avoiding lookahead bias - as only past data is used.
100100
first_valid_idx = dataframe[date_merge].first_valid_index()
101-
first_valid_date_merge = dataframe.at[first_valid_idx, date_merge]
102-
matching_informative_raws = informative[
103-
informative[date_merge] < first_valid_date_merge
104-
]
105-
if not matching_informative_raws.empty:
106-
dataframe.loc[: first_valid_idx - 1] = dataframe.loc[: first_valid_idx - 1].fillna(
107-
matching_informative_raws.iloc[-1]
108-
)
101+
if first_valid_idx:
102+
first_valid_date_merge = dataframe.at[first_valid_idx, date_merge]
103+
matching_informative_raws = informative[
104+
informative[date_merge] < first_valid_date_merge
105+
]
106+
if not matching_informative_raws.empty:
107+
dataframe.loc[: first_valid_idx - 1] = dataframe.loc[
108+
: first_valid_idx - 1
109+
].fillna(matching_informative_raws.iloc[-1])
109110
else:
110111
dataframe = pd.merge(
111112
dataframe, informative, left_on="date", right_on=date_merge, how="left"

0 commit comments

Comments
 (0)