From 11ace0f867c8f504feabddf5a96ddb84a557c694 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Fri, 7 Jan 2022 12:07:49 +0200 Subject: [PATCH 1/4] Instead of clearing `processed` dict, store `df_analyzed` (one with buy/sell signals) dataframe in it. It still saves memory because this dataframe is kept by DataProvider. Fixes #6179. Amends #6133 (a715083fc09cc9c53277e884238a371c138473b9). --- freqtrade/optimize/backtesting.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index fed872015..6cd6d17a6 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -270,8 +270,8 @@ class Backtesting: df_analyzed = self.strategy.advise_sell( self.strategy.advise_buy(pair_data, {'pair': pair}), {'pair': pair}).copy() # Trim startup period from analyzed dataframe - df_analyzed = trim_dataframe(df_analyzed, self.timerange, - startup_candles=self.required_startup) + df_analyzed = processed[pair] = pair_data = trim_dataframe( + df_analyzed, self.timerange, startup_candles=self.required_startup) # To avoid using data from future, we use buy/sell signals shifted # from the previous candle df_analyzed.loc[:, 'buy'] = df_analyzed.loc[:, 'buy'].shift(1) @@ -287,9 +287,6 @@ class Backtesting: # Convert from Pandas to list for performance reasons # (Looping Pandas is slow.) data[pair] = df_analyzed[headers].values.tolist() - - # Do not hold on to old data to reduce memory usage - processed[pair] = pair_data = None return data def _get_close_rate(self, sell_row: Tuple, trade: LocalTrade, sell: SellCheckTuple, From 04976658da1303b99f377f3b98c5ccd5ac17a99a Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 7 Jan 2022 17:32:13 +0100 Subject: [PATCH 2/4] Fix crash when using backtesting-show on a old backtestresult --- freqtrade/optimize/optimize_reports.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 17d1d8128..d0ffe49a9 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -642,7 +642,12 @@ def text_table_strategy(strategy_results, stake_currency: str) -> str: headers.append('Drawdown') # Align drawdown string on the center two space separator. - drawdown = [f'{t["max_drawdown_account"] * 100:.2f}' for t in strategy_results] + if 'max_drawdown_account' in strategy_results[0]: + drawdown = [f'{t["max_drawdown_account"] * 100:.2f}' for t in strategy_results] + else: + # Support for prior backtest results + drawdown = [f'{t["max_drawdown_per"]:.2f}' for t in strategy_results] + dd_pad_abs = max([len(t['max_drawdown_abs']) for t in strategy_results]) dd_pad_per = max([len(dd) for dd in drawdown]) drawdown = [f'{t["max_drawdown_abs"]:>{dd_pad_abs}} {stake_currency} {dd:>{dd_pad_per}}%' From 827b8d3e4c86dac5d39611add1a75b32cb095481 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 7 Jan 2022 20:00:20 +0100 Subject: [PATCH 3/4] Don't use test_datadir as userdata dir use tmpdir --- tests/optimize/test_hyperopt.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index ca64d73d5..1f7c2ee8c 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -191,8 +191,8 @@ def test_start_no_hyperopt_allowed(mocker, hyperopt_conf, caplog) -> None: start_hyperopt(pargs) -def test_start_no_data(mocker, hyperopt_conf) -> None: - hyperopt_conf['user_data_dir'] = Path("tests") +def test_start_no_data(mocker, hyperopt_conf, tmpdir) -> None: + hyperopt_conf['user_data_dir'] = Path(tmpdir) patched_configuration_load_config_file(mocker, hyperopt_conf) mocker.patch('freqtrade.data.history.load_pair_history', MagicMock(return_value=pd.DataFrame)) mocker.patch( @@ -201,7 +201,6 @@ def test_start_no_data(mocker, hyperopt_conf) -> None: ) patch_exchange(mocker) - # TODO: migrate to strategy-based hyperopt args = [ 'hyperopt', '--config', 'config.json', From 43f8087f32b8108ec8ee263a8d6bf5d7e27dd347 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 8 Jan 2022 10:44:07 +0100 Subject: [PATCH 4/4] Bitvavo does not support USDT stake --- tests/exchange/test_ccxt_compat.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/exchange/test_ccxt_compat.py b/tests/exchange/test_ccxt_compat.py index ab8a9b651..35620e9e2 100644 --- a/tests/exchange/test_ccxt_compat.py +++ b/tests/exchange/test_ccxt_compat.py @@ -54,6 +54,7 @@ EXCHANGES = { }, 'bitvavo': { 'pair': 'BTC/EUR', + 'stake_currency': 'EUR', 'hasQuoteVolume': True, 'timeframe': '5m', }, @@ -73,6 +74,8 @@ def exchange_conf(): @pytest.fixture(params=EXCHANGES, scope="class") def exchange(request, exchange_conf): exchange_conf['exchange']['name'] = request.param + exchange_conf['stake_currency'] = EXCHANGES[request.param].get( + 'stake_currency', exchange_conf['stake_currency']) exchange = ExchangeResolver.load_exchange(request.param, exchange_conf, validate=True) yield exchange, request.param