Apply special case for negative ROI

This commit is contained in:
Matthias 2019-12-07 15:18:12 +01:00
parent 1e6f9f9fe2
commit 3163cbdf8a
2 changed files with 12 additions and 6 deletions

View File

@ -267,7 +267,7 @@ class Backtesting:
# Set close_rate to stoploss # Set close_rate to stoploss
closerate = trade.stop_loss closerate = trade.stop_loss
elif sell.sell_type == (SellType.ROI): elif sell.sell_type == (SellType.ROI):
roi = self.strategy.min_roi_reached_entry(trade_dur) roi_entry, roi = self.strategy.min_roi_reached_entry(trade_dur)
if roi is not None: if roi is not None:
# - (Expected abs profit + open_rate + open_fee) / (fee_close -1) # - (Expected abs profit + open_rate + open_fee) / (fee_close -1)
closerate = - (trade.open_rate * roi + trade.open_rate * closerate = - (trade.open_rate * roi + trade.open_rate *
@ -275,8 +275,14 @@ class Backtesting:
# Use the maximum between closerate and low as we # Use the maximum between closerate and low as we
# cannot sell outside of a candle. # cannot sell outside of a candle.
# Applies when using {"xx": -1} as roi to force sells after xx minutes # Applies when a new ROI setting comes in place and the whole candle is above that.
closerate = max(closerate, sell_row.low) closerate = max(closerate, sell_row.low)
if roi == -1 and roi_entry % self.timeframe_mins == 0:
# When forceselling with ROI=-1, the roi-entry will always be "on the entry".
# If that entry is a multiple of the timeframe (so on open)
# - we'll use open instead of close
closerate = max(closerate, sell_row.open)
else: else:
# This should not be reached... # This should not be reached...
closerate = sell_row.open closerate = sell_row.open

View File

@ -394,7 +394,7 @@ class IStrategy(ABC):
return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE) return SellCheckTuple(sell_flag=False, sell_type=SellType.NONE)
def min_roi_reached_entry(self, trade_dur: int) -> Optional[float]: def min_roi_reached_entry(self, trade_dur: int) -> Tuple[Optional[int], Optional[float]]:
""" """
Based on trade duration defines the ROI entry that may have been reached. Based on trade duration defines the ROI entry that may have been reached.
:param trade_dur: trade duration in minutes :param trade_dur: trade duration in minutes
@ -403,9 +403,9 @@ class IStrategy(ABC):
# Get highest entry in ROI dict where key <= trade-duration # Get highest entry in ROI dict where key <= trade-duration
roi_list = list(filter(lambda x: x <= trade_dur, self.minimal_roi.keys())) roi_list = list(filter(lambda x: x <= trade_dur, self.minimal_roi.keys()))
if not roi_list: if not roi_list:
return None return None, None
roi_entry = max(roi_list) roi_entry = max(roi_list)
return self.minimal_roi[roi_entry] return roi_entry, self.minimal_roi[roi_entry]
def min_roi_reached(self, trade: Trade, current_profit: float, current_time: datetime) -> bool: def min_roi_reached(self, trade: Trade, current_profit: float, current_time: datetime) -> bool:
""" """
@ -415,7 +415,7 @@ class IStrategy(ABC):
""" """
# Check if time matches and current rate is above threshold # Check if time matches and current rate is above threshold
trade_dur = int((current_time.timestamp() - trade.open_date.timestamp()) // 60) trade_dur = int((current_time.timestamp() - trade.open_date.timestamp()) // 60)
roi = self.min_roi_reached_entry(trade_dur) _, roi = self.min_roi_reached_entry(trade_dur)
if roi is None: if roi is None:
return False return False
else: else: