2017-11-25 00:04:11 +00:00
|
|
|
# pragma pylint: disable=missing-docstring
|
|
|
|
|
2018-03-25 19:37:14 +00:00
|
|
|
import logging
|
2018-10-18 17:42:54 +00:00
|
|
|
from datetime import datetime
|
2018-12-13 05:12:10 +00:00
|
|
|
from typing import List, Dict, Tuple
|
2018-10-17 17:59:33 +00:00
|
|
|
import operator
|
|
|
|
|
2018-04-27 21:16:34 +00:00
|
|
|
import arrow
|
2018-10-17 17:59:33 +00:00
|
|
|
from pandas import DataFrame
|
2018-01-18 07:10:48 +00:00
|
|
|
|
2018-12-13 05:12:10 +00:00
|
|
|
|
2018-06-05 21:34:26 +00:00
|
|
|
from freqtrade.arguments import TimeRange
|
2018-11-07 18:46:04 +00:00
|
|
|
from freqtrade.optimize.default_hyperopt import DefaultHyperOpts # noqa: F401
|
2018-04-27 21:16:34 +00:00
|
|
|
|
2018-03-25 19:37:14 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2017-12-16 14:42:28 +00:00
|
|
|
|
2017-11-25 00:04:11 +00:00
|
|
|
|
2018-10-17 17:59:33 +00:00
|
|
|
def get_timeframe(data: Dict[str, DataFrame]) -> Tuple[arrow.Arrow, arrow.Arrow]:
|
|
|
|
"""
|
|
|
|
Get the maximum timeframe for the given backtest data
|
|
|
|
:param data: dictionary with preprocessed backtesting data
|
|
|
|
:return: tuple containing min_date, max_date
|
|
|
|
"""
|
|
|
|
timeframe = [
|
|
|
|
(arrow.get(frame['date'].min()), arrow.get(frame['date'].max()))
|
|
|
|
for frame in data.values()
|
|
|
|
]
|
|
|
|
return min(timeframe, key=operator.itemgetter(0))[0], \
|
|
|
|
max(timeframe, key=operator.itemgetter(1))[1]
|
|
|
|
|
|
|
|
|
2018-10-18 17:42:54 +00:00
|
|
|
def validate_backtest_data(data: Dict[str, DataFrame], min_date: datetime,
|
2018-10-18 17:48:54 +00:00
|
|
|
max_date: datetime, ticker_interval_mins: int) -> bool:
|
2018-10-18 17:42:54 +00:00
|
|
|
"""
|
|
|
|
Validates preprocessed backtesting data for missing values and shows warnings about it that.
|
|
|
|
|
|
|
|
:param data: dictionary with preprocessed backtesting data
|
|
|
|
:param min_date: start-date of the data
|
|
|
|
:param max_date: end-date of the data
|
|
|
|
:param ticker_interval_mins: ticker interval in minutes
|
|
|
|
"""
|
|
|
|
# total difference in minutes / interval-minutes
|
|
|
|
expected_frames = int((max_date - min_date).total_seconds() // 60 // ticker_interval_mins)
|
2018-10-18 17:48:54 +00:00
|
|
|
found_missing = False
|
2018-10-18 17:42:54 +00:00
|
|
|
for pair, df in data.items():
|
2018-10-18 18:05:57 +00:00
|
|
|
dflen = len(df)
|
|
|
|
if dflen < expected_frames:
|
2018-10-18 17:48:54 +00:00
|
|
|
found_missing = True
|
2018-10-18 18:05:57 +00:00
|
|
|
logger.warning("%s has missing frames: expected %s, got %s, that's %s missing values",
|
|
|
|
pair, expected_frames, dflen, expected_frames - dflen)
|
2018-10-18 17:48:54 +00:00
|
|
|
return found_missing
|