Merge pull request #515 from gcarq/indicator_helpers

Random indicator helpers
This commit is contained in:
Samuel Husso 2018-02-15 10:12:37 +02:00 committed by GitHub
commit d13d6736b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 5 deletions

View File

@ -0,0 +1,40 @@
from math import exp, pi, sqrt, cos
import numpy
import talib as ta
from pandas import Series
def went_up(series: Series) -> Series:
return series > series.shift(1)
def went_down(series: Series) -> Series:
return series < series.shift(1)
def ehlers_super_smoother(series: Series, smoothing: float = 6):
magic = pi * sqrt(2) / smoothing
a1 = exp(-magic)
coeff2 = 2 * a1 * cos(magic)
coeff3 = -a1 * a1
coeff1 = (1 - coeff2 - coeff3) / 2
filtered = series.copy()
for i in range(2, len(series)):
filtered.iloc[i] = coeff1 * (series.iloc[i] + series.iloc[i-1]) + \
coeff2 * filtered.iloc[i-1] + coeff3 * filtered.iloc[i-2]
return filtered
def fishers_inverse(series: Series, smoothing: float = 0):
""" Does a smoothed fishers inverse transformation.
Can be used with any oscillator that goes from 0 to 100 like RSI or MFI """
v1 = 0.1 * (series - 50)
if smoothing > 0:
v2 = ta.WMA(v1.values, timeperiod=smoothing)
else:
v2 = v1
return (numpy.exp(2 * v2)-1) / (numpy.exp(2 * v2) + 1)

View File

@ -4,7 +4,7 @@ import talib.abstract as ta
from pandas import DataFrame from pandas import DataFrame
import freqtrade.vendor.qtpylib.indicators as qtpylib import freqtrade.vendor.qtpylib.indicators as qtpylib
from freqtrade.strategy.interface import IStrategy from freqtrade.strategy.interface import IStrategy
from freqtrade.indicator_helpers import fishers_inverse
class_name = 'DefaultStrategy' class_name = 'DefaultStrategy'
@ -74,17 +74,18 @@ class DefaultStrategy(IStrategy):
""" """
# RSI # RSI
dataframe['rsi'] = ta.RSI(dataframe) dataframe['rsi'] = ta.RSI(dataframe)
"""
# Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy) # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy)
rsi = 0.1 * (dataframe['rsi'] - 50) dataframe['fisher_rsi'] = fishers_inverse(dataframe['rsi'])
dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) - 1) / (numpy.exp(2 * rsi) + 1)
# Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy) # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy)
dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1) dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1)
# Stoch # Stoch
stoch = ta.STOCH(dataframe) stoch = ta.STOCH(dataframe)
dataframe['slowd'] = stoch['slowd'] dataframe['slowd'] = stoch['slowd']
dataframe['slowk'] = stoch['slowk'] dataframe['slowk'] = stoch['slowk']
"""
# Stoch fast # Stoch fast
stoch_fast = ta.STOCHF(dataframe) stoch_fast = ta.STOCHF(dataframe)
dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastd'] = stoch_fast['fastd']

View File

@ -0,0 +1,12 @@
import pandas as pd
from freqtrade.indicator_helpers import went_up, went_down
def test_went_up():
series = pd.Series([1, 2, 3, 1])
assert went_up(series).equals(pd.Series([False, True, True, False]))
def test_went_down():
series = pd.Series([1, 2, 3, 1])
assert went_down(series).equals(pd.Series([False, False, False, True]))