2018-01-28 07:38:41 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, protected-access, C0103
|
2019-04-04 17:56:40 +00:00
|
|
|
from freqtrade import optimize
|
2018-06-05 21:53:49 +00:00
|
|
|
from freqtrade.arguments import TimeRange
|
2018-12-13 05:35:42 +00:00
|
|
|
from freqtrade.data import history
|
2019-04-09 09:27:35 +00:00
|
|
|
from freqtrade.exchange import timeframe_to_minutes
|
2018-10-17 17:59:33 +00:00
|
|
|
from freqtrade.strategy.default_strategy import DefaultStrategy
|
2018-12-13 05:35:42 +00:00
|
|
|
from freqtrade.tests.conftest import log_has, patch_exchange
|
2018-10-17 17:59:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_timeframe(default_conf, mocker) -> None:
|
|
|
|
patch_exchange(mocker)
|
|
|
|
strategy = DefaultStrategy(default_conf)
|
|
|
|
|
|
|
|
data = strategy.tickerdata_to_dataframe(
|
2018-12-13 05:35:42 +00:00
|
|
|
history.load_data(
|
2018-12-15 19:14:13 +00:00
|
|
|
datadir=None,
|
2018-10-17 17:59:33 +00:00
|
|
|
ticker_interval='1m',
|
|
|
|
pairs=['UNITTEST/BTC']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
min_date, max_date = optimize.get_timeframe(data)
|
|
|
|
assert min_date.isoformat() == '2017-11-04T23:02:00+00:00'
|
|
|
|
assert max_date.isoformat() == '2017-11-14T22:58:00+00:00'
|
2018-10-18 17:42:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_validate_backtest_data_warn(default_conf, mocker, caplog) -> None:
|
|
|
|
patch_exchange(mocker)
|
|
|
|
strategy = DefaultStrategy(default_conf)
|
|
|
|
|
|
|
|
data = strategy.tickerdata_to_dataframe(
|
2018-12-13 05:35:42 +00:00
|
|
|
history.load_data(
|
2018-12-15 19:14:13 +00:00
|
|
|
datadir=None,
|
2018-10-18 17:42:54 +00:00
|
|
|
ticker_interval='1m',
|
2018-12-31 18:15:05 +00:00
|
|
|
pairs=['UNITTEST/BTC'],
|
|
|
|
fill_up_missing=False
|
2018-10-18 17:42:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
min_date, max_date = optimize.get_timeframe(data)
|
|
|
|
caplog.clear()
|
2018-10-18 17:48:54 +00:00
|
|
|
assert optimize.validate_backtest_data(data, min_date, max_date,
|
2019-04-04 17:56:40 +00:00
|
|
|
timeframe_to_minutes('1m'))
|
2018-10-18 17:42:54 +00:00
|
|
|
assert len(caplog.record_tuples) == 1
|
2018-10-18 18:05:57 +00:00
|
|
|
assert log_has(
|
|
|
|
"UNITTEST/BTC has missing frames: expected 14396, got 13680, that's 716 missing values",
|
|
|
|
caplog.record_tuples)
|
2018-10-18 17:42:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_validate_backtest_data(default_conf, mocker, caplog) -> None:
|
|
|
|
patch_exchange(mocker)
|
|
|
|
strategy = DefaultStrategy(default_conf)
|
|
|
|
|
|
|
|
timerange = TimeRange('index', 'index', 200, 250)
|
|
|
|
data = strategy.tickerdata_to_dataframe(
|
2018-12-13 05:35:42 +00:00
|
|
|
history.load_data(
|
2018-12-15 19:14:13 +00:00
|
|
|
datadir=None,
|
2018-10-18 17:42:54 +00:00
|
|
|
ticker_interval='5m',
|
|
|
|
pairs=['UNITTEST/BTC'],
|
|
|
|
timerange=timerange
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
min_date, max_date = optimize.get_timeframe(data)
|
|
|
|
caplog.clear()
|
2018-10-18 17:48:54 +00:00
|
|
|
assert not optimize.validate_backtest_data(data, min_date, max_date,
|
2019-04-04 17:56:40 +00:00
|
|
|
timeframe_to_minutes('5m'))
|
2018-10-18 17:42:54 +00:00
|
|
|
assert len(caplog.record_tuples) == 0
|