diff --git a/docs/advanced-hyperopt.md b/docs/advanced-hyperopt.md index 20af0aaab..25b4bd900 100644 --- a/docs/advanced-hyperopt.md +++ b/docs/advanced-hyperopt.md @@ -4,6 +4,34 @@ This page explains some advanced Hyperopt topics that may require higher coding skills and Python knowledge than creation of an ordinal hyperoptimization class. +## Derived hyperopt classes + +Custom hyperop classes can be derived in the same way [it can be done for strategies](strategy-customization.md#derived-strategies). + +Applying to hyperoptimization, as an example, you may override how dimensions are defined in your optimization hyperspace: + +```python +class MyAwesomeHyperOpt(IHyperOpt): + ... + # Uses default stoploss dimension + +class MyAwesomeHyperOpt2(MyAwesomeHyperOpt): + @staticmethod + def stoploss_space() -> List[Dimension]: + # Override boundaries for stoploss + return [ + Real(-0.33, -0.01, name='stoploss'), + ] +``` + +and then quickly switch between hyperopt classes, running optimization process with hyperopt class you need in each particular case: + +``` +$ freqtrade hyperopt --hyperopt MyAwesomeHyperOpt ... +or +$ freqtrade hyperopt --hyperopt MyAwesomeHyperOpt2 ... +``` + ## Creating and using a custom loss function To use a custom loss function class, make sure that the function `hyperopt_loss_function` is defined in your custom hyperopt loss class. diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index d59b097d7..688647c2b 100644 --- a/docs/strategy-customization.md +++ b/docs/strategy-customization.md @@ -532,6 +532,27 @@ If you want to use a strategy from a different directory you can pass `--strateg freqtrade trade --strategy AwesomeStrategy --strategy-path /some/directory ``` +### Derived strategies + +The strategies can be derived from other strategies. This avoids duplication of your custom strategy code. You can use this technique to override small parts of your main strategy, leaving the rest untouched: + +``` python +class MyAwesomeStrategy(IStrategy): + ... + stoploss = 0.13 + trailing_stop = False + # All other attributes and methods are here as they + # should be in any custom strategy... + ... + +class MyAwesomeStrategy2(MyAwesomeStrategy): + # Override something + stoploss = 0.08 + trailing_stop = True +``` + +Both attributes and methods may be overriden, altering behavior of the original strategy in a way you need. + ### Common mistakes when developing strategies Backtesting analyzes the whole time-range at once for performance reasons. Because of this, strategy authors need to make sure that strategies do not look-ahead into the future. diff --git a/freqtrade/resolvers/iresolver.py b/freqtrade/resolvers/iresolver.py index 3aec5f9e9..a75c45933 100644 --- a/freqtrade/resolvers/iresolver.py +++ b/freqtrade/resolvers/iresolver.py @@ -61,7 +61,8 @@ class IResolver: valid_objects_gen = ( obj for name, obj in inspect.getmembers(module, inspect.isclass) - if (object_name is None or object_name == name) and cls.object_type in obj.__bases__ + if ((object_name is None or object_name == name) and + issubclass(obj, cls.object_type) and obj is not cls.object_type) ) return valid_objects_gen