From cf03daa0fd60e9a2ae2769a89bbde4cfb92d62f0 Mon Sep 17 00:00:00 2001 From: Antreas Gribas Date: Fri, 30 Apr 2021 00:28:42 +0300 Subject: [PATCH 1/5] Fix bug in running hyperopt in windows 10 with preferred encoding in locale differrent from utf-8 --- freqtrade/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/freqtrade/__init__.py b/freqtrade/__init__.py index e96e7f530..30ad96b33 100644 --- a/freqtrade/__init__.py +++ b/freqtrade/__init__.py @@ -1,6 +1,11 @@ """ Freqtrade bot """ __version__ = 'develop' +import locale +def getpreferredencoding(do_setlocale=True): + return "utf-8" +locale.getpreferredencoding = getpreferredencoding + if __version__ == 'develop': try: From 30da307d137e997d2d0c8590fa403e3e29a2f49f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 1 May 2021 17:01:52 +0200 Subject: [PATCH 2/5] Remove encode/decode for hyperopt --- freqtrade/__init__.py | 5 ----- freqtrade/optimize/hyperopt.py | 3 +-- tests/optimize/test_hyperopt.py | 3 +-- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/freqtrade/__init__.py b/freqtrade/__init__.py index 30ad96b33..e96e7f530 100644 --- a/freqtrade/__init__.py +++ b/freqtrade/__init__.py @@ -1,11 +1,6 @@ """ Freqtrade bot """ __version__ = 'develop' -import locale -def getpreferredencoding(do_setlocale=True): - return "utf-8" -locale.getpreferredencoding = getpreferredencoding - if __version__ == 'develop': try: diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index d1dabff36..6f899aba6 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -4,7 +4,6 @@ This module contains the hyperopt logic """ -import locale import logging import random import warnings @@ -354,7 +353,7 @@ class Hyperopt: f"Total profit {results_metrics['total_profit']: 11.8f} {stake_cur} " f"({results_metrics['profit']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). " f"Avg duration {results_metrics['duration']:5.1f} min." - ).encode(locale.getpreferredencoding(), 'replace').decode('utf-8') + ) def get_optimizer(self, dimensions: List[Dimension], cpu_count) -> Optimizer: return Optimizer( diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index 90ff8a1d0..637623e7d 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -1,5 +1,4 @@ # pragma pylint: disable=missing-docstring,W0212,C0103 -import locale import logging import re from datetime import datetime @@ -631,7 +630,7 @@ def test_generate_optimizer(mocker, hyperopt_conf) -> None: 'Avg profit 2.31%. Median profit 2.31%. Total profit ' '0.00023300 BTC ( 2.31\N{GREEK CAPITAL LETTER SIGMA}%). ' 'Avg duration 100.0 min.' - ).encode(locale.getpreferredencoding(), 'replace').decode('utf-8'), + ), 'params_details': {'buy': {'adx-enabled': False, 'adx-value': 0, 'fastd-enabled': True, From e0ca3c014c254c9e34447a6bf417d80ac1faf8a9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 1 May 2021 17:12:48 +0200 Subject: [PATCH 3/5] Don't completely remove encode/decode --- freqtrade/optimize/hyperopt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 6f899aba6..ef842faec 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -353,7 +353,7 @@ class Hyperopt: f"Total profit {results_metrics['total_profit']: 11.8f} {stake_cur} " f"({results_metrics['profit']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). " f"Avg duration {results_metrics['duration']:5.1f} min." - ) + ).encode('utf-8', 'replace').decode('utf-8') def get_optimizer(self, dimensions: List[Dimension], cpu_count) -> Optimizer: return Optimizer( From 1cb430f59b0116cbf66d71ea5f6d7909eeacea25 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 1 May 2021 17:41:40 +0200 Subject: [PATCH 4/5] Remove encoding specifics, gitattributes to echeckout as utf8 --- .gitattributes | 7 ++++--- freqtrade/optimize/hyperopt.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index 00abd1d9d..bc0382636 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ -*.py eol=lf -*.sh eol=lf -*.ps1 eol=crlf +* encoding=UTF-8 +*.py eol=lf +*.sh eol=lf +*.ps1 eol=crlf diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index ef842faec..6f899aba6 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -353,7 +353,7 @@ class Hyperopt: f"Total profit {results_metrics['total_profit']: 11.8f} {stake_cur} " f"({results_metrics['profit']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). " f"Avg duration {results_metrics['duration']:5.1f} min." - ).encode('utf-8', 'replace').decode('utf-8') + ) def get_optimizer(self, dimensions: List[Dimension], cpu_count) -> Optimizer: return Optimizer( From 3014bc34673bd8b5b32c46162d7313c0a51139ab Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 27 May 2021 14:22:11 +0200 Subject: [PATCH 5/5] Don't use Sum sign in hyperopt to avoid compatibility problems --- docs/advanced-hyperopt.md | 2 +- docs/hyperopt.md | 8 ++++---- freqtrade/optimize/hyperopt.py | 2 +- tests/optimize/test_hyperopt.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/advanced-hyperopt.md b/docs/advanced-hyperopt.md index c86978b80..35fd3de4a 100644 --- a/docs/advanced-hyperopt.md +++ b/docs/advanced-hyperopt.md @@ -289,7 +289,7 @@ Given the following result from hyperopt: ``` Best result: - 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722Σ%). Avg duration 180.4 mins. Objective: 1.94367 + 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367 Buy hyperspace params: { 'adx-value': 44, diff --git a/docs/hyperopt.md b/docs/hyperopt.md index b3fdc699b..1c95d84c9 100644 --- a/docs/hyperopt.md +++ b/docs/hyperopt.md @@ -486,7 +486,7 @@ Given the following result from hyperopt: ``` Best result: - 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722Σ%). Avg duration 180.4 mins. Objective: 1.94367 + 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367 # Buy hyperspace params: buy_params = { @@ -527,7 +527,7 @@ If you are optimizing ROI (i.e. if optimization search-space contains 'all', 'de ``` Best result: - 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722Σ%). Avg duration 180.4 mins. Objective: 1.94367 + 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367 # ROI table: minimal_roi = { @@ -582,7 +582,7 @@ If you are optimizing stoploss values (i.e. if optimization search-space contain ``` Best result: - 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722Σ%). Avg duration 180.4 mins. Objective: 1.94367 + 44/100: 135 trades. Avg profit 0.57%. Total profit 0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367 # Buy hyperspace params: buy_params = { @@ -624,7 +624,7 @@ If you are optimizing trailing stop values (i.e. if optimization search-space co ``` Best result: - 45/100: 606 trades. Avg profit 1.04%. Total profit 0.31555614 BTC ( 630.48Σ%). Avg duration 150.3 mins. Objective: -1.10161 + 45/100: 606 trades. Avg profit 1.04%. Total profit 0.31555614 BTC ( 630.48%). Avg duration 150.3 mins. Objective: -1.10161 # Trailing stop: trailing_stop = True diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 6f899aba6..9af3710a3 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -351,7 +351,7 @@ class Hyperopt: f"Avg profit {results_metrics['avg_profit']: 6.2f}%. " f"Median profit {results_metrics['median_profit']: 6.2f}%. " f"Total profit {results_metrics['total_profit']: 11.8f} {stake_cur} " - f"({results_metrics['profit']: 7.2f}\N{GREEK CAPITAL LETTER SIGMA}%). " + f"({results_metrics['profit']: 7.2f}%). " f"Avg duration {results_metrics['duration']:5.1f} min." ) diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index 637623e7d..7cb04fae0 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -628,7 +628,7 @@ def test_generate_optimizer(mocker, hyperopt_conf) -> None: 'loss': 1.9840569076926293, 'results_explanation': (' 1 trades. 1/0/0 Wins/Draws/Losses. ' 'Avg profit 2.31%. Median profit 2.31%. Total profit ' - '0.00023300 BTC ( 2.31\N{GREEK CAPITAL LETTER SIGMA}%). ' + '0.00023300 BTC ( 2.31%). ' 'Avg duration 100.0 min.' ), 'params_details': {'buy': {'adx-enabled': False,