From 537596001e5c4ff030855327095992c48d205724 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Mon, 3 Feb 2020 06:20:01 +0300 Subject: [PATCH 1/6] Allow derived strategies --- freqtrade/resolvers/iresolver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/freqtrade/resolvers/iresolver.py b/freqtrade/resolvers/iresolver.py index 5a844097c..53d08d387 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 From 2846f9454fdf48cf90493f91d19f790ddf51cb61 Mon Sep 17 00:00:00 2001 From: hroff-1902 <47309513+hroff-1902@users.noreply.github.com> Date: Thu, 6 Feb 2020 17:02:11 +0300 Subject: [PATCH 2/6] Add description in the docs --- docs/strategy-customization.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index d59b097d7..cc3f8ee33 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: + +``` +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. The strategy classes may be located in the same module (python file with the source code of your strategy) or in different modules (different python files). In the latter case you need to properly import the strategy class you derive the new one from. + ### 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. From 412f5d68de2eeefa9b306e5b2604cb695dfc317a Mon Sep 17 00:00:00 2001 From: hroff-1902 <47309513+hroff-1902@users.noreply.github.com> Date: Thu, 6 Feb 2020 17:42:26 +0300 Subject: [PATCH 3/6] Add description to hyperopt advanced doc chapter --- docs/advanced-hyperopt.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/advanced-hyperopt.md b/docs/advanced-hyperopt.md index 20af0aaab..f47c33880 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: + +``` +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. From 2034527faa4c96d518f9a0506799fac89f1f0f56 Mon Sep 17 00:00:00 2001 From: hroff-1902 <47309513+hroff-1902@users.noreply.github.com> Date: Thu, 6 Feb 2020 17:45:15 +0300 Subject: [PATCH 4/6] Update docs/strategy-customization.md Co-Authored-By: Matthias --- docs/strategy-customization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index cc3f8ee33..717baf4db 100644 --- a/docs/strategy-customization.md +++ b/docs/strategy-customization.md @@ -536,7 +536,7 @@ freqtrade trade --strategy AwesomeStrategy --strategy-path /some/directory 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 From 418e7adac159d30e48a21cb09c4547c432fbf67e Mon Sep 17 00:00:00 2001 From: hroff-1902 <47309513+hroff-1902@users.noreply.github.com> Date: Thu, 6 Feb 2020 17:49:10 +0300 Subject: [PATCH 5/6] Highlight syntax in advanced-hyperopt as well --- docs/advanced-hyperopt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced-hyperopt.md b/docs/advanced-hyperopt.md index f47c33880..25b4bd900 100644 --- a/docs/advanced-hyperopt.md +++ b/docs/advanced-hyperopt.md @@ -10,7 +10,7 @@ Custom hyperop classes can be derived in the same way [it can be done for strate 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 From f57bd6b616872904c68dee27fcd3c5814e67d486 Mon Sep 17 00:00:00 2001 From: hroff-1902 <47309513+hroff-1902@users.noreply.github.com> Date: Thu, 6 Feb 2020 21:53:03 +0300 Subject: [PATCH 6/6] Keep the docs clean for unexperienced users --- docs/strategy-customization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index 717baf4db..688647c2b 100644 --- a/docs/strategy-customization.md +++ b/docs/strategy-customization.md @@ -551,7 +551,7 @@ class MyAwesomeStrategy2(MyAwesomeStrategy): trailing_stop = True ``` -Both attributes and methods may be overriden, altering behavior of the original strategy in a way you need. The strategy classes may be located in the same module (python file with the source code of your strategy) or in different modules (different python files). In the latter case you need to properly import the strategy class you derive the new one from. +Both attributes and methods may be overriden, altering behavior of the original strategy in a way you need. ### Common mistakes when developing strategies