diff --git a/docs/backtesting.md b/docs/backtesting.md index c3af0798b..e1ab1c72d 100644 --- a/docs/backtesting.md +++ b/docs/backtesting.md @@ -262,7 +262,7 @@ It contains some useful key metrics about performance of your strategy on backte ``` - `Backtesting from` / `Backtesting to`: Backtesting range (usually defined with the `--timerange` option). -- `Max open trades`: Setting of `max_open_trades` (or `--max-open-trades`) - to clearly see settings for this. +- `Max open trades`: Setting of `max_open_trades` (or `--max-open-trades`) - or number of pairs in the pairlist (whatever is lower). - `Total trades`: Identical to the total trades of the backtest output table. - `Total Profit %`: Total profit. Aligned to the `TOTAL` row's `Tot Profit %` from the first table. - `Trades per day`: Total trades divided by the backtesting duration in days (this will give you information about how many trades to expect from the strategy). diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 20140492d..d0cdceaeb 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -585,9 +585,9 @@ class Hyperopt: 'winsdrawslosses': f"{wins:>4} {draws:>4} {losses:>4}", 'avg_profit': backtesting_results['profit_ratio'].mean() * 100.0, 'median_profit': backtesting_results['profit_ratio'].median() * 100.0, - 'total_profit': backtesting_results.profit_abs.sum(), + 'total_profit': backtesting_results['profit_abs'].sum(), 'profit': backtesting_results['profit_ratio'].sum() * 100.0, - 'duration': backtesting_results.trade_duration.mean(), + 'duration': backtesting_results['trade_duration'].mean(), } def _format_results_explanation_string(self, results_metrics: Dict) -> str: diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index 492d2b941..375709423 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -302,9 +302,11 @@ class Trade(_DECL_BASE): 'close_profit_pct': round(self.close_profit * 100, 2) if self.close_profit else None, 'close_profit_abs': self.close_profit_abs, # Deprecated - # TODO: should this be in minutes or seconds?? + 'trade_duration_s': (int((self.close_date - self.open_date).total_seconds()) + if self.close_date else None), 'trade_duration': (int((self.close_date - self.open_date).total_seconds() // 60) if self.close_date else None), + 'profit_ratio': self.close_profit, 'profit_pct': round(self.close_profit * 100, 2) if self.close_profit else None, 'profit_abs': self.close_profit_abs, diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 69d79159a..60d9950aa 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -81,6 +81,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'amount_requested': 91.07468123, 'stake_amount': 0.001, 'trade_duration': None, + 'trade_duration_s': None, 'close_profit': None, 'close_profit_pct': None, 'close_profit_abs': None, @@ -146,6 +147,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'amount': 91.07468123, 'amount_requested': 91.07468123, 'trade_duration': ANY, + 'trade_duration_s': ANY, 'stake_amount': 0.001, 'close_profit': None, 'close_profit_pct': None, diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 76c6ec9f6..9921f541b 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -816,6 +816,7 @@ def test_to_json(default_conf, fee): 'amount_requested': 123.0, 'stake_amount': 0.001, 'trade_duration': None, + 'trade_duration_s': None, 'close_profit': None, 'close_profit_pct': None, 'close_profit_abs': None, @@ -871,6 +872,7 @@ def test_to_json(default_conf, fee): 'amount_requested': 101.0, 'stake_amount': 0.001, 'trade_duration': 60, + 'trade_duration_s': 3600, 'stop_loss_abs': None, 'stop_loss_pct': None, 'stop_loss_ratio': None,