diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index e057d8189..450b88f3b 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -9,7 +9,7 @@ from copy import deepcopy from datetime import datetime, timedelta, timezone from typing import Any, Dict, List, Optional, Tuple -from pandas import DataFrame, NaT +from pandas import DataFrame from freqtrade.configuration import TimeRange, remove_credentials, validate_config_consistency from freqtrade.constants import DATETIME_PRINT_FORMAT @@ -457,13 +457,21 @@ class Backtesting: preprocessed = self.strategy.ohlcvdata_to_dataframe(data) # Trim startup period from analyzed dataframe - for pair, df in preprocessed.items(): - preprocessed[pair] = trim_dataframe(df, timerange, - startup_candles=self.required_startup) - min_date, max_date = history.get_timerange(preprocessed) - if min_date is NaT or max_date is NaT: + for pair in list(preprocessed): + df = preprocessed[pair] + df = trim_dataframe(df, timerange, startup_candles=self.required_startup) + if len(df) > 0: + preprocessed[pair] = df + else: + logger.warning(f'{pair} has no data left after adjusting for startup candles, ' + f'skipping.') + del preprocessed[pair] + + if not preprocessed: raise OperationalException( - "No data left after adjusting for startup candles. ") + "No data left after adjusting for startup candles.") + + min_date, max_date = history.get_timerange(preprocessed) logger.info(f'Backtesting with data from {min_date.strftime(DATETIME_PRINT_FORMAT)} ' f'up to {max_date.strftime(DATETIME_PRINT_FORMAT)} ' f'({(max_date - min_date).days} days).')