diff --git a/freqtrade/commands/arguments.py b/freqtrade/commands/arguments.py index df4c35cc0..8f68e6521 100644 --- a/freqtrade/commands/arguments.py +++ b/freqtrade/commands/arguments.py @@ -41,7 +41,7 @@ ARGS_LIST_STRATEGIES = ["strategy_path", "print_one_column", "print_colorized"] ARGS_LIST_HYPEROPTS = ["hyperopt_path", "print_one_column", "print_colorized"] -ARGS_BACKTEST_FILTER = [] +ARGS_BACKTEST_FILTER = ["exportfilename", "backtest_show_pair_list"] ARGS_LIST_EXCHANGES = ["print_one_column", "list_exchanges_all"] @@ -175,16 +175,15 @@ class Arguments: self.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot') self._build_args(optionlist=['version'], parser=self.parser) - from freqtrade.commands import ( - start_backtesting, start_backtest_filter, start_convert_data, start_convert_trades, - start_create_userdir, start_download_data, start_edge, - start_hyperopt, start_hyperopt_list, start_hyperopt_show, - start_install_ui, start_list_data, start_list_exchanges, - start_list_markets, start_list_strategies, - start_list_timeframes, start_new_config, start_new_strategy, - start_plot_dataframe, start_plot_profit, start_show_trades, - start_test_pairlist, start_trading, start_webserver - ) + from freqtrade.commands import (start_backtest_filter, start_backtesting, + start_convert_data, start_convert_trades, + start_create_userdir, start_download_data, start_edge, + start_hyperopt, start_hyperopt_list, start_hyperopt_show, + start_install_ui, start_list_data, start_list_exchanges, + start_list_markets, start_list_strategies, + start_list_timeframes, start_new_config, start_new_strategy, + start_plot_dataframe, start_plot_profit, start_show_trades, + start_test_pairlist, start_trading, start_webserver) subparsers = self.parser.add_subparsers(dest='command', # Use custom message when no subhandler is added diff --git a/freqtrade/commands/cli_options.py b/freqtrade/commands/cli_options.py index 8d9b28c40..6aa4ed363 100644 --- a/freqtrade/commands/cli_options.py +++ b/freqtrade/commands/cli_options.py @@ -152,6 +152,12 @@ AVAILABLE_CLI_OPTIONS = { action='store_false', default=True, ), + "backtest_show_pair_list": Arg( + '--show-pair-list', + help='Show backtesting pairlist sorted by profit.', + action='store_true', + default=False, + ), "enable_protections": Arg( '--enable-protections', '--enableprotections', help='Enable protections for backtesting.' diff --git a/freqtrade/commands/optimize_commands.py b/freqtrade/commands/optimize_commands.py index 75392d897..0d1f304db 100644 --- a/freqtrade/commands/optimize_commands.py +++ b/freqtrade/commands/optimize_commands.py @@ -1,15 +1,13 @@ -from freqtrade.data.btanalysis import get_latest_backtest_filename -import pandas -from pandas.io import json -from freqtrade.optimize import backtesting import logging from typing import Any, Dict from freqtrade import constants from freqtrade.configuration import setup_utils_configuration +from freqtrade.data.btanalysis import load_backtest_stats from freqtrade.enums import RunMode from freqtrade.exceptions import OperationalException from freqtrade.misc import round_coin_value +from freqtrade.optimize.optimize_reports import show_backtest_results, show_filtered_pairlist logger = logging.getLogger(__name__) @@ -57,27 +55,19 @@ def start_backtesting(args: Dict[str, Any]) -> None: backtesting = Backtesting(config) backtesting.start() + def start_backtest_filter(args: Dict[str, Any]) -> None: """ - List backtest pairs previously filtered + Show previous backtest result """ config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE) - no_header = config.get('backtest_show_pair_list', False) - results_file = get_latest_backtest_filename( - config['user_data_dir'] / 'backtest_results/') - - logger.info("Using Backtesting result {results_file}") - - # load data using Python JSON module - with open(config['user_data_dir'] / 'backtest_results/' / results_file,'r') as f: - data = json.loads(f.read()) - strategy = list(data["strategy"])[0] - trades = data["strategy"][strategy] - - print(trades) + results = load_backtest_stats(config['exportfilename']) + # print(results) + show_backtest_results(config, results) + show_filtered_pairlist(config, results) logger.info("Backtest filtering complete. ") diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index 822577916..f5a674878 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -245,6 +245,10 @@ class Configuration: self._args_to_config(config, argname='timeframe_detail', logstring='Parameter --timeframe-detail detected, ' 'using {} for intra-candle backtesting ...') + + self._args_to_config(config, argname='backtest_show_pair_list', + logstring='Parameter --show-pair-list detected.') + self._args_to_config(config, argname='stake_amount', logstring='Parameter --stake-amount detected, ' 'overriding stake_amount to: {} ...') diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 712cce028..5adad39c1 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -736,17 +736,12 @@ def show_backtest_results(config: Dict, backtest_stats: Dict): print('=' * len(table.splitlines()[0])) print('\nFor more details, please look at the detail tables above') -def show_backtest_results_filtered(config: Dict, backtest_stats: Dict): - stake_currency = config['stake_currency'] - for strategy, results in backtest_stats['strategy'].items(): - show_backtest_result(strategy, results, stake_currency) - - if len(backtest_stats['strategy']) > 1: - # Print Strategy summary table - - table = text_table_strategy(backtest_stats['strategy_comparison'], stake_currency) - print(' STRATEGY SUMMARY '.center(len(table.splitlines()[0]), '=')) - print(table) - print('=' * len(table.splitlines()[0])) - print('\nFor more details, please look at the detail tables above') +def show_filtered_pairlist(config: Dict, backtest_stats: Dict): + if config.get('backtest_show_pair_list', False): + for strategy, results in backtest_stats['strategy'].items(): + print("Pairs for Strategy: \n[") + for result in results['results_per_pair']: + if result["key"] != 'TOTAL': + print(f'"{result["key"]}", // {round(result["profit_mean_pct"], 2)}%') + print("]")