From 1a984ac6774a9e7e20105580cc157f5ec482be45 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 21 May 2020 07:12:23 +0200 Subject: [PATCH] Explicitly raise ValueError if trades are empty --- freqtrade/data/btanalysis.py | 3 +++ tests/data/test_btanalysis.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index b0c642c1d..f98135c27 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -194,7 +194,10 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str, :param col_name: Column name that will be assigned the results :param timeframe: Timeframe used during the operations :return: Returns df with one additional column, col_name, containing the cumulative profit. + :raise: ValueError if trade-dataframe was found empty. """ + if len(trades) == 0: + raise ValueError("Trade dataframe empty.") from freqtrade.exchange import timeframe_to_minutes timeframe_minutes = timeframe_to_minutes(timeframe) # Resample to timeframe to make sure trades match candles diff --git a/tests/data/test_btanalysis.py b/tests/data/test_btanalysis.py index 4da2acc5e..50cf9db3d 100644 --- a/tests/data/test_btanalysis.py +++ b/tests/data/test_btanalysis.py @@ -178,6 +178,10 @@ def test_create_cum_profit1(testdatadir): assert cum_profits.iloc[0]['cum_profits'] == 0 assert cum_profits.iloc[-1]['cum_profits'] == 0.0798005 + with pytest.raises(ValueError, match='Trade dataframe empty.'): + create_cum_profit(df.set_index('date'), bt_data[bt_data["pair"] == 'NOTAPAIR'], + "cum_profits", timeframe="5m") + def test_calculate_max_drawdown(testdatadir): filename = testdatadir / "backtest-result_test.json"