add --epochs to hyperopt subcommand
This commit is contained in:
parent
b9c4eafd96
commit
9ff1f05e66
@ -159,7 +159,14 @@ def build_subcommands(parser: argparse.ArgumentParser) -> None:
|
|||||||
# Add hyperopt subcommand
|
# Add hyperopt subcommand
|
||||||
hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module')
|
hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module')
|
||||||
hyperopt_cmd.set_defaults(func=hyperopt.start)
|
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
|
# Required json-schema for user specified config
|
||||||
CONF_SCHEMA = {
|
CONF_SCHEMA = {
|
||||||
|
@ -151,6 +151,7 @@ def start(args):
|
|||||||
print('Using max_open_trades: {} ...'.format(config['max_open_trades']))
|
print('Using max_open_trades: {} ...'.format(config['max_open_trades']))
|
||||||
max_open_trades = config['max_open_trades']
|
max_open_trades = config['max_open_trades']
|
||||||
|
|
||||||
|
# Monkey patch config
|
||||||
from freqtrade import main
|
from freqtrade import main
|
||||||
main._CONF = config
|
main._CONF = config
|
||||||
|
|
||||||
|
@ -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
|
# set TARGET_TRADES to suit your number concurrent trades so its realistic to 20days of data
|
||||||
TARGET_TRADES = 1100
|
TARGET_TRADES = 1100
|
||||||
TOTAL_TRIES = 4
|
TOTAL_TRIES = 4
|
||||||
# pylint: disable=C0103
|
_CURRENT_TRIES = 0
|
||||||
current_tries = 0
|
|
||||||
|
|
||||||
# Configuration and data used by hyperopt
|
# Configuration and data used by hyperopt
|
||||||
PROCESSED = optimize.preprocess(optimize.load_data())
|
PROCESSED = optimize.preprocess(optimize.load_data())
|
||||||
@ -85,6 +84,8 @@ SPACE = {
|
|||||||
|
|
||||||
|
|
||||||
def optimizer(params):
|
def optimizer(params):
|
||||||
|
global _CURRENT_TRIES
|
||||||
|
|
||||||
from freqtrade.optimize import backtesting
|
from freqtrade.optimize import backtesting
|
||||||
backtesting.populate_buy_trend = buy_strategy_generator(params)
|
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)
|
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
|
profit_loss = max(0, 1 - total_profit / 10000) # max profit 10000
|
||||||
|
|
||||||
# pylint: disable=W0603
|
_CURRENT_TRIES += 1
|
||||||
global current_tries
|
print('{:5d}/{}: {}'.format(_CURRENT_TRIES, TOTAL_TRIES, result))
|
||||||
current_tries += 1
|
|
||||||
print('{:5d}/{}: {}'.format(current_tries, TOTAL_TRIES, result))
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'loss': trade_loss + profit_loss,
|
'loss': trade_loss + profit_loss,
|
||||||
@ -166,7 +165,12 @@ def buy_strategy_generator(params):
|
|||||||
|
|
||||||
|
|
||||||
def start(args):
|
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': ''})
|
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||||
|
|
||||||
|
@ -112,6 +112,20 @@ def test_parse_args_hyperopt(mocker):
|
|||||||
assert call_args.func is not None
|
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):
|
def test_load_config(default_conf, mocker):
|
||||||
file_mock = mocker.patch('freqtrade.misc.open', mocker.mock_open(
|
file_mock = mocker.patch('freqtrade.misc.open', mocker.mock_open(
|
||||||
read_data=json.dumps(default_conf)
|
read_data=json.dumps(default_conf)
|
||||||
|
Loading…
Reference in New Issue
Block a user