integrate hyperopt and implement subcommand

This commit is contained in:
gcarq
2017-11-25 01:04:11 +01:00
parent 7fa5846c6b
commit b9c4eafd96
9 changed files with 191 additions and 167 deletions

View File

@@ -1,21 +0,0 @@
# pragma pylint: disable=missing-docstring
import json
import os
from typing import Optional, List
def load_backtesting_data(ticker_interval: int = 5, pairs: Optional[List[str]] = None):
path = os.path.abspath(os.path.dirname(__file__))
result = {}
_pairs = pairs or [
'BTC_BCC', 'BTC_ETH', 'BTC_DASH', 'BTC_POWR', 'BTC_ETC',
'BTC_VTC', 'BTC_WAVES', 'BTC_LSK', 'BTC_XLM', 'BTC_OK',
]
for pair in _pairs:
with open('{abspath}/testdata/{pair}-{ticker_interval}.json'.format(
abspath=path,
pair=pair,
ticker_interval=ticker_interval,
)) as tickerdata:
result[pair] = json.load(tickerdata)
return result

View File

@@ -51,22 +51,6 @@ def default_conf():
return configuration
@pytest.fixture(scope="module")
def backtest_conf():
return {
"max_open_trades": 3,
"stake_currency": "BTC",
"stake_amount": 0.01,
"minimal_roi": {
"40": 0.0,
"30": 0.01,
"20": 0.02,
"0": 0.04
},
"stoploss": -0.10
}
@pytest.fixture
def update():
_update = Update(0)

View File

@@ -78,10 +78,10 @@ def test_parse_args_backtesting(mocker):
def test_parse_args_backtesting_invalid():
with pytest.raises(SystemExit, match=r'2'):
parse_args(['--ticker-interval'])
parse_args(['backtesting --ticker-interval'])
with pytest.raises(SystemExit, match=r'2'):
parse_args(['--ticker-interval', 'abc'])
parse_args(['backtesting --ticker-interval', 'abc'])
def test_parse_args_backtesting_custom(mocker):
@@ -99,6 +99,19 @@ def test_parse_args_backtesting_custom(mocker):
assert call_args.ticker_interval == 1
def test_parse_args_hyperopt(mocker):
hyperopt_mock = mocker.patch('freqtrade.optimize.hyperopt.start', MagicMock())
args = parse_args(['hyperopt'])
assert args is None
assert hyperopt_mock.call_count == 1
call_args = hyperopt_mock.call_args[0][0]
assert call_args.config == 'config.json'
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)

View File

@@ -1,18 +1,16 @@
# pragma pylint: disable=missing-docstring,W0212
from freqtrade import exchange
from freqtrade import exchange, optimize
from freqtrade.exchange import Bittrex
from freqtrade.optimize.backtesting import backtest, preprocess
from freqtrade.tests import load_backtesting_data
from freqtrade.optimize.backtesting import backtest
def test_backtest(backtest_conf, mocker):
mocker.patch.dict('freqtrade.main._CONF', backtest_conf)
def test_backtest(default_conf, mocker):
mocker.patch.dict('freqtrade.main._CONF', default_conf)
exchange._API = Bittrex({'key': '', 'secret': ''})
data = load_backtesting_data(ticker_interval=5, pairs=['BTC_ETH'])
results = backtest(backtest_conf, preprocess(data), 10, True)
data = optimize.load_data(ticker_interval=5, pairs=['BTC_ETH'])
results = backtest(default_conf, optimize.preprocess(data), 10, True)
num_resutls = len(results)
assert num_resutls > 0

View File

@@ -0,0 +1,6 @@
# pragma pylint: disable=missing-docstring,W0212
def test_optimizer(default_conf, mocker):
# TODO: implement test
pass