Add support for fudging unavailable funding rates, allowing backtesting of timeranges where futures candles are available, but rates are not
This commit is contained in:
@@ -68,7 +68,8 @@ def load_data(datadir: Path,
|
||||
startup_candles: int = 0,
|
||||
fail_without_data: bool = False,
|
||||
data_format: str = 'json',
|
||||
candle_type: CandleType = CandleType.SPOT
|
||||
candle_type: CandleType = CandleType.SPOT,
|
||||
user_futures_funding_rate = None,
|
||||
) -> Dict[str, DataFrame]:
|
||||
"""
|
||||
Load ohlcv history data for a list of pairs.
|
||||
@@ -100,6 +101,10 @@ def load_data(datadir: Path,
|
||||
)
|
||||
if not hist.empty:
|
||||
result[pair] = hist
|
||||
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"])
|
||||
|
||||
if fail_without_data and not result:
|
||||
raise OperationalException("No data found. Terminating.")
|
||||
|
@@ -275,8 +275,27 @@ class Backtesting:
|
||||
if pair not in self.exchange._leverage_tiers:
|
||||
unavailable_pairs.append(pair)
|
||||
continue
|
||||
self.futures_data[pair] = funding_rates_dict[pair].merge(
|
||||
mark_rates_dict[pair], on='date', how="inner", suffixes=["_fund", "_mark"])
|
||||
|
||||
if (pair in mark_rates_dict
|
||||
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)
|
||||
|
||||
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"])
|
||||
|
||||
if unavailable_pairs:
|
||||
raise OperationalException(
|
||||
|
Reference in New Issue
Block a user