Load latest file
This commit is contained in:
parent
ff96cf154c
commit
c42a924df8
@ -7,6 +7,7 @@ from colorama import init as colorama_init
|
|||||||
from freqtrade.configuration import setup_utils_configuration
|
from freqtrade.configuration import setup_utils_configuration
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.state import RunMode
|
from freqtrade.state import RunMode
|
||||||
|
from freqtrade.data.btanalysis import get_latest_hyperopt_file
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -40,8 +41,7 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None:
|
|||||||
'filter_max_objective': config.get('hyperopt_list_max_objective', None),
|
'filter_max_objective': config.get('hyperopt_list_max_objective', None),
|
||||||
}
|
}
|
||||||
|
|
||||||
results_file = (config['user_data_dir'] /
|
results_file = get_latest_hyperopt_file(config['user_data_dir'] / 'hyperopt_results')
|
||||||
'hyperopt_results' / 'hyperopt_results.pickle')
|
|
||||||
|
|
||||||
# Previous evaluations
|
# Previous evaluations
|
||||||
epochs = Hyperopt.load_previous_results(results_file)
|
epochs = Hyperopt.load_previous_results(results_file)
|
||||||
@ -80,8 +80,8 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None:
|
|||||||
|
|
||||||
print_json = config.get('print_json', False)
|
print_json = config.get('print_json', False)
|
||||||
no_header = config.get('hyperopt_show_no_header', False)
|
no_header = config.get('hyperopt_show_no_header', False)
|
||||||
results_file = (config['user_data_dir'] /
|
results_file = get_latest_hyperopt_file(config['user_data_dir'] / 'hyperopt_results')
|
||||||
'hyperopt_results' / 'hyperopt_results.pickle')
|
|
||||||
n = config.get('hyperopt_show_index', -1)
|
n = config.get('hyperopt_show_index', -1)
|
||||||
|
|
||||||
filteroptions = {
|
filteroptions = {
|
||||||
|
@ -21,10 +21,11 @@ BT_DATA_COLUMNS = ["pair", "profit_percent", "open_date", "close_date", "index",
|
|||||||
"open_rate", "close_rate", "open_at_end", "sell_reason"]
|
"open_rate", "close_rate", "open_at_end", "sell_reason"]
|
||||||
|
|
||||||
|
|
||||||
def get_latest_backtest_filename(directory: Union[Path, str]) -> str:
|
def get_latest_optimize_filename(directory: Union[Path, str], variant: str) -> str:
|
||||||
"""
|
"""
|
||||||
Get latest backtest export based on '.last_result.json'.
|
Get latest backtest export based on '.last_result.json'.
|
||||||
:param directory: Directory to search for last result
|
:param directory: Directory to search for last result
|
||||||
|
:param variant: 'backtest' or 'hyperopt' - the method to return
|
||||||
:return: string containing the filename of the latest backtest result
|
:return: string containing the filename of the latest backtest result
|
||||||
:raises: ValueError in the following cases:
|
:raises: ValueError in the following cases:
|
||||||
* Directory does not exist
|
* Directory does not exist
|
||||||
@ -44,10 +45,53 @@ def get_latest_backtest_filename(directory: Union[Path, str]) -> str:
|
|||||||
with filename.open() as file:
|
with filename.open() as file:
|
||||||
data = json_load(file)
|
data = json_load(file)
|
||||||
|
|
||||||
if 'latest_backtest' not in data:
|
if f'latest_{variant}' not in data:
|
||||||
raise ValueError(f"Invalid '{LAST_BT_RESULT_FN}' format.")
|
raise ValueError(f"Invalid '{LAST_BT_RESULT_FN}' format.")
|
||||||
|
|
||||||
return data['latest_backtest']
|
return data[f'latest_{variant}']
|
||||||
|
|
||||||
|
|
||||||
|
def get_latest_backtest_filename(directory: Union[Path, str]) -> str:
|
||||||
|
"""
|
||||||
|
Get latest backtest export based on '.last_result.json'.
|
||||||
|
:param directory: Directory to search for last result
|
||||||
|
:return: string containing the filename of the latest backtest result
|
||||||
|
:raises: ValueError in the following cases:
|
||||||
|
* Directory does not exist
|
||||||
|
* `directory/.last_result.json` does not exist
|
||||||
|
* `directory/.last_result.json` has the wrong content
|
||||||
|
"""
|
||||||
|
return get_latest_optimize_filename(directory, 'backtest')
|
||||||
|
|
||||||
|
|
||||||
|
def get_latest_hyperopt_filename(directory: Union[Path, str]) -> str:
|
||||||
|
"""
|
||||||
|
Get latest hyperopt export based on '.last_result.json'.
|
||||||
|
:param directory: Directory to search for last result
|
||||||
|
:return: string containing the filename of the latest hyperopt result
|
||||||
|
:raises: ValueError in the following cases:
|
||||||
|
* Directory does not exist
|
||||||
|
* `directory/.last_result.json` does not exist
|
||||||
|
* `directory/.last_result.json` has the wrong content
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return get_latest_optimize_filename(directory, 'hyperopt')
|
||||||
|
except ValueError:
|
||||||
|
# Return default (legacy) pickle filename
|
||||||
|
return 'hyperopt_results.pickle'
|
||||||
|
|
||||||
|
|
||||||
|
def get_latest_hyperopt_file(directory: Union[Path, str]) -> Path:
|
||||||
|
"""
|
||||||
|
Get latest hyperopt export based on '.last_result.json'.
|
||||||
|
:param directory: Directory to search for last result
|
||||||
|
:return: string containing the filename of the latest hyperopt result
|
||||||
|
:raises: ValueError in the following cases:
|
||||||
|
* Directory does not exist
|
||||||
|
* `directory/.last_result.json` does not exist
|
||||||
|
* `directory/.last_result.json` has the wrong content
|
||||||
|
"""
|
||||||
|
return directory / get_latest_hyperopt_filename(directory)
|
||||||
|
|
||||||
|
|
||||||
def load_backtest_stats(filename: Union[Path, str]) -> Dict[str, Any]:
|
def load_backtest_stats(filename: Union[Path, str]) -> Dict[str, Any]:
|
||||||
|
@ -657,8 +657,6 @@ class Hyperopt:
|
|||||||
self.backtesting.strategy.dp = None # type: ignore
|
self.backtesting.strategy.dp = None # type: ignore
|
||||||
IStrategy.dp = None # type: ignore
|
IStrategy.dp = None # type: ignore
|
||||||
|
|
||||||
self.epochs = self.load_previous_results(self.results_file)
|
|
||||||
|
|
||||||
cpus = cpu_count()
|
cpus = cpu_count()
|
||||||
logger.info(f"Found {cpus} CPU cores. Let's make them scream!")
|
logger.info(f"Found {cpus} CPU cores. Let's make them scream!")
|
||||||
config_jobs = self.config.get('hyperopt_jobs', -1)
|
config_jobs = self.config.get('hyperopt_jobs', -1)
|
||||||
|
@ -497,6 +497,7 @@ def test_no_log_if_loss_does_not_improve(hyperopt, caplog) -> None:
|
|||||||
def test_save_results_saves_epochs(mocker, hyperopt, testdatadir, caplog) -> None:
|
def test_save_results_saves_epochs(mocker, hyperopt, testdatadir, caplog) -> None:
|
||||||
epochs = create_results(mocker, hyperopt, testdatadir)
|
epochs = create_results(mocker, hyperopt, testdatadir)
|
||||||
mock_dump = mocker.patch('freqtrade.optimize.hyperopt.dump', return_value=None)
|
mock_dump = mocker.patch('freqtrade.optimize.hyperopt.dump', return_value=None)
|
||||||
|
mock_dump_json = mocker.patch('freqtrade.optimize.hyperopt.file_dump_json', return_value=None)
|
||||||
results_file = testdatadir / 'optimize' / 'ut_results.pickle'
|
results_file = testdatadir / 'optimize' / 'ut_results.pickle'
|
||||||
|
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
@ -505,6 +506,7 @@ def test_save_results_saves_epochs(mocker, hyperopt, testdatadir, caplog) -> Non
|
|||||||
hyperopt._save_results()
|
hyperopt._save_results()
|
||||||
assert log_has(f"1 epoch saved to '{results_file}'.", caplog)
|
assert log_has(f"1 epoch saved to '{results_file}'.", caplog)
|
||||||
mock_dump.assert_called_once()
|
mock_dump.assert_called_once()
|
||||||
|
mock_dump_json.assert_called_once()
|
||||||
|
|
||||||
hyperopt.epochs = epochs + epochs
|
hyperopt.epochs = epochs + epochs
|
||||||
hyperopt._save_results()
|
hyperopt._save_results()
|
||||||
|
Loading…
Reference in New Issue
Block a user