From 37e4ede65c674c898193a828d72feb90a92c5ea4 Mon Sep 17 00:00:00 2001 From: froggleston Date: Tue, 17 May 2022 22:32:17 +0100 Subject: [PATCH] Fix flake issues --- docs/leverage.md | 5 +++-- freqtrade/data/history/history_utils.py | 4 ++-- freqtrade/optimize/backtesting.py | 19 ++++++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/leverage.md b/docs/leverage.md index d8a9c8032..0c8139ad3 100644 --- a/docs/leverage.md +++ b/docs/leverage.md @@ -105,8 +105,9 @@ Possible values are any floats between 0.0 and 0.99 For futures data, exchanges commonly provide the futures candles, the marks, and the funding rates. However, it is common that whilst candles and marks might be available, the funding rates are not. This can affect backtesting timeranges, i.e. you may only be able to test recent timeranges and not earlier, experiencing the `No data found. Terminating.` error. To get around this, add the `futures_funding_rate` config option as listed in [configuration.md](configuration.md), and it is recommended that you set this to `0`, unless you know a given specific funding rate for your pair, exchange and timerange. Setting this to anything other than `0` can have drastic effects on your profit calculations within strategy, e.g. within the `custom_exit`, `custom_stoploss`, etc functions. -!!! This will not overwrite funding rates that are available from the exchange. - +!!! Warning This will mean your backtests are inaccurate. + This will not overwrite funding rates that are available from the exchange, but bear in mind that setting a false funding rate will mean backtesting results will be inaccurate for historical timeranges where funding rates are not available. + ### Developer #### Margin mode diff --git a/freqtrade/data/history/history_utils.py b/freqtrade/data/history/history_utils.py index b589001ca..4600d6ab4 100644 --- a/freqtrade/data/history/history_utils.py +++ b/freqtrade/data/history/history_utils.py @@ -69,7 +69,7 @@ def load_data(datadir: Path, fail_without_data: bool = False, data_format: str = 'json', candle_type: CandleType = CandleType.SPOT, - user_futures_funding_rate = None, + user_futures_funding_rate: int = None, ) -> Dict[str, DataFrame]: """ Load ohlcv history data for a list of pairs. @@ -104,7 +104,7 @@ def load_data(datadir: Path, else: if candle_type is CandleType.FUNDING_RATE and user_futures_funding_rate is not None: logger.warn(f"{pair} using user specified [{user_futures_funding_rate}]") - result[pair] = DataFrame(columns=["open","close","high","low","volume"]) + result[pair] = DataFrame(columns=["open", "close", "high", "low", "volume"]) if fail_without_data and not result: raise OperationalException("No data found. Terminating.") diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 49b085ca1..8d5a5fcea 100755 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -277,25 +277,26 @@ class Backtesting: continue if (pair in mark_rates_dict - and len(funding_rates_dict[pair]) == 0 - and "futures_funding_rate" in self.config): + and len(funding_rates_dict[pair]) == 0 + and "futures_funding_rate" in self.config): mark_rates_dict[pair]["open_fund"] = self.config.get('futures_funding_rate') mark_rates_dict[pair]["close_fund"] = 0.0 mark_rates_dict[pair]["high_fund"] = 0.0 mark_rates_dict[pair]["low_fund"] = 0.0 mark_rates_dict[pair]["volume_fund"] = 0.0 mark_rates_dict[pair].rename( - columns = {'open':'open_mark', - 'close':'close_mark', - 'high':'high_mark', - 'low':'low_mark', - 'volume':'volume_mark'}, - inplace = True) + columns={'open': 'open_mark', + 'close': 'close_mark', + 'high': 'high_mark', + 'low': 'low_mark', + 'volume': 'volume_mark'}, + inplace=True) self.futures_data[pair] = mark_rates_dict[pair] else: self.futures_data[pair] = mark_rates_dict[pair].merge( - funding_rates_dict[pair], on='date', how="inner", suffixes=["_fund", "_mark"]) + funding_rates_dict[pair], on='date', + how="inner", suffixes=["_fund", "_mark"]) if unavailable_pairs: raise OperationalException(