Make BinHV45 use hyperoptable parameters (removes hyperopt file)
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
# --- Do not remove these libs ---
|
||||
from functools import reduce
|
||||
from typing import Any, Callable, Dict, List
|
||||
|
||||
import numpy as np # noqa
|
||||
import pandas as pd # noqa
|
||||
from pandas import DataFrame
|
||||
from skopt.space import Categorical, Dimension, Integer, Real # noqa
|
||||
|
||||
from freqtrade.optimize.hyperopt_interface import IHyperOpt
|
||||
|
||||
# --------------------------------
|
||||
# Add your lib to import here
|
||||
import talib.abstract as ta # noqa
|
||||
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
||||
|
||||
|
||||
class BinHV45HyperOpt(IHyperOpt):
|
||||
"""
|
||||
Hyperopt file for optimizing BinHV45Strategy.
|
||||
Uses ranges to find best parameter combination for bbdelta, closedelta and tail
|
||||
of the buy strategy.
|
||||
|
||||
Sell strategy is ignored, because it's ignored in BinHV45Strategy as well.
|
||||
This strategy therefor works without explicit sell signal therefor hyperopting
|
||||
for 'roi' is recommend as well
|
||||
|
||||
Also, this is just ONE way to optimize this strategy - others might also include
|
||||
disabling certain conditions completely. This file is just a starting point, feel free
|
||||
to improve and PR.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def buy_strategy_generator(params: Dict[str, Any]) -> Callable:
|
||||
"""
|
||||
Define the buy strategy parameters to be used by Hyperopt.
|
||||
"""
|
||||
def populate_buy_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
"""
|
||||
Buy strategy Hyperopt will build and use.
|
||||
"""
|
||||
conditions = []
|
||||
|
||||
conditions.append(dataframe['lower'].shift().gt(0))
|
||||
conditions.append(dataframe['bbdelta'].gt(
|
||||
dataframe['close'] * params['bbdelta'] / 1000))
|
||||
conditions.append(dataframe['closedelta'].gt(
|
||||
dataframe['close'] * params['closedelta'] / 1000))
|
||||
conditions.append(dataframe['tail'].lt(dataframe['bbdelta'] * params['tail'] / 1000))
|
||||
conditions.append(dataframe['close'].lt(dataframe['lower'].shift()))
|
||||
conditions.append(dataframe['close'].le(dataframe['close'].shift()))
|
||||
|
||||
# Check that the candle had volume
|
||||
conditions.append(dataframe['volume'] > 0)
|
||||
|
||||
if conditions:
|
||||
dataframe.loc[
|
||||
reduce(lambda x, y: x & y, conditions),
|
||||
'buy'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
return populate_buy_trend
|
||||
|
||||
@staticmethod
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching buy strategy parameters.
|
||||
"""
|
||||
return [
|
||||
Integer(1, 15, name='bbdelta'),
|
||||
Integer(15, 20, name='closedelta'),
|
||||
Integer(20, 30, name='tail'),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def sell_strategy_generator(params: Dict[str, Any]) -> Callable:
|
||||
"""
|
||||
Define the sell strategy parameters to be used by Hyperopt.
|
||||
"""
|
||||
def populate_sell_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
"""
|
||||
no sell signal
|
||||
"""
|
||||
dataframe['sell'] = 0
|
||||
return dataframe
|
||||
|
||||
return populate_sell_trend
|
||||
|
||||
@staticmethod
|
||||
def sell_indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
Define your Hyperopt space for searching sell strategy parameters.
|
||||
"""
|
||||
return []
|
||||
@@ -1,7 +1,6 @@
|
||||
# --- Do not remove these libs ---
|
||||
from freqtrade.strategy.interface import IStrategy
|
||||
from typing import Dict, List
|
||||
from functools import reduce
|
||||
from freqtrade.strategy import IStrategy
|
||||
from freqtrade.strategy import IntParameter
|
||||
from pandas import DataFrame
|
||||
import numpy as np
|
||||
# --------------------------------
|
||||
@@ -19,6 +18,8 @@ def bollinger_bands(stock_price, window_size, num_of_std):
|
||||
|
||||
|
||||
class BinHV45(IStrategy):
|
||||
INTERFACE_VERSION = 2
|
||||
|
||||
minimal_roi = {
|
||||
"0": 0.0125
|
||||
}
|
||||
@@ -26,10 +27,23 @@ class BinHV45(IStrategy):
|
||||
stoploss = -0.05
|
||||
timeframe = '1m'
|
||||
|
||||
buy_bbdelta = IntParameter(low=1, high=15, default=30, space='buy', optimize=True)
|
||||
buy_closedelta = IntParameter(low=15, high=20, default=30, space='buy', optimize=True)
|
||||
buy_tail = IntParameter(low=20, high=30, default=30, space='buy', optimize=True)
|
||||
|
||||
# Hyperopt parameters
|
||||
buy_params = {
|
||||
"buy_bbdelta": 7,
|
||||
"buy_closedelta": 17,
|
||||
"buy_tail": 25,
|
||||
}
|
||||
|
||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
mid, lower = bollinger_bands(dataframe['close'], window_size=40, num_of_std=2)
|
||||
dataframe['mid'] = np.nan_to_num(mid)
|
||||
dataframe['lower'] = np.nan_to_num(lower)
|
||||
bollinger = qtpylib.bollinger_bands(dataframe['close'], window=40, stds=2)
|
||||
|
||||
dataframe['upper'] = bollinger['upper']
|
||||
dataframe['mid'] = bollinger['mid']
|
||||
dataframe['lower'] = bollinger['lower']
|
||||
dataframe['bbdelta'] = (dataframe['mid'] - dataframe['lower']).abs()
|
||||
dataframe['pricedelta'] = (dataframe['open'] - dataframe['close']).abs()
|
||||
dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs()
|
||||
@@ -40,9 +54,9 @@ class BinHV45(IStrategy):
|
||||
dataframe.loc[
|
||||
(
|
||||
dataframe['lower'].shift().gt(0) &
|
||||
dataframe['bbdelta'].gt(dataframe['close'] * 0.008) &
|
||||
dataframe['closedelta'].gt(dataframe['close'] * 0.0175) &
|
||||
dataframe['tail'].lt(dataframe['bbdelta'] * 0.25) &
|
||||
dataframe['bbdelta'].gt(dataframe['close'] * self.buy_bbdelta.value / 1000) &
|
||||
dataframe['closedelta'].gt(dataframe['close'] * self.buy_closedelta.value / 1000) &
|
||||
dataframe['tail'].lt(dataframe['bbdelta'] * self.buy_tail.value / 1000) &
|
||||
dataframe['close'].lt(dataframe['lower'].shift()) &
|
||||
dataframe['close'].le(dataframe['close'].shift())
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user