Introduce File versions to hyperopt result files

This commit is contained in:
Matthias 2021-06-15 20:27:46 +02:00
parent a7e9e362b7
commit d4514f5f16
4 changed files with 14 additions and 10 deletions

View File

@ -5,6 +5,7 @@ from typing import Any, Dict, List
from colorama import init as colorama_init from colorama import init as colorama_init
from freqtrade.configuration import setup_utils_configuration from freqtrade.configuration import setup_utils_configuration
from freqtrade.constants import FTHYPT_FILEVERSION
from freqtrade.data.btanalysis import get_latest_hyperopt_file from freqtrade.data.btanalysis import get_latest_hyperopt_file
from freqtrade.enums import RunMode from freqtrade.enums import RunMode
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
@ -133,6 +134,7 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None:
show_backtest_result(strategy_name, metrics, show_backtest_result(strategy_name, metrics,
metrics['stake_currency']) metrics['stake_currency'])
if val.get(FTHYPT_FILEVERSION, 1) >= 2:
# Export parameters ... # Export parameters ...
# TODO: make this optional? otherwise it'll overwrite previous parameters ... # TODO: make this optional? otherwise it'll overwrite previous parameters ...
fn = HyperoptTools.get_strategy_filename(config, strategy_name) fn = HyperoptTools.get_strategy_filename(config, strategy_name)

View File

@ -40,6 +40,7 @@ DEFAULT_DATAFRAME_COLUMNS = ['date', 'open', 'high', 'low', 'close', 'volume']
DEFAULT_TRADES_COLUMNS = ['timestamp', 'id', 'type', 'side', 'price', 'amount', 'cost'] DEFAULT_TRADES_COLUMNS = ['timestamp', 'id', 'type', 'side', 'price', 'amount', 'cost']
LAST_BT_RESULT_FN = '.last_result.json' LAST_BT_RESULT_FN = '.last_result.json'
FTHYPT_FILEVERSION = 'fthypt_fileversion'
USERPATH_HYPEROPTS = 'hyperopts' USERPATH_HYPEROPTS = 'hyperopts'
USERPATH_STRATEGIES = 'strategies' USERPATH_STRATEGIES = 'strategies'

View File

@ -20,7 +20,7 @@ from colorama import init as colorama_init
from joblib import Parallel, cpu_count, delayed, dump, load, wrap_non_picklable_objects from joblib import Parallel, cpu_count, delayed, dump, load, wrap_non_picklable_objects
from pandas import DataFrame from pandas import DataFrame
from freqtrade.constants import DATETIME_PRINT_FORMAT, LAST_BT_RESULT_FN from freqtrade.constants import DATETIME_PRINT_FORMAT, FTHYPT_FILEVERSION, LAST_BT_RESULT_FN
from freqtrade.data.converter import trim_dataframes from freqtrade.data.converter import trim_dataframes
from freqtrade.data.history import get_timerange from freqtrade.data.history import get_timerange
from freqtrade.misc import deep_merge_dicts, file_dump_json, plural from freqtrade.misc import deep_merge_dicts, file_dump_json, plural
@ -167,7 +167,7 @@ class Hyperopt:
if isinstance(x, np.integer): if isinstance(x, np.integer):
return int(x) return int(x)
return str(x) return str(x)
epoch[FTHYPT_FILEVERSION] = 2
with self.results_file.open('a') as f: with self.results_file.open('a') as f:
rapidjson.dump(epoch, f, default=default_parser, rapidjson.dump(epoch, f, default=default_parser,
number_mode=rapidjson.NM_NATIVE | rapidjson.NM_NAN) number_mode=rapidjson.NM_NATIVE | rapidjson.NM_NAN)

View File

@ -46,7 +46,8 @@ class HyperoptTools():
final_params = deep_merge_dicts(params['params_details'], final_params) final_params = deep_merge_dicts(params['params_details'], final_params)
final_params = { final_params = {
'strategy_name': strategy_name, 'strategy_name': strategy_name,
'params': final_params 'params': final_params,
'ft_stratparam_v': 1,
} }
logger.info(f"Dumping parameters to {filename}") logger.info(f"Dumping parameters to {filename}")
rapidjson.dump(final_params, filename.open('w'), indent=2) rapidjson.dump(final_params, filename.open('w'), indent=2)