flake8 cleanup
This commit is contained in:
parent
6ac220982c
commit
a3d6b472a7
@ -643,14 +643,23 @@ In order to use these best dynamic ROI parameters found by Hyperopt in backtesti
|
||||
If you are optimizing dynamic ROI values, Freqtrade creates the 'dynamic-roi' optimization hyperspace for you. By default, the `enabled` parameter will try both True and False values. The value the `type` vary between `linear`, `exponential`, and `connect`.
|
||||
|
||||
Other values have default ranges of:
|
||||
|
||||
| Param | Range |
|
||||
|------------|-------------|
|
||||
| decay-time | 180..1440 |
|
||||
| decay-rate | 0.001..0.03 |
|
||||
| start | 0.05..0.25 |
|
||||
| end | 0..0.005 |
|
||||
|
||||
Override the `dynamic_roi_space()` method and define the desired range in it if you want values of the dynamic ROI parameters to vary in other ranges during hyperoptimization. A sample for this method can be found in [user_data/hyperopts/sample_hyperopt_advanced.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py).
|
||||
Just as the standard ROI table, the time decay value (in minutes) has a range which varies based on your candle size, for example:
|
||||
|
||||
| Candle | Range |
|
||||
|----------|---------------|
|
||||
| 1m | 30..144 |
|
||||
| 5m | 150..720 |
|
||||
| 1h | 1800..8640 |
|
||||
| 1d | 3456..207360 |
|
||||
|
||||
It is **highly** recommended to override the `dynamic_roi_space()` method and define the desired ranges in it if you want values of the dynamic ROI parameters to vary in other ranges during hyperoptimization. A sample for this method can be found in [user_data/hyperopts/sample_hyperopt_advanced.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/templates/sample_hyperopt_advanced.py).
|
||||
|
||||
## Show details of Hyperopt results
|
||||
|
||||
|
@ -500,7 +500,7 @@ class Hyperopt:
|
||||
if space == 'roi' or (space is None and self.has_space('roi')):
|
||||
logger.debug("Hyperopt has 'roi' space")
|
||||
spaces += self.custom_hyperopt.roi_space()
|
||||
|
||||
|
||||
if space == 'dynamic-roi' or (space is None and self.has_space('dynamic-roi')):
|
||||
logger.debug("Hyperopt has 'dynamic-roi' space")
|
||||
spaces += self.custom_hyperopt.dynamic_roi_space()
|
||||
@ -526,7 +526,7 @@ class Hyperopt:
|
||||
if self.has_space('roi'):
|
||||
self.backtesting.strategy.minimal_roi = ( # type: ignore
|
||||
self.custom_hyperopt.generate_roi_table(params_dict))
|
||||
|
||||
|
||||
if self.has_space('dynamic-roi'):
|
||||
self.backtesting.strategy.dynamic_roi = ( # type: ignore
|
||||
self.custom_hyperopt.generate_dynamic_roi_table(params_dict))
|
||||
|
@ -238,14 +238,14 @@ class IHyperOpt(ABC):
|
||||
Create a dynamic ROI space.
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
"""
|
||||
"""
|
||||
# Time and percentage scaling are the same as in roi_space()
|
||||
# Refer to the notes there for additional details
|
||||
roi_t_alpha = 1.0
|
||||
timeframe_min = timeframe_to_minutes(IHyperOpt.ticker_interval)
|
||||
roi_t_scale = timeframe_min / 5
|
||||
|
||||
# scaled range in minutes
|
||||
# scaled range in minutes
|
||||
# candle min max
|
||||
# 1m 30 144
|
||||
# 5m 150 720
|
||||
@ -263,7 +263,6 @@ class IHyperOpt(ABC):
|
||||
Real(0, 0.005, name='dynamic_roi_end')
|
||||
]
|
||||
|
||||
|
||||
# This is needed for proper unpickling the class attribute ticker_interval
|
||||
# which is set to the actual value by the resolver.
|
||||
# Why do I still need such shamanic mantras in modern python?
|
||||
|
@ -637,21 +637,21 @@ class IStrategy(ABC):
|
||||
"""
|
||||
dynamic_roi = self.dynamic_roi
|
||||
minimal_roi = self.minimal_roi
|
||||
|
||||
|
||||
if not dynamic_roi:
|
||||
return None, None
|
||||
|
||||
if 'dynamic_roi_type' in dynamic_roi and dynamic_roi['dynamic_roi_type'] \
|
||||
in ['linear', 'exponential', 'connect']:
|
||||
in ['linear', 'exponential', 'connect']:
|
||||
roi_type = dynamic_roi['dynamic_roi_type']
|
||||
# linear decay: f(t) = start - (rate * t)
|
||||
if roi_type == 'linear':
|
||||
if 'dynamic_roi_start' in dynamic_roi and 'dynamic_roi_end' in dynamic_roi and \
|
||||
'dynamic_roi_time' in dynamic_roi:
|
||||
start = dynamic_roi['dynamic_roi_start']
|
||||
end = dynamic_roi['dynamic_roi_end']
|
||||
time = dynamic_roi['dynamic_roi_time']
|
||||
rate = (start - end) / time
|
||||
end = dynamic_roi['dynamic_roi_end']
|
||||
time = dynamic_roi['dynamic_roi_time']
|
||||
rate = (start - end) / time
|
||||
min_roi = max(end, start - (rate * trade_dur))
|
||||
return trade_dur, min_roi
|
||||
else:
|
||||
@ -661,8 +661,8 @@ class IStrategy(ABC):
|
||||
if 'dynamic_roi_start' in dynamic_roi and 'dynamic_roi_end' in dynamic_roi and \
|
||||
'dynamic_roi_rate' in dynamic_roi:
|
||||
start = dynamic_roi['dynamic_roi_start']
|
||||
end = dynamic_roi['dynamic_roi_end']
|
||||
rate = dynamic_roi['dynamic_roi_rate']
|
||||
end = dynamic_roi['dynamic_roi_end']
|
||||
rate = dynamic_roi['dynamic_roi_rate']
|
||||
min_roi = max(end, start * np.exp(-rate*trade_dur))
|
||||
return trade_dur, min_roi
|
||||
else:
|
||||
@ -673,7 +673,7 @@ class IStrategy(ABC):
|
||||
return None, None
|
||||
# figure out where we are in the defined roi table
|
||||
past_roi = list(filter(lambda x: x <= trade_dur, minimal_roi.keys()))
|
||||
next_roi = list(filter(lambda x: x > trade_dur, minimal_roi.keys()))
|
||||
next_roi = list(filter(lambda x: x > trade_dur, minimal_roi.keys()))
|
||||
# if we are past the final point in the table, use that key/vaule pair
|
||||
if not past_roi:
|
||||
return None, None
|
||||
@ -714,9 +714,9 @@ class IStrategy(ABC):
|
||||
"""
|
||||
# Check if time matches and current rate is above threshold
|
||||
trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60)
|
||||
|
||||
|
||||
if self.dynamic_roi and 'dynamic_roi_enabled' in self.dynamic_roi \
|
||||
and self.dynamic_roi['dynamic_roi_enabled']:
|
||||
and self.dynamic_roi['dynamic_roi_enabled']:
|
||||
_, roi = self.min_roi_reached_dynamic(trade_dur)
|
||||
else:
|
||||
_, roi = self.min_roi_reached_entry(trade_dur)
|
||||
|
@ -275,10 +275,10 @@ class AdvancedSampleHyperOpt(IHyperOpt):
|
||||
|
||||
You may override it in your custom Hyperopt class.
|
||||
|
||||
If you are reducing the types, you may also remove the parameters that will not be used on the
|
||||
reduced scope. For example, if you reduce the types to only 'connect' you do not need to specify
|
||||
the ranges for decay-rate, decay-time, start, or end.
|
||||
"""
|
||||
If you are reducing the types, you may also remove the parameters that will not be used on
|
||||
the reduced scope. For example, if you reduce the types to only 'connect' you do not
|
||||
need to specify the ranges for decay-rate, decay-time, start, or end.
|
||||
"""
|
||||
return [
|
||||
Categorical([True, False], name='dynamic_roi_enabled'),
|
||||
Categorical(['linear', 'exponential', 'connect'], name='dynamic_roi_type'),
|
||||
|
Loading…
Reference in New Issue
Block a user