diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index cb021c9ff..106d0f200 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -6,7 +6,7 @@ This module contains the backtesting logic import logging from collections import defaultdict from copy import deepcopy -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from typing import Any, Dict, List, NamedTuple, Optional, Tuple from pandas import DataFrame @@ -433,6 +433,7 @@ class Backtesting: def backtest_one_strategy(self, strat: IStrategy, data: Dict[str, Any], timerange: TimeRange): logger.info("Running backtesting for Strategy %s", strat.get_strategy_name()) + backtest_start_time = datetime.now(timezone.utc) self._set_strategy(strat) strategy_safe_wrapper(self.strategy.bot_loop_start, supress_error=True)() @@ -467,10 +468,13 @@ class Backtesting: position_stacking=self.config.get('position_stacking', False), enable_protections=self.config.get('enable_protections', False), ) + backtest_end_time = datetime.now(timezone.utc) self.all_results[self.strategy.get_strategy_name()] = { 'results': results, 'config': self.strategy.config, 'locks': PairLocks.locks, + 'backtest_start_time': int(backtest_start_time.timestamp()), + 'backtest_end_time': int(backtest_end_time.timestamp()), } return min_date, max_date diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 6c70b7c84..a2bb6277e 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -282,6 +282,9 @@ def generate_backtest_stats(btdata: Dict[str, DataFrame], 'backtest_end_ts': max_date.int_timestamp * 1000, 'backtest_days': backtest_days, + 'backtest_run_start_ts': content['backtest_start_time'], + 'backtest_run_end_ts': content['backtest_end_time'], + 'trades_per_day': round(len(results) / backtest_days, 2) if backtest_days > 0 else 0, 'market_change': market_change, 'pairlist': list(btdata.keys()), @@ -290,6 +293,9 @@ def generate_backtest_stats(btdata: Dict[str, DataFrame], 'max_open_trades': (config['max_open_trades'] if config['max_open_trades'] != float('inf') else -1), 'timeframe': config['timeframe'], + 'timerange': config.get('timerange', ''), + 'enable_protections': config.get('enable_protections', False), + 'strategy_name': strategy, # Parameters relevant for backtesting 'stoploss': config['stoploss'], 'trailing_stop': config.get('trailing_stop', False), diff --git a/tests/optimize/test_optimize_reports.py b/tests/optimize/test_optimize_reports.py index e194e7de4..f184cb125 100644 --- a/tests/optimize/test_optimize_reports.py +++ b/tests/optimize/test_optimize_reports.py @@ -77,7 +77,10 @@ def test_generate_backtest_stats(default_conf, testdatadir): SellType.ROI, SellType.FORCE_SELL] }), 'config': default_conf, - 'locks': []} + 'locks': [], + 'backtest_start_time': Arrow.utcnow().int_timestamp, + 'backtest_end_time': Arrow.utcnow().int_timestamp, + } } timerange = TimeRange.parse_timerange('1510688220-1510700340') min_date = Arrow.fromtimestamp(1510688220)