From abf79e4ab44c1131060bd22d01d70c8c45e0af08 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 25 May 2020 20:47:48 +0200 Subject: [PATCH] Use temporary variable to clean up code --- freqtrade/optimize/optimize_reports.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index b8465ad2e..4887fe891 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -248,31 +248,34 @@ def generate_edge_table(results: dict) -> str: def show_backtest_results(config: Dict, btdata: Dict[str, DataFrame], all_results: Dict[str, DataFrame]): + stake_currency = config['stake_currency'] + max_open_trades = config['max_open_trades'] + for strategy, results in all_results.items(): - pair_results = generate_pair_metrics(btdata, stake_currency=config['stake_currency'], - max_open_trades=config['max_open_trades'], + pair_results = generate_pair_metrics(btdata, stake_currency=stake_currency, + max_open_trades=max_open_trades, results=results, skip_nan=False) - sell_reason_stats = generate_sell_reason_stats(max_open_trades=config['max_open_trades'], + sell_reason_stats = generate_sell_reason_stats(max_open_trades=max_open_trades, results=results) - left_open_results = generate_pair_metrics(btdata, stake_currency=config['stake_currency'], - max_open_trades=config['max_open_trades'], + left_open_results = generate_pair_metrics(btdata, stake_currency=stake_currency, + max_open_trades=max_open_trades, results=results.loc[results['open_at_end']], skip_nan=True) # Print results print(f"Result for strategy {strategy}") - table = generate_text_table(pair_results, stake_currency=config['stake_currency']) + table = generate_text_table(pair_results, stake_currency=stake_currency) if isinstance(table, str): print(' BACKTESTING REPORT '.center(len(table.splitlines()[0]), '=')) print(table) table = generate_text_table_sell_reason(sell_reason_stats=sell_reason_stats, - stake_currency=config['stake_currency'], + stake_currency=stake_currency, ) if isinstance(table, str): print(' SELL REASON STATS '.center(len(table.splitlines()[0]), '=')) print(table) - table = generate_text_table(left_open_results, stake_currency=config['stake_currency']) + table = generate_text_table(left_open_results, stake_currency=stake_currency) if isinstance(table, str): print(' LEFT OPEN TRADES REPORT '.center(len(table.splitlines()[0]), '=')) print(table) @@ -282,11 +285,11 @@ def show_backtest_results(config: Dict, btdata: Dict[str, DataFrame], if len(all_results) > 1: # Print Strategy summary table - strategy_results = generate_strategy_metrics(stake_currency=config['stake_currency'], - max_open_trades=config['max_open_trades'], + strategy_results = generate_strategy_metrics(stake_currency=stake_currency, + max_open_trades=max_open_trades, all_results=all_results) - table = generate_text_table_strategy(strategy_results, config['stake_currency']) + table = generate_text_table_strategy(strategy_results, stake_currency) print(' STRATEGY SUMMARY '.center(len(table.splitlines()[0]), '=')) print(table) print('=' * len(table.splitlines()[0]))