Add export-filename support

This commit is contained in:
froggleston 2022-06-14 16:54:27 +01:00
parent be6e0813db
commit 6bb342f23a
4 changed files with 43 additions and 12 deletions

View File

@ -45,6 +45,31 @@ ranging from the simplest (0) to the most detailed per pair, per buy and per sel
More options are available by running with the `-h` option. More options are available by running with the `-h` option.
### Using export-filename
Normally, `backtesting-analysis` uses the latest backtest results, but if you wanted to go
back to a previous backtest output, you need to supply the `--export-filename` option.
You can supply the same parameter to `backtest-analysis` with the name of the final backtest
output file. This allows you to keep historical versions of backtest results and reanalyse
them at a later date:
``` bash
freqtrade backtesting -c <config.json> --timeframe <tf> --strategy <strategy_name> --timerange=<timerange> --export=signals --export-filename=/tmp/mystrat_backtest.json
```
You should see some output similar to below in the logs with the name of the timestamped
filename that was exported:
```
2022-06-14 16:28:32,698 - freqtrade.misc - INFO - dumping json to "/tmp/mystrat_backtest-2022-06-14_16-28-32.json"
```
You can then use that filename in `backtesting-analysis`:
```
freqtrade backtesting-analysis -c <config.json> --export-filename=/tmp/mystrat_backtest-2022-06-14_16-28-32.json
```
### Tuning the buy tags and sell tags to display ### Tuning the buy tags and sell tags to display
To show only certain buy and sell tags in the displayed output, use the following two options: To show only certain buy and sell tags in the displayed output, use the following two options:

View File

@ -25,17 +25,23 @@ def setup_analyze_configuration(args: Dict[str, Any], method: RunMode) -> Dict[s
if method in no_unlimited_runmodes.keys(): if method in no_unlimited_runmodes.keys():
from freqtrade.data.btanalysis import get_latest_backtest_filename from freqtrade.data.btanalysis import get_latest_backtest_filename
btfile = Path(get_latest_backtest_filename(config['user_data_dir'] / 'backtest_results')) if 'exportfilename' in config:
signals_file = f"{btfile.stem}_signals.pkl" if config['exportfilename'].is_dir():
btfile = Path(get_latest_backtest_filename(config['exportfilename']))
signals_file = f"{config['exportfilename']}/{btfile.stem}_signals.pkl"
else:
if config['exportfilename'].exists():
btfile = Path(config['exportfilename'])
signals_file = f"{btfile.parent}/{btfile.stem}_signals.pkl"
else:
raise OperationalException(f"{config['exportfilename']} does not exist.")
else:
raise OperationalException('exportfilename not in config.')
if (not (config['user_data_dir'] / 'backtest_results' / signals_file).exists()): if (not Path(signals_file).exists()):
raise OperationalException( raise OperationalException(
"Cannot find latest backtest signals file. Run backtesting with --export signals." (f"Cannot find latest backtest signals file: {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 return config
@ -54,7 +60,7 @@ def start_analysis_entries_exits(args: Dict[str, Any]) -> None:
logger.info('Starting freqtrade in analysis mode') logger.info('Starting freqtrade in analysis mode')
process_entry_exit_reasons(Path(config['user_data_dir'], 'backtest_results'), process_entry_exit_reasons(config['exportfilename'],
config['exchange']['pair_whitelist'], config['exchange']['pair_whitelist'],
config['analysis_groups'], config['analysis_groups'],
config['enter_reason_list'], config['enter_reason_list'],

View File

@ -101,7 +101,7 @@ ARGS_HYPEROPT_SHOW = ["hyperopt_list_best", "hyperopt_list_profitable", "hyperop
"print_json", "hyperoptexportfilename", "hyperopt_show_no_header", "print_json", "hyperoptexportfilename", "hyperopt_show_no_header",
"disableparamexport", "backtest_breakdown"] "disableparamexport", "backtest_breakdown"]
ARGS_ANALYZE_ENTRIES_EXITS = ["analysis_groups", "enter_reason_list", ARGS_ANALYZE_ENTRIES_EXITS = ["exportfilename", "analysis_groups", "enter_reason_list",
"exit_reason_list", "indicator_list"] "exit_reason_list", "indicator_list"]
NO_CONF_REQURIED = ["convert-data", "convert-trade-data", "download-data", "list-timeframes", NO_CONF_REQURIED = ["convert-data", "convert-trade-data", "download-data", "list-timeframes",

View File

@ -20,7 +20,7 @@ def _load_signal_candles(backtest_dir: Path):
Path(get_latest_backtest_filename(backtest_dir)).stem + "_signals.pkl" Path(get_latest_backtest_filename(backtest_dir)).stem + "_signals.pkl"
) )
else: else:
scpf = Path(Path(get_latest_backtest_filename(backtest_dir)).stem + "_signals.pkl") scpf = Path(backtest_dir.parent / f"{backtest_dir.stem}_signals.pkl")
try: try:
scp = open(scpf, "rb") scp = open(scpf, "rb")