From c8d06e2b0e4db96e87f09a31a0ea07fe6dcfa900 Mon Sep 17 00:00:00 2001 From: misagh Date: Fri, 28 Sep 2018 16:40:34 +0200 Subject: [PATCH] filter pairs according to expectancy + bug at the end of array resolved --- config.json.example | 2 ++ freqtrade/edge/__init__.py | 18 +++++++++++------- freqtrade/freqtradebot.py | 2 +- freqtrade/tests/conftest.py | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config.json.example b/config.json.example index 83e9e0d38..2c1ef4fd0 100644 --- a/config.json.example +++ b/config.json.example @@ -53,12 +53,14 @@ "edge": { "enabled": false, "process_throttle_secs": 1800, + "calculate_since_number_of_days": 14, "total_capital_in_stake_currency": 0.5, "allowed_risk": 0.01, "stoploss_range_min": -0.01, "stoploss_range_max": -0.1, "stoploss_range_step": -0.001, "maximum_winrate": 0.80, + "minimum_expectancy": 0.20, "min_trade_number": 15, "max_trade_duration_minute": 1440, "remove_pumps": true, diff --git a/freqtrade/edge/__init__.py b/freqtrade/edge/__init__.py index f9549cd90..9789f2991 100644 --- a/freqtrade/edge/__init__.py +++ b/freqtrade/edge/__init__.py @@ -154,11 +154,14 @@ class Edge(): info = [x for x in self._cached_pairs if x[0] == pair][0] return info[1] - def sort_pairs(self, pairs) -> list: - if len(self._cached_pairs) == 0: - self.calculate() - edge_sorted_pairs = [x[0] for x in self._cached_pairs] - return [x for _, x in sorted(zip(edge_sorted_pairs, pairs), key=lambda pair: pair[0])] + def filter(self, pairs) -> list: + # Filtering pairs acccording to the expectancy + filtered_expectancy: list = [] + filtered_expectancy = [x[0] for x in self._cached_pairs if x[5] > float(self.edge_config.get('minimum_expectancy', 0.2))] + + # Only return pairs which are included in "pairs" argument list + final = [x for x in filtered_expectancy if x in pairs] + return final def _fill_calculable_fields(self, result: DataFrame): """ @@ -312,8 +315,9 @@ class Edge(): open_trade_index = utf1st.find_1st(buy_column, 1, utf1st.cmp_equal) # open_trade_index = np.argmax(buy_column == 1) - # return empty if we don't find trade entry (i.e. buy==1) - if open_trade_index == -1: + # return empty if we don't find trade entry (i.e. buy==1) or + # we find a buy but at the of array + if open_trade_index == -1 or open_trade_index == len(buy_column) - 1: return [] stop_price_percentage = stoploss + 1 diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 9ac0fd02f..299954e49 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -399,7 +399,7 @@ class FreqtradeBot(object): # running get_signal on historical data fetched # to find buy signals if self.config['edge']['enabled']: - whitelist = self.edge.sort_pairs(whitelist) + whitelist = self.edge.filter(whitelist) for _pair in whitelist: (buy, sell) = self.strategy.get_signal(_pair, interval, self.exchange.klines.get(_pair)) diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index 99c90d00a..c72cc5a40 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -132,12 +132,14 @@ def default_conf(): "edge": { "enabled": False, "process_throttle_secs": 1800, + "calculate_since_number_of_days": 14, "total_capital_in_stake_currency": 0.5, "allowed_risk": 0.01, "stoploss_range_min": -0.01, "stoploss_range_max": -0.1, "stoploss_range_step": -0.001, "maximum_winrate": 0.80, + "minimum_expectancy": 0.20, "min_trade_number": 15, "max_trade_duration_minute": 1440, "remove_pumps": True,