Fix group 0 table, add pathlib.Path use

This commit is contained in:
froggleston 2022-05-24 12:48:13 +01:00
parent 80c6190c05
commit 8c03ebb78f
3 changed files with 16 additions and 11 deletions

View File

@ -1,5 +1,4 @@
import logging
import os
from pathlib import Path
from typing import Any, Dict
@ -26,14 +25,19 @@ def setup_analyze_configuration(args: Dict[str, Any], method: RunMode) -> Dict[s
if method in no_unlimited_runmodes.keys():
from freqtrade.data.btanalysis import get_latest_backtest_filename
btfile = get_latest_backtest_filename(config['user_data_dir'] / 'backtest_results')
signals_file = f"{os.path.basename(os.path.splitext(btfile)[0])}_signals.pkl"
btfile = Path(get_latest_backtest_filename(config['user_data_dir'] / 'backtest_results'))
signals_file = f"{btfile.stem}_signals.pkl"
if (not os.path.exists(config['user_data_dir'] / 'backtest_results' / signals_file)):
if (not (config['user_data_dir'] / 'backtest_results' / signals_file).exists()):
raise OperationalException(
"Cannot find latest backtest signals file. Run backtesting with --export signals."
)
if ('strategy' not in config):
raise OperationalException(
"No strategy defined. Use --strategy or supply in config."
)
return config
@ -48,6 +52,8 @@ def start_analysis_entries_exits(args: Dict[str, Any]) -> None:
# Initialize configuration
config = setup_analyze_configuration(args, RunMode.BACKTEST)
print(config)
logger.info('Starting freqtrade in analysis mode')
process_entry_exit_reasons(Path(config['user_data_dir'], 'backtest_results'),

View File

@ -644,5 +644,6 @@ AVAILABLE_CLI_OPTIONS = {
help=("Comma separated list of indicators to analyse. ",
"e.g. 'close,rsi,bb_lowerband,profit_abs'"),
nargs='?',
default='',
),
}

View File

@ -97,15 +97,12 @@ def _do_group_table_output(bigdf, glist):
'count',
lambda x: sum(x > 0),
lambda x: sum(x <= 0)]})
new = pd.merge(new, wins, left_index=True, right_index=True)
new = pd.merge(new, loss, left_index=True, right_index=True)
new = pd.concat([new, wins, loss], axis=1).fillna(0)
new['profit_tot'] = new['profit_abs_wins'] - abs(new['profit_abs_loss'])
new['wl_ratio_pct'] = (new.iloc[:, 1] / new.iloc[:, 0] * 100)
new['avg_win'] = (new['profit_abs_wins'] / new.iloc[:, 1])
new['avg_loss'] = (new['profit_abs_loss'] / new.iloc[:, 2])
new['wl_ratio_pct'] = (new.iloc[:, 1] / new.iloc[:, 0] * 100).fillna(0)
new['avg_win'] = (new['profit_abs_wins'] / new.iloc[:, 1]).fillna(0)
new['avg_loss'] = (new['profit_abs_loss'] / new.iloc[:, 2]).fillna(0)
new.columns = ['total_num_buys', 'wins', 'losses', 'profit_abs_wins', 'profit_abs_loss',
'profit_tot', 'wl_ratio_pct', 'avg_win', 'avg_loss']
@ -249,6 +246,7 @@ def process_entry_exit_reasons(backtest_dir: Path,
signal_candles = _load_signal_candles(backtest_dir)
analysed_trades_dict = _process_candles_and_indicators(pairlist, strategy_name,
trades, signal_candles)
_print_results(analysed_trades_dict,
strategy_name,
analysis_groups,