add tests for IntParameter.range
This commit is contained in:
parent
90476c4287
commit
5c7f278c8a
@ -6,6 +6,7 @@ import pandas as pd
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.optimize.hyperopt import Hyperopt
|
from freqtrade.optimize.hyperopt import Hyperopt
|
||||||
|
from freqtrade.state import RunMode
|
||||||
from freqtrade.strategy.interface import SellType
|
from freqtrade.strategy.interface import SellType
|
||||||
from tests.conftest import patch_exchange
|
from tests.conftest import patch_exchange
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ def hyperopt_conf(default_conf):
|
|||||||
hyperconf = deepcopy(default_conf)
|
hyperconf = deepcopy(default_conf)
|
||||||
hyperconf.update({
|
hyperconf.update({
|
||||||
'datadir': Path(default_conf['datadir']),
|
'datadir': Path(default_conf['datadir']),
|
||||||
|
'runmode': RunMode.HYPEROPT,
|
||||||
'hyperopt': 'DefaultHyperOpt',
|
'hyperopt': 'DefaultHyperOpt',
|
||||||
'hyperopt_loss': 'ShortTradeDurHyperOptLoss',
|
'hyperopt_loss': 'ShortTradeDurHyperOptLoss',
|
||||||
'hyperopt_path': str(Path(__file__).parent / 'hyperopts'),
|
'hyperopt_path': str(Path(__file__).parent / 'hyperopts'),
|
||||||
|
@ -21,6 +21,7 @@ from freqtrade.optimize.hyperopt_tools import HyperoptTools
|
|||||||
from freqtrade.optimize.space import SKDecimal
|
from freqtrade.optimize.space import SKDecimal
|
||||||
from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver
|
from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver
|
||||||
from freqtrade.state import RunMode
|
from freqtrade.state import RunMode
|
||||||
|
from freqtrade.strategy.hyper import IntParameter
|
||||||
from tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
|
from tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
|
||||||
patched_configuration_load_config_file)
|
patched_configuration_load_config_file)
|
||||||
|
|
||||||
@ -1103,6 +1104,14 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir) -> None:
|
|||||||
})
|
})
|
||||||
hyperopt = Hyperopt(hyperopt_conf)
|
hyperopt = Hyperopt(hyperopt_conf)
|
||||||
assert isinstance(hyperopt.custom_hyperopt, HyperOptAuto)
|
assert isinstance(hyperopt.custom_hyperopt, HyperOptAuto)
|
||||||
|
assert isinstance(hyperopt.backtesting.strategy.buy_rsi, IntParameter)
|
||||||
|
|
||||||
|
assert hyperopt.backtesting.strategy.buy_rsi.hyperopt is True
|
||||||
|
assert hyperopt.backtesting.strategy.buy_rsi.value == 35
|
||||||
|
buy_rsi_range = hyperopt.backtesting.strategy.buy_rsi.range
|
||||||
|
assert isinstance(buy_rsi_range, range)
|
||||||
|
# Range from 0 - 50 (inclusive)
|
||||||
|
assert len(list(buy_rsi_range)) == 51
|
||||||
|
|
||||||
hyperopt.start()
|
hyperopt.start()
|
||||||
|
|
||||||
|
@ -588,6 +588,14 @@ def test_hyperopt_parameters():
|
|||||||
intpar = IntParameter(low=0, high=5, default=1, space='buy')
|
intpar = IntParameter(low=0, high=5, default=1, space='buy')
|
||||||
assert intpar.value == 1
|
assert intpar.value == 1
|
||||||
assert isinstance(intpar.get_space(''), Integer)
|
assert isinstance(intpar.get_space(''), Integer)
|
||||||
|
assert isinstance(intpar.range, range)
|
||||||
|
assert len(list(intpar.range)) == 1
|
||||||
|
# Range contains ONLY the default / value.
|
||||||
|
assert list(intpar.range) == [intpar.value]
|
||||||
|
intpar.hyperopt = True
|
||||||
|
|
||||||
|
assert len(list(intpar.range)) == 6
|
||||||
|
assert list(intpar.range) == [0, 1, 2, 3, 4, 5]
|
||||||
|
|
||||||
fltpar = RealParameter(low=0.0, high=5.5, default=1.0, space='buy')
|
fltpar = RealParameter(low=0.0, high=5.5, default=1.0, space='buy')
|
||||||
assert isinstance(fltpar.get_space(''), Real)
|
assert isinstance(fltpar.get_space(''), Real)
|
||||||
|
Loading…
Reference in New Issue
Block a user