From 1203d08d1ec6b9632b80b22b74b25b75f2358917 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 7 Jan 2022 08:44:11 +0100 Subject: [PATCH] generate_pair_metrics does not need processed dict --- freqtrade/optimize/optimize_reports.py | 15 ++++++++------- tests/optimize/test_optimize_reports.py | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 162ece08e..70689ac3b 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -99,11 +99,11 @@ def _generate_result_line(result: DataFrame, starting_balance: int, first_column } -def generate_pair_metrics(data: Dict[str, Dict], stake_currency: str, starting_balance: int, +def generate_pair_metrics(pairlist: List[str], stake_currency: str, starting_balance: int, results: DataFrame, skip_nan: bool = False) -> List[Dict]: """ Generates and returns a list for the given backtest data and the results dataframe - :param data: Dict of containing data that was used during backtesting. + :param pairlist: Pairlist used :param stake_currency: stake-currency - used to correctly name headers :param starting_balance: Starting balance :param results: Dataframe containing the backtest results @@ -113,7 +113,7 @@ def generate_pair_metrics(data: Dict[str, Dict], stake_currency: str, starting_b tabular_data = [] - for pair in data: + for pair in pairlist: result = results[results['pair'] == pair] if skip_nan and result['profit_abs'].isnull().all(): continue @@ -365,11 +365,12 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame], if not isinstance(results, DataFrame): return {} config = content['config'] - max_open_trades = min(config['max_open_trades'], len(btdata.keys())) + pairlist = list(btdata.keys()) + max_open_trades = min(config['max_open_trades'], len(pairlist)) starting_balance = config['dry_run_wallet'] stake_currency = config['stake_currency'] - pair_results = generate_pair_metrics(btdata, stake_currency=stake_currency, + pair_results = generate_pair_metrics(pairlist, stake_currency=stake_currency, starting_balance=starting_balance, results=results, skip_nan=False) @@ -378,7 +379,7 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame], sell_reason_stats = generate_sell_reason_stats(max_open_trades=max_open_trades, results=results) - left_open_results = generate_pair_metrics(btdata, stake_currency=stake_currency, + left_open_results = generate_pair_metrics(pairlist, stake_currency=stake_currency, starting_balance=starting_balance, results=results.loc[results['is_open']], skip_nan=True) @@ -422,7 +423,7 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame], 'trades_per_day': round(len(results) / backtest_days, 2), 'market_change': market_change, - 'pairlist': list(btdata.keys()), + 'pairlist': pairlist, 'stake_amount': config['stake_amount'], 'stake_currency': config['stake_currency'], 'stake_currency_decimals': decimals_per_coin(config['stake_currency']), diff --git a/tests/optimize/test_optimize_reports.py b/tests/optimize/test_optimize_reports.py index 925dc3caa..ed939d6b0 100644 --- a/tests/optimize/test_optimize_reports.py +++ b/tests/optimize/test_optimize_reports.py @@ -48,7 +48,7 @@ def test_text_table_bt_results(): ' 0:20:00 | 2 0 1 66.7 |' ) - pair_results = generate_pair_metrics(data={'ETH/BTC': {}}, stake_currency='BTC', + pair_results = generate_pair_metrics(['ETH/BTC'], stake_currency='BTC', starting_balance=4, results=results) assert text_table_bt_results(pair_results, stake_currency='BTC') == result_str @@ -207,7 +207,7 @@ def test_generate_pair_metrics(): } ) - pair_results = generate_pair_metrics(data={'ETH/BTC': {}}, stake_currency='BTC', + pair_results = generate_pair_metrics(['ETH/BTC'], stake_currency='BTC', starting_balance=2, results=results) assert isinstance(pair_results, list) assert len(pair_results) == 2