freqtrade_origin/freqtrade/optimize/__init__.py

50 lines
1.8 KiB
Python
Raw Normal View History

# 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:37:07 +00:00
from typing import Dict, Tuple
import operator
import arrow
from pandas import DataFrame
2018-01-18 07:10:48 +00:00
2018-11-07 18:46:04 +00:00
from freqtrade.optimize.default_hyperopt import DefaultHyperOpts # noqa: F401
2018-03-25 19:37:14 +00:00
logger = logging.getLogger(__name__)
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,
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)
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:
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)
return found_missing