add --epochs to hyperopt subcommand

This commit is contained in:
gcarq 2017-11-25 01:12:44 +01:00
parent b9c4eafd96
commit 9ff1f05e66
4 changed files with 34 additions and 8 deletions

View File

@ -159,7 +159,14 @@ def build_subcommands(parser: argparse.ArgumentParser) -> None:
# Add hyperopt subcommand
hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module')
hyperopt_cmd.set_defaults(func=hyperopt.start)
hyperopt_cmd.add_argument(
'-e', '--epochs',
help='specify number of epochs (default: 100)',
dest='epochs',
default=100,
type=int,
metavar='INT',
)
# Required json-schema for user specified config
CONF_SCHEMA = {

View File

@ -151,6 +151,7 @@ def start(args):
print('Using max_open_trades: {} ...'.format(config['max_open_trades']))
max_open_trades = config['max_open_trades']
# Monkey patch config
from freqtrade import main
main._CONF = config

View File

@ -16,8 +16,7 @@ from freqtrade.vendor.qtpylib.indicators import crossed_above
# set TARGET_TRADES to suit your number concurrent trades so its realistic to 20days of data
TARGET_TRADES = 1100
TOTAL_TRIES = 4
# pylint: disable=C0103
current_tries = 0
_CURRENT_TRIES = 0
# Configuration and data used by hyperopt
PROCESSED = optimize.preprocess(optimize.load_data())
@ -85,6 +84,8 @@ SPACE = {
def optimizer(params):
global _CURRENT_TRIES
from freqtrade.optimize import backtesting
backtesting.populate_buy_trend = buy_strategy_generator(params)
@ -98,10 +99,8 @@ def optimizer(params):
trade_loss = 1 - 0.35 * exp(-(trade_count - TARGET_TRADES) ** 2 / 10 ** 5.2)
profit_loss = max(0, 1 - total_profit / 10000) # max profit 10000
# pylint: disable=W0603
global current_tries
current_tries += 1
print('{:5d}/{}: {}'.format(current_tries, TOTAL_TRIES, result))
_CURRENT_TRIES += 1
print('{:5d}/{}: {}'.format(_CURRENT_TRIES, TOTAL_TRIES, result))
return {
'loss': trade_loss + profit_loss,
@ -166,7 +165,12 @@ def buy_strategy_generator(params):
def start(args):
# TODO: parse args
global TOTAL_TRIES
TOTAL_TRIES = args.epochs
# Monkey patch config
from freqtrade import main
main._CONF = OPTIMIZE_CONFIG
exchange._API = Bittrex({'key': '', 'secret': ''})

View File

@ -112,6 +112,20 @@ def test_parse_args_hyperopt(mocker):
assert call_args.func is not None
def test_parse_args_hyperopt_custom(mocker):
hyperopt_mock = mocker.patch('freqtrade.optimize.hyperopt.start', MagicMock())
args = parse_args(['-c', 'test_conf.json', 'hyperopt', '--epochs', '20'])
assert args is None
assert hyperopt_mock.call_count == 1
call_args = hyperopt_mock.call_args[0][0]
assert call_args.config == 'test_conf.json'
assert call_args.epochs == 20
assert call_args.loglevel == 20
assert call_args.subparser == 'hyperopt'
assert call_args.func is not None
def test_load_config(default_conf, mocker):
file_mock = mocker.patch('freqtrade.misc.open', mocker.mock_open(
read_data=json.dumps(default_conf)