From 2591a34db4167cfb64f680493be1a0899719f02e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 18 Oct 2020 16:18:52 +0200 Subject: [PATCH] Don't use arrow objects for backtesting --- freqtrade/optimize/backtesting.py | 11 +++++------ freqtrade/optimize/hyperopt.py | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index f59a782e8..61a83afc1 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -9,7 +9,6 @@ from copy import deepcopy from datetime import datetime, timedelta from typing import Any, Dict, List, NamedTuple, Optional, Tuple -import arrow from pandas import DataFrame from freqtrade.configuration import TimeRange, remove_credentials, validate_config_consistency @@ -173,7 +172,7 @@ class Backtesting: # Convert from Pandas to list for performance reasons # (Looping Pandas is slow.) - data[pair] = [x for x in df_analyzed.itertuples()] + data[pair] = [x for x in df_analyzed.itertuples(index=False)] return data def _get_close_rate(self, sell_row, trade: Trade, sell: SellCheckTuple, @@ -271,7 +270,7 @@ class Backtesting: return trades def backtest(self, processed: Dict, stake_amount: float, - start_date: arrow.Arrow, end_date: arrow.Arrow, + start_date: datetime, end_date: datetime, max_open_trades: int = 0, position_stacking: bool = False) -> DataFrame: """ Implement backtesting functionality @@ -321,7 +320,7 @@ class Backtesting: continue # Waits until the time-counter reaches the start of the data for this pair. - if row.date > tmp.datetime: + if row.date > tmp: continue indexes[pair] += 1 @@ -413,8 +412,8 @@ class Backtesting: results = self.backtest( processed=preprocessed, stake_amount=self.config['stake_amount'], - start_date=min_date, - end_date=max_date, + start_date=min_date.datetime, + end_date=max_date.datetime, max_open_trades=max_open_trades, position_stacking=position_stacking, ) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 5997e077b..e24212536 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -538,8 +538,8 @@ class Hyperopt: backtesting_results = self.backtesting.backtest( processed=processed, stake_amount=self.config['stake_amount'], - start_date=min_date, - end_date=max_date, + start_date=min_date.datetime, + end_date=max_date.datetime, max_open_trades=self.max_open_trades, position_stacking=self.position_stacking, )