From a021cd3ae2755f889c0fd47af25b202cc0326ce9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 30 Dec 2018 16:07:47 +0100 Subject: [PATCH] Add ohlcv data interpolator --- freqtrade/data/converter.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/freqtrade/data/converter.py b/freqtrade/data/converter.py index ee915ec19..71a7e35a4 100644 --- a/freqtrade/data/converter.py +++ b/freqtrade/data/converter.py @@ -5,6 +5,8 @@ import logging import pandas as pd from pandas import DataFrame, to_datetime +from freqtrade.constants import TICKER_INTERVAL_MINUTES + logger = logging.getLogger(__name__) @@ -36,6 +38,35 @@ def parse_ticker_dataframe(ticker: list) -> DataFrame: return frame +def ohlcv_fill_up_missing_data(dataframe: DataFrame, ticker_interval: str) -> DataFrame: + """ + Fills up missing data with 0 volume rows, + using the previous close as price for "open", "high" "low" and "close", volume is set to 0 + + """ + ohlc_dict = { + 'open': 'first', + 'high': 'max', + 'low': 'min', + 'close': 'last', + 'volume': 'sum' + } + tick_mins = TICKER_INTERVAL_MINUTES[ticker_interval] + # Resample to create "NAN" values + df = dataframe.resample(f'{tick_mins}min', on='date').agg(ohlc_dict) + + # Forwardfill close for missing columns + df['close'] = df['close'].fillna(method='ffill') + # Use close for "open, high, low" + df.loc[:, ['open', 'high', 'low']] = df[['open', 'high', 'low']].fillna( + value={'open': df['close'], + 'high': df['close'], + 'low': df['close'], + }) + df.reset_index(inplace=True) + return df + + def order_book_to_dataframe(bids: list, asks: list) -> DataFrame: """ Gets order book list, returns dataframe with below format per suggested by creslin