From 7d8cd736b8113904c427ccba13b2a5113e959be3 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 17 Oct 2021 16:48:31 +0200 Subject: [PATCH] Support days-breakdown also for hyperopt results --- freqtrade/commands/arguments.py | 2 +- freqtrade/commands/hyperopt_commands.py | 2 +- freqtrade/optimize/optimize_reports.py | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/freqtrade/commands/arguments.py b/freqtrade/commands/arguments.py index 00aa0ded0..11c1e9191 100644 --- a/freqtrade/commands/arguments.py +++ b/freqtrade/commands/arguments.py @@ -89,7 +89,7 @@ ARGS_HYPEROPT_LIST = ["hyperopt_list_best", "hyperopt_list_profitable", ARGS_HYPEROPT_SHOW = ["hyperopt_list_best", "hyperopt_list_profitable", "hyperopt_show_index", "print_json", "hyperoptexportfilename", "hyperopt_show_no_header", - "disableparamexport"] + "disableparamexport", "show_days"] NO_CONF_REQURIED = ["convert-data", "convert-trade-data", "download-data", "list-timeframes", "list-markets", "list-pairs", "list-strategies", "list-data", diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index 614c4b3f5..d2f8c188c 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -96,7 +96,7 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None: if 'strategy_name' in metrics: strategy_name = metrics['strategy_name'] show_backtest_result(strategy_name, metrics, - metrics['stake_currency']) + metrics['stake_currency'], config.get('show_days', False)) HyperoptTools.try_export_params(config, strategy_name, val) diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 384ca006b..a6eedc6c7 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import Any, Dict, List, Union from numpy import int64 -from pandas import DataFrame +from pandas import DataFrame, to_datetime from tabulate import tabulate from freqtrade.constants import DATETIME_PRINT_FORMAT, LAST_BT_RESULT_FN, UNLIMITED_STAKE_AMOUNT @@ -213,7 +213,9 @@ def generate_edge_table(results: dict) -> str: floatfmt=floatfmt, tablefmt="orgtbl", stralign="right") # type: ignore -def generate_days_breakdown_stats(results: DataFrame, starting_balance: int) -> Dict[str, Any]: +def generate_days_breakdown_stats(trade_list: List, starting_balance: int) -> List[Dict[str, Any]]: + results = DataFrame.from_records(trade_list) + results['close_date'] = to_datetime(results['close_date'], utc=True) days = results.resample('1d', on='close_date') days_stats = [] for name, day in days: @@ -341,8 +343,6 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame], starting_balance=starting_balance, results=results.loc[results['is_open']], skip_nan=True) - days_breakdown_stats = generate_days_breakdown_stats( - results=results, starting_balance=starting_balance) daily_stats = generate_daily_stats(results) trade_stats = generate_trading_stats(results) best_pair = max([pair for pair in pair_results if pair['key'] != 'TOTAL'], @@ -362,7 +362,7 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame], 'results_per_pair': pair_results, 'sell_reason_summary': sell_reason_stats, 'left_open_trades': left_open_results, - 'days_breakdown_stats': days_breakdown_stats, + # 'days_breakdown_stats': days_breakdown_stats, 'total_trades': len(results), 'total_volume': float(results['stake_amount'].sum()), @@ -690,7 +690,9 @@ def show_backtest_result(strategy: str, results: Dict[str, Any], stake_currency: print(table) if show_days: - table = text_table_days_breakdown(days_breakdown_stats=results['days_breakdown_stats'], + days_breakdown_stats = generate_days_breakdown_stats( + trade_list=results['trades'], starting_balance=results['starting_balance']) + table = text_table_days_breakdown(days_breakdown_stats=days_breakdown_stats, stake_currency=stake_currency) if isinstance(table, str) and len(table) > 0: print(' DAYS BREAKDOWN '.center(len(table.splitlines()[0]), '='))