2022-05-22 22:34:31 +00:00
|
|
|
import logging
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Any, Dict
|
|
|
|
|
|
|
|
from freqtrade.configuration import setup_utils_configuration
|
|
|
|
from freqtrade.enums import RunMode
|
|
|
|
from freqtrade.exceptions import OperationalException
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_analyze_configuration(args: Dict[str, Any], method: RunMode) -> Dict[str, Any]:
|
|
|
|
"""
|
|
|
|
Prepare the configuration for the entry/exit reason analysis module
|
|
|
|
:param args: Cli args from Arguments()
|
|
|
|
:param method: Bot running mode
|
|
|
|
:return: Configuration
|
|
|
|
"""
|
|
|
|
config = setup_utils_configuration(args, method)
|
|
|
|
|
|
|
|
no_unlimited_runmodes = {
|
|
|
|
RunMode.BACKTEST: 'backtesting',
|
|
|
|
}
|
|
|
|
if method in no_unlimited_runmodes.keys():
|
|
|
|
from freqtrade.data.btanalysis import get_latest_backtest_filename
|
|
|
|
|
2022-05-24 11:48:13 +00:00
|
|
|
btfile = Path(get_latest_backtest_filename(config['user_data_dir'] / 'backtest_results'))
|
|
|
|
signals_file = f"{btfile.stem}_signals.pkl"
|
2022-05-22 22:34:31 +00:00
|
|
|
|
2022-05-24 11:48:13 +00:00
|
|
|
if (not (config['user_data_dir'] / 'backtest_results' / signals_file).exists()):
|
2022-05-22 22:34:31 +00:00
|
|
|
raise OperationalException(
|
|
|
|
"Cannot find latest backtest signals file. Run backtesting with --export signals."
|
|
|
|
)
|
|
|
|
|
2022-05-24 11:48:13 +00:00
|
|
|
if ('strategy' not in config):
|
|
|
|
raise OperationalException(
|
|
|
|
"No strategy defined. Use --strategy or supply in config."
|
|
|
|
)
|
|
|
|
|
2022-05-22 22:34:31 +00:00
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def start_analysis_entries_exits(args: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
Start analysis script
|
|
|
|
:param args: Cli args from Arguments()
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
from freqtrade.data.entryexitanalysis import process_entry_exit_reasons
|
|
|
|
|
|
|
|
# Initialize configuration
|
|
|
|
config = setup_analyze_configuration(args, RunMode.BACKTEST)
|
|
|
|
|
|
|
|
logger.info('Starting freqtrade in analysis mode')
|
|
|
|
|
|
|
|
process_entry_exit_reasons(Path(config['user_data_dir'], 'backtest_results'),
|
|
|
|
config['exchange']['pair_whitelist'],
|
|
|
|
config['analysis_groups'],
|
|
|
|
config['enter_reason_list'],
|
|
|
|
config['exit_reason_list'],
|
|
|
|
config['indicator_list']
|
|
|
|
)
|