From 2ae398913d0fbfe232dec90fd8c3aa76c78dd124 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 23 Aug 2019 20:43:39 +0200 Subject: [PATCH] Fix bug in bt-analysis when multiple trades sell at the same time --- freqtrade/data/btanalysis.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 992100cbd..b03bdb74d 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -157,7 +157,8 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str) -> :param trades: DataFrame containing trades (requires columns close_time and profitperc) :return: Returns df with one additional column, col_name, containing the cumulative profit. """ - df[col_name] = trades.set_index('close_time')['profitperc'].cumsum() + # Use groupby/sum().cumsum() to avoid errors when multiple trades sold at the same candle. + df[col_name] = trades.groupby('close_time')['profitperc'].sum().cumsum() # Set first value to 0 df.loc[df.iloc[0].name, col_name] = 0 # FFill to get continuous