Add option to show sorted pairlist

Allows easy copy/pasting of the pairlist to a configuration
This commit is contained in:
Matthias 2021-10-30 10:50:40 +02:00
parent 0f3809345a
commit f472709438
5 changed files with 36 additions and 42 deletions

View File

@ -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_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"] 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.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot')
self._build_args(optionlist=['version'], parser=self.parser) self._build_args(optionlist=['version'], parser=self.parser)
from freqtrade.commands import ( from freqtrade.commands import (start_backtest_filter, start_backtesting,
start_backtesting, start_backtest_filter, start_convert_data, start_convert_trades, start_convert_data, start_convert_trades,
start_create_userdir, start_download_data, start_edge, start_create_userdir, start_download_data, start_edge,
start_hyperopt, start_hyperopt_list, start_hyperopt_show, start_hyperopt, start_hyperopt_list, start_hyperopt_show,
start_install_ui, start_list_data, start_list_exchanges, start_install_ui, start_list_data, start_list_exchanges,
start_list_markets, start_list_strategies, start_list_markets, start_list_strategies,
start_list_timeframes, start_new_config, start_new_strategy, start_list_timeframes, start_new_config, start_new_strategy,
start_plot_dataframe, start_plot_profit, start_show_trades, start_plot_dataframe, start_plot_profit, start_show_trades,
start_test_pairlist, start_trading, start_webserver start_test_pairlist, start_trading, start_webserver)
)
subparsers = self.parser.add_subparsers(dest='command', subparsers = self.parser.add_subparsers(dest='command',
# Use custom message when no subhandler is added # Use custom message when no subhandler is added

View File

@ -152,6 +152,12 @@ AVAILABLE_CLI_OPTIONS = {
action='store_false', action='store_false',
default=True, 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": Arg(
'--enable-protections', '--enableprotections', '--enable-protections', '--enableprotections',
help='Enable protections for backtesting.' help='Enable protections for backtesting.'

View File

@ -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 import logging
from typing import Any, Dict from typing import Any, Dict
from freqtrade import constants from freqtrade import constants
from freqtrade.configuration import setup_utils_configuration from freqtrade.configuration import setup_utils_configuration
from freqtrade.data.btanalysis import load_backtest_stats
from freqtrade.enums import RunMode from freqtrade.enums import RunMode
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.misc import round_coin_value from freqtrade.misc import round_coin_value
from freqtrade.optimize.optimize_reports import show_backtest_results, show_filtered_pairlist
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -57,27 +55,19 @@ def start_backtesting(args: Dict[str, Any]) -> None:
backtesting = Backtesting(config) backtesting = Backtesting(config)
backtesting.start() backtesting.start()
def start_backtest_filter(args: Dict[str, Any]) -> None: 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) config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
no_header = config.get('backtest_show_pair_list', False) results = load_backtest_stats(config['exportfilename'])
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)
# print(results)
show_backtest_results(config, results)
show_filtered_pairlist(config, results)
logger.info("Backtest filtering complete. ") logger.info("Backtest filtering complete. ")

View File

@ -245,6 +245,10 @@ class Configuration:
self._args_to_config(config, argname='timeframe_detail', self._args_to_config(config, argname='timeframe_detail',
logstring='Parameter --timeframe-detail detected, ' logstring='Parameter --timeframe-detail detected, '
'using {} for intra-candle backtesting ...') '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', self._args_to_config(config, argname='stake_amount',
logstring='Parameter --stake-amount detected, ' logstring='Parameter --stake-amount detected, '
'overriding stake_amount to: {} ...') 'overriding stake_amount to: {} ...')

View File

@ -736,17 +736,12 @@ def show_backtest_results(config: Dict, backtest_stats: Dict):
print('=' * len(table.splitlines()[0])) print('=' * len(table.splitlines()[0]))
print('\nFor more details, please look at the detail tables above') 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(): def show_filtered_pairlist(config: Dict, backtest_stats: Dict):
show_backtest_result(strategy, results, stake_currency) if config.get('backtest_show_pair_list', False):
for strategy, results in backtest_stats['strategy'].items():
if len(backtest_stats['strategy']) > 1: print("Pairs for Strategy: \n[")
# Print Strategy summary table for result in results['results_per_pair']:
if result["key"] != 'TOTAL':
table = text_table_strategy(backtest_stats['strategy_comparison'], stake_currency) print(f'"{result["key"]}", // {round(result["profit_mean_pct"], 2)}%')
print(' STRATEGY SUMMARY '.center(len(table.splitlines()[0]), '=')) print("]")
print(table)
print('=' * len(table.splitlines()[0]))
print('\nFor more details, please look at the detail tables above')