changed trades_space to max_open_trades_space

This commit is contained in:
Antonio Della Fortuna 2023-01-15 11:50:40 +01:00
parent 5e64980319
commit ab12aace5f
6 changed files with 11 additions and 10 deletions

View File

@ -75,7 +75,7 @@ This function needs to return a floating point number (`float`). Smaller numbers
## Overriding pre-defined spaces ## Overriding pre-defined spaces
To override a pre-defined space (`roi_space`, `generate_roi_table`, `stoploss_space`, `trailing_space`, `trades_space`), define a nested class called Hyperopt and define the required spaces as follows: To override a pre-defined space (`roi_space`, `generate_roi_table`, `stoploss_space`, `trailing_space`, `max_open_trades_space`), define a nested class called Hyperopt and define the required spaces as follows:
```python ```python
from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal
@ -125,7 +125,7 @@ class MyAwesomeStrategy(IStrategy):
] ]
# Define a custom max_open_trades space # Define a custom max_open_trades space
def trades_space(self) -> List[Dimension]: def max_open_trades_space(self) -> List[Dimension]:
return [ return [
Integer(-1, 10, name='max_open_trades'), Integer(-1, 10, name='max_open_trades'),
] ]

View File

@ -180,7 +180,7 @@ Rarely you may also need to create a [nested class](advanced-hyperopt.md#overrid
* `generate_roi_table` - for custom ROI optimization (if you need the ranges for the values in the ROI table that differ from default or the number of entries (steps) in the ROI table which differs from the default 4 steps) * `generate_roi_table` - for custom ROI optimization (if you need the ranges for the values in the ROI table that differ from default or the number of entries (steps) in the ROI table which differs from the default 4 steps)
* `stoploss_space` - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default) * `stoploss_space` - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default)
* `trailing_space` - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default) * `trailing_space` - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default)
* `trades_space` - for custom max_open_trades optimization (if you need the ranges for the max_open_trades parameter in the optimization hyperspace that differ from default) * `max_open_trades_space` - for custom max_open_trades optimization (if you need the ranges for the max_open_trades parameter in the optimization hyperspace that differ from default)
!!! Tip "Quickly optimize ROI, stoploss and trailing stoploss" !!! Tip "Quickly optimize ROI, stoploss and trailing stoploss"
You can quickly optimize the spaces `roi`, `stoploss` and `trailing` without changing anything in your strategy. You can quickly optimize the spaces `roi`, `stoploss` and `trailing` without changing anything in your strategy.

View File

@ -74,7 +74,7 @@ class Hyperopt:
self.roi_space: List[Dimension] = [] self.roi_space: List[Dimension] = []
self.stoploss_space: List[Dimension] = [] self.stoploss_space: List[Dimension] = []
self.trailing_space: List[Dimension] = [] self.trailing_space: List[Dimension] = []
self.trades_space: List[Dimension] = [] self.max_open_trades_space: List[Dimension] = []
self.dimensions: List[Dimension] = [] self.dimensions: List[Dimension] = []
self.config = config self.config = config
@ -288,11 +288,11 @@ class Hyperopt:
if HyperoptTools.has_space(self.config, 'trades'): if HyperoptTools.has_space(self.config, 'trades'):
logger.debug("Hyperopt has 'trades' space") logger.debug("Hyperopt has 'trades' space")
self.trades_space = self.custom_hyperopt.trades_space() self.max_open_trades_space = self.custom_hyperopt.max_open_trades_space()
self.dimensions = (self.buy_space + self.sell_space + self.protection_space self.dimensions = (self.buy_space + self.sell_space + self.protection_space
+ self.roi_space + self.stoploss_space + self.trailing_space + self.roi_space + self.stoploss_space + self.trailing_space
+ self.trades_space) + self.max_open_trades_space)
def assign_params(self, params_dict: Dict, category: str) -> None: def assign_params(self, params_dict: Dict, category: str) -> None:
""" """

View File

@ -91,8 +91,8 @@ class HyperOptAuto(IHyperOpt):
def trailing_space(self) -> List['Dimension']: def trailing_space(self) -> List['Dimension']:
return self._get_func('trailing_space')() return self._get_func('trailing_space')()
def trades_space(self) -> List['Dimension']: def max_open_trades_space(self) -> List['Dimension']:
return self._get_func('trades_space')() return self._get_func('max_open_trades_space')()
def generate_estimator(self, dimensions: List['Dimension'], **kwargs) -> EstimatorType: def generate_estimator(self, dimensions: List['Dimension'], **kwargs) -> EstimatorType:
return self._get_func('generate_estimator')(dimensions=dimensions, **kwargs) return self._get_func('generate_estimator')(dimensions=dimensions, **kwargs)

View File

@ -191,7 +191,7 @@ class IHyperOpt(ABC):
Categorical([True, False], name='trailing_only_offset_is_reached'), Categorical([True, False], name='trailing_only_offset_is_reached'),
] ]
def trades_space(self) -> List[Dimension]: def max_open_trades_space(self) -> List[Dimension]:
""" """
Create a max open trades space. Create a max open trades space.

View File

@ -1088,7 +1088,8 @@ def test_max_open_trades_consistency(mocker, hyperopt_conf, tmpdir, fee) -> None
assert isinstance(hyperopt.custom_hyperopt, HyperOptAuto) assert isinstance(hyperopt.custom_hyperopt, HyperOptAuto)
hyperopt.custom_hyperopt.trades_space = lambda: [Integer(1, 10, name='max_open_trades')] hyperopt.custom_hyperopt.max_open_trades_space = lambda: [
Integer(1, 10, name='max_open_trades')]
first_time_evaluated = False first_time_evaluated = False