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:
froggleston
2022-05-17 22:05:33 +01:00
parent 7b9439f2e4
commit bb758da940
4 changed files with 34 additions and 3 deletions

View File

@@ -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(