Remove unnecessary methods, improve docstring

This commit is contained in:
Matthias
2020-04-11 17:19:16 +02:00
parent 7e40bccdf8
commit 23c2e43cba
+14 -49
View File
@@ -3,12 +3,11 @@
import talib.abstract as ta
from pandas import DataFrame
from typing import Dict, Any, Callable, List
from functools import reduce
import numpy
# import numpy as np
from skopt.space import Categorical, Dimension, Integer, Real
import freqtrade.vendor.qtpylib.indicators as qtpylib
# import freqtrade.vendor.qtpylib.indicators as qtpylib
from freqtrade.optimize.hyperopt_interface import IHyperOpt
class_name = 'MACDStrategy_hyperopt'
@@ -17,20 +16,22 @@ class_name = 'MACDStrategy_hyperopt'
# This class is a sample. Feel free to customize it.
class MACDStrategy_hyperopt(IHyperOpt):
"""
This is a test hyperopt to inspire you.
This is an Example hyperopt to inspire you. - corresponding to MACDStrategy in this repository.
To run this, best use the following command (adjust to your environment
```
freqtrade hyperopt --strategy MACDStrategy --hyperopts MACDStrategy_hyperopt --spaces buy sell
```
The idea is to optimize only the CCI value.
- Buy side: CCI between -700 and 0
- Sell side: CCI between 0 and 700
More information in https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md
You can:
- Rename the class name (Do not forget to update class_name)
- Add any methods you want to build your hyperopt
- Add any lib you need to build your hyperopt
You must keep:
- the prototype for the methods: populate_indicators, indicator_space, buy_strategy_generator,
roi_space, generate_roi_table, stoploss_space
"""
"""
@staticmethod
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
macd = ta.MACD(dataframe)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
@@ -97,42 +98,6 @@ class MACDStrategy_hyperopt(IHyperOpt):
Integer(0, 700, name='sell-cci-value'),
]
@staticmethod
def generate_roi_table(params: Dict) -> Dict[int, float]:
"""
Generate the ROI table that will be used by Hyperopt
"""
roi_table = {}
roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']
roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']
roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0
return roi_table
@staticmethod
def stoploss_space() -> List[Dimension]:
"""
Stoploss Value to search
"""
return [
Real(-0.5, -0.02, name='stoploss'),
]
@staticmethod
def roi_space() -> List[Dimension]:
"""
Values to search for each ROI steps
"""
return [
Integer(10, 120, name='roi_t1'),
Integer(10, 60, name='roi_t2'),
Integer(10, 40, name='roi_t3'),
Real(0.01, 0.04, name='roi_p1'),
Real(0.01, 0.07, name='roi_p2'),
Real(0.01, 0.20, name='roi_p3'),
]
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators. Should be a copy of from strategy