From 61f92b7460b1781c0a17a149b4fdbdf1f297f181 Mon Sep 17 00:00:00 2001 From: ran Date: Tue, 31 Oct 2017 21:57:58 +0200 Subject: [PATCH 1/4] bugfix --- freqtrade/vendor/qtpylib/indicators.py | 50 ++++++++++---------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py index ee1f14e1f..c4b955626 100644 --- a/freqtrade/vendor/qtpylib/indicators.py +++ b/freqtrade/vendor/qtpylib/indicators.py @@ -248,45 +248,34 @@ def crossed_below(series1, series2): def rolling_std(series, window=200, min_periods=None): min_periods = window if min_periods is None else min_periods - try: - if min_periods == window: - return numpy_rolling_std(series, window, True) - else: - try: - return series.rolling(window=window, min_periods=min_periods).std() - except BaseException: - return pd.Series(series).rolling(window=window, min_periods=min_periods).std() - except BaseException: - return pd.rolling_std(series, window=window, min_periods=min_periods) - + if min_periods == window and len(series) > window: + return numpy_rolling_std(series, window, True) + else: + try: + return series.rolling(window=window, min_periods=min_periods).std() + except BaseException: + return pd.Series(series).rolling(window=window, min_periods=min_periods).std() # --------------------------------------------- def rolling_mean(series, window=200, min_periods=None): min_periods = window if min_periods is None else min_periods - try: - if min_periods == window: - return numpy_rolling_mean(series, window, True) - else: - try: - return series.rolling(window=window, min_periods=min_periods).mean() - except BaseException: - return pd.Series(series).rolling(window=window, min_periods=min_periods).mean() - except BaseException: - return pd.rolling_mean(series, window=window, min_periods=min_periods) - + if min_periods == window and len(series) > window: + return numpy_rolling_mean(series, window, True) + else: + try: + return series.rolling(window=window, min_periods=min_periods).mean() + except BaseException: + return pd.Series(series).rolling(window=window, min_periods=min_periods).mean() # --------------------------------------------- def rolling_min(series, window=14, min_periods=None): min_periods = window if min_periods is None else min_periods try: - try: - return series.rolling(window=window, min_periods=min_periods).min() - except BaseException: - return pd.Series(series).rolling(window=window, min_periods=min_periods).min() + return series.rolling(window=window, min_periods=min_periods).min() except BaseException: - return pd.rolling_min(series, window=window, min_periods=min_periods) + return pd.Series(series).rolling(window=window, min_periods=min_periods).min() # --------------------------------------------- @@ -294,12 +283,9 @@ def rolling_min(series, window=14, min_periods=None): def rolling_max(series, window=14, min_periods=None): min_periods = window if min_periods is None else min_periods try: - try: - return series.rolling(window=window, min_periods=min_periods).min() - except BaseException: - return pd.Series(series).rolling(window=window, min_periods=min_periods).min() + return series.rolling(window=window, min_periods=min_periods).min() except BaseException: - return pd.rolling_min(series, window=window, min_periods=min_periods) + return pd.Series(series).rolling(window=window, min_periods=min_periods).min() # --------------------------------------------- From e6e5c5daf02a88fa875f5445c5fece13aaf109ef Mon Sep 17 00:00:00 2001 From: ran Date: Tue, 31 Oct 2017 21:58:03 +0200 Subject: [PATCH 2/4] added zlma --- freqtrade/vendor/qtpylib/indicators.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py index c4b955626..22fac4e2a 100644 --- a/freqtrade/vendor/qtpylib/indicators.py +++ b/freqtrade/vendor/qtpylib/indicators.py @@ -552,6 +552,26 @@ def stoch(df, window=14, d=3, k=3, fast=False): return pd.DataFrame(index=df.index, data=data) +# --------------------------------------------- +def zlma(series, window=20, kind="ema"): + """ + John Ehlers' Zero lag (exponential) moving average + https://en.wikipedia.org/wiki/Zero_lag_exponential_moving_average + """ + lag = (window - 1) // 2 + series = 2 * series - series.shift(lag) + if kind in ['ewm', 'ema']: + return ema(series, lag) + elif kind == "hma": + return hma(series, lag) + return sma(series, lag) + +def zlema(series, window): + return zlma(series, window, kind="ema") +def zlsma(series, window): + return zlma(series, window, kind="sma") +def zlhma(series, window): + return zlma(series, window, kind="hma") # --------------------------------------------- From 6edb25f5c2f083060e68e274f23ddcdb25d23e03 Mon Sep 17 00:00:00 2001 From: ran Date: Fri, 12 Jan 2018 09:27:52 +0200 Subject: [PATCH 3/4] fixed heikenashi calculation --- freqtrade/vendor/qtpylib/indicators.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py index 22fac4e2a..9830e08fe 100644 --- a/freqtrade/vendor/qtpylib/indicators.py +++ b/freqtrade/vendor/qtpylib/indicators.py @@ -110,10 +110,13 @@ def heikinashi(bars): bars = bars.copy() bars['ha_close'] = (bars['open'] + bars['high'] + bars['low'] + bars['close']) / 4 + bars['ha_open'] = (bars['open'].shift(1) + bars['close'].shift(1)) / 2 bars.loc[:1, 'ha_open'] = bars['open'].values[0] - bars.loc[1:, 'ha_open'] = ( - (bars['ha_open'].shift(1) + bars['ha_close'].shift(1)) / 2)[1:] + for x in range(2): + bars.loc[1:, 'ha_open'] = ( + (bars['ha_open'].shift(1) + bars['ha_close'].shift(1)) / 2)[1:] + bars['ha_high'] = bars.loc[:, ['high', 'ha_open', 'ha_close']].max(axis=1) bars['ha_low'] = bars.loc[:, ['low', 'ha_open', 'ha_close']].min(axis=1) From d684ff5715271a2ef52bf2cd9b85783b5077d69f Mon Sep 17 00:00:00 2001 From: gcarq Date: Wed, 13 Jun 2018 16:20:13 +0200 Subject: [PATCH 4/4] drop zlma implementation --- freqtrade/vendor/qtpylib/indicators.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py index 9830e08fe..e68932998 100644 --- a/freqtrade/vendor/qtpylib/indicators.py +++ b/freqtrade/vendor/qtpylib/indicators.py @@ -261,6 +261,7 @@ def rolling_std(series, window=200, min_periods=None): # --------------------------------------------- + def rolling_mean(series, window=200, min_periods=None): min_periods = window if min_periods is None else min_periods if min_periods == window and len(series) > window: @@ -273,6 +274,7 @@ def rolling_mean(series, window=200, min_periods=None): # --------------------------------------------- + def rolling_min(series, window=14, min_periods=None): min_periods = window if min_periods is None else min_periods try: @@ -556,27 +558,7 @@ def stoch(df, window=14, d=3, k=3, fast=False): return pd.DataFrame(index=df.index, data=data) # --------------------------------------------- -def zlma(series, window=20, kind="ema"): - """ - John Ehlers' Zero lag (exponential) moving average - https://en.wikipedia.org/wiki/Zero_lag_exponential_moving_average - """ - lag = (window - 1) // 2 - series = 2 * series - series.shift(lag) - if kind in ['ewm', 'ema']: - return ema(series, lag) - elif kind == "hma": - return hma(series, lag) - return sma(series, lag) -def zlema(series, window): - return zlma(series, window, kind="ema") -def zlsma(series, window): - return zlma(series, window, kind="sma") -def zlhma(series, window): - return zlma(series, window, kind="hma") - -# --------------------------------------------- def zscore(bars, window=20, stds=1, col='close'): """ get zscore of price """