moved dynamic ROI to its own function in the strategy interface
This commit is contained in:
parent
39ffcecffa
commit
db5e038b0f
@ -628,18 +628,16 @@ 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) -> Tuple[Optional[int], Optional[float]]:
|
def min_roi_reached_dynamic(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 returns an ROI value based on various functions.
|
||||||
:param trade_dur: trade duration in minutes
|
:param trade_dur: trade duration in minutes
|
||||||
:return: minimal ROI entry value or None if none proper ROI entry was found.
|
:return: minimal ROI value or None if no proper ROI type was found.
|
||||||
"""
|
"""
|
||||||
dynamic_roi = self.dynamic_roi
|
dynamic_roi = self.dynamic_roi
|
||||||
minimal_roi = self.minimal_roi
|
minimal_roi = self.minimal_roi
|
||||||
start, end = dynamic_roi['dynamic_roi_start'], dynamic_roi['dynamic_roi_end']
|
start, end = dynamic_roi['dynamic_roi_start'], dynamic_roi['dynamic_roi_end']
|
||||||
|
|
||||||
# if the dynamic_roi dict is defined and enabled, use it, otherwise fallback to default functionality
|
|
||||||
if dynamic_roi and dynamic_roi['dynamic_roi_enabled']:
|
|
||||||
# linear decay: f(t) = start - (rate * t)
|
# linear decay: f(t) = start - (rate * t)
|
||||||
if dynamic_roi['dynamic_roi_type'] == 'linear':
|
if dynamic_roi['dynamic_roi_type'] == 'linear':
|
||||||
rate = (start - end) / dynamic_roi['dynamic_roi_time']
|
rate = (start - end) / dynamic_roi['dynamic_roi_time']
|
||||||
@ -654,6 +652,7 @@ class IStrategy(ABC):
|
|||||||
if not past_roi:
|
if not past_roi:
|
||||||
return None, None
|
return None, None
|
||||||
current_entry = max(past_roi)
|
current_entry = max(past_roi)
|
||||||
|
# if we are past the final point in the table, use that key/vaule pair
|
||||||
if not next_roi:
|
if not next_roi:
|
||||||
return current_entry, minimal_roi[current_entry]
|
return current_entry, minimal_roi[current_entry]
|
||||||
# use the slope-intercept formula between the two points in the roi table we are between
|
# use the slope-intercept formula between the two points in the roi table we are between
|
||||||
@ -666,11 +665,16 @@ class IStrategy(ABC):
|
|||||||
b = (x1*y2 - x2*y1)/(x1-x2)
|
b = (x1*y2 - x2*y1)/(x1-x2)
|
||||||
min_roi = (m * trade_dur) + b
|
min_roi = (m * trade_dur) + b
|
||||||
else:
|
else:
|
||||||
min_roi = 0
|
return None, None
|
||||||
|
|
||||||
return trade_dur, min_roi
|
return trade_dur, min_roi
|
||||||
# Default ROI table functionality
|
|
||||||
else:
|
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.
|
||||||
|
:param trade_dur: trade duration in minutes
|
||||||
|
:return: minimal ROI entry value or None if none proper ROI entry was found.
|
||||||
|
"""
|
||||||
# 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:
|
||||||
@ -687,6 +691,9 @@ 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_utc.timestamp()) // 60)
|
trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60)
|
||||||
|
if self.dynamic_roi and self.dynamic_roi['dynamic_roi_enabled']:
|
||||||
|
_, roi = self.min_roi_reached_dynamic(trade_dur)
|
||||||
|
else:
|
||||||
_, 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
|
||||||
|
Loading…
Reference in New Issue
Block a user