Support days-breakdown also for hyperopt results

This commit is contained in:
Matthias 2021-10-17 16:48:31 +02:00
parent 47bba331c1
commit 7d8cd736b8
3 changed files with 10 additions and 8 deletions

View File

@ -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",

View File

@ -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)

View File

@ -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]), '='))