Skip to content

Commit

Permalink
Merge pull request freqtrade#1247 from freqtrade/fix_hyperopt_pickle
Browse files Browse the repository at this point in the history
Fix hyperopt pickle
  • Loading branch information
xmatthias authored Sep 30, 2018
2 parents e1dddda + 84622dc commit 3af3094
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
9 changes: 8 additions & 1 deletion freqtrade/optimize/hyperopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def calculate_loss(self, total_profit: float, trade_count: int, trade_duration:
@staticmethod
def generate_roi_table(params: Dict) -> Dict[int, float]:
"""
Generate the ROI table thqt will be used by Hyperopt
Generate the ROI table that will be used by Hyperopt
"""
roi_table = {}
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
Expand Down Expand Up @@ -402,6 +402,13 @@ def start(args: Namespace) -> None:
config['exchange']['key'] = ''
config['exchange']['secret'] = ''

if config.get('strategy') and config.get('strategy') != 'DefaultStrategy':
logger.error("Please don't use --strategy for hyperopt.")
logger.error(
"Read the documentation at "
"https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md "
"to understand how to configure hyperopt.")
raise ValueError("--strategy configured but not supported for hyperopt")
# Initialize backtesting object
hyperopt = Hyperopt(config)
hyperopt.start()
3 changes: 2 additions & 1 deletion freqtrade/strategy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from copy import deepcopy

from freqtrade.strategy.interface import IStrategy

# Import Default-Strategy to have hyperopt correctly resolve
from freqtrade.strategy.default_strategy import DefaultStrategy # noqa: F401

logger = logging.getLogger(__name__)

Expand Down
25 changes: 25 additions & 0 deletions freqtrade/tests/optimize/test_hyperopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ def test_start(mocker, default_conf, caplog) -> None:
assert start_mock.call_count == 1


def test_start_failure(mocker, default_conf, caplog) -> None:
start_mock = MagicMock()
mocker.patch(
'freqtrade.configuration.Configuration._load_config_file',
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.optimize.hyperopt.Hyperopt.start', start_mock)
patch_exchange(mocker)

args = [
'--config', 'config.json',
'--strategy', 'TestStrategy',
'hyperopt',
'--epochs', '5'
]
args = get_args(args)
StrategyResolver({'strategy': 'DefaultStrategy'})
with pytest.raises(ValueError):
start(args)
assert log_has(
"Please don't use --strategy for hyperopt.",
caplog.record_tuples
)


def test_loss_calculation_prefer_correct_trade_count(hyperopt) -> None:
StrategyResolver({'strategy': 'DefaultStrategy'})

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requests==2.19.1
urllib3==1.22
wrapt==1.10.11
pandas==0.23.4
scikit-learn==0.19.2
scikit-learn==0.20.0
scipy==1.1.0
jsonschema==2.6.0
numpy==1.15.2
Expand Down

0 comments on commit 3af3094

Please sign in to comment.