Beispiel #1
0
    def __init__(self, period, timeSeries=None):
        super(DEMA, self).__init__()

        self.period = period

        self.ema = EMA(period)
        self.addSubIndicator(self.ema)

        self.emaEma = EMA(period)

        self.initialize(timeSeries)
Beispiel #2
0
    def __init__(self, periodFast, periodSlow, timeSeries=None):
        super(ChaikinOsc, self).__init__()

        self.periodFast = periodFast
        self.periodSlow = periodSlow

        self.accuDist = AccuDist()

        self.emaFast = EMA(periodFast)
        self.emaSlow = EMA(periodSlow)

        self.addSubIndicator(self.accuDist)

        self.initialize(timeSeries)
Beispiel #3
0
	def __init__(self, fastPeriod, slowPeriod, signalPeriod, timeSeries = None):
		super(MACD, self).__init__()

		self.fastPeriod = fastPeriod
		self.slowPeriod = slowPeriod
		self.signalPeriod = signalPeriod

		self.emaFast = EMA(fastPeriod)
		self.emaSlow = EMA(slowPeriod)
		self.signalLine = EMA(signalPeriod)
		self.macdLine = []

		self.addSubIndicator(self.emaFast)
		self.addSubIndicator(self.emaSlow)

		self.initialize(timeSeries)
Beispiel #4
0
    def __init__(self,
                 emaPeriod,
                 emaEmaPeriod,
                 emaRatioPeriod,
                 timeSeries=None):
        super(MassIndex, self).__init__()

        self.emaPeriod = emaPeriod
        self.emaEmaPeriod = emaEmaPeriod
        self.emaRatioPeriod = emaRatioPeriod

        self.ema = EMA(emaPeriod)
        self.emaEma = EMA(emaEmaPeriod)
        self.emaRatio = []

        self.initialize(timeSeries)
Beispiel #5
0
    def getEMA(self, cretenInterval, symbol, period):
        self.setupIndMap(symbol, cretenInterval)
        indKey = self.getIndKey('EMA', period)
        if not indKey in self.indMap[symbol][cretenInterval]:
            self.indMap[symbol][cretenInterval][indKey] = EMA(
                period, self.getCandles(symbol, cretenInterval))

        return self.indMap[symbol][cretenInterval][indKey]
Beispiel #6
0
class DEMA(SingleValueIndicator):
    def __init__(self, period, timeSeries=None):
        super(DEMA, self).__init__()

        self.period = period

        self.ema = EMA(period)
        self.addSubIndicator(self.ema)

        self.emaEma = EMA(period)

        self.initialize(timeSeries)

    def _calculate(self):
        if len(self.ema) < 1:
            return

        self.emaEma.addValue(self.ema[-1])

        if len(self.emaEma) < 1:
            return

        self.values.append(2.0 * self.ema[-1] - self.emaEma[-1])

    def removeValue(self):
        super(DEMA, self).removeValue()

        self.emaEma.removeValue()

    def removeAll(self):
        super(DEMA, self).removeAll()

        self.emaEma.removeAll()
Beispiel #7
0
    def generate_all_features(self, df):

        # Calculating indicators
        baseline = EMA(20, CLOSE).calculate(df)
        first_trend_ind = SuperTrend(10, 3).calculate(df)
        second_trend_ind = AroonHorn(20).calculate(df)
        volume = SqueezeBreak(20, 20).calculate(df)

        baseline = EMA_FT().transform(df, baseline)
        first_trend_ind = SuperTrend_FT().transform(df, first_trend_ind)
        second_trend_ind = AroonHorn_FT().transform(df, second_trend_ind)
        volume = SqueezeBreak_FT().transform(df, volume)

        features = pd.concat(
            [baseline, first_trend_ind, second_trend_ind, volume],
            join='inner',
            axis=1)

        return features
Beispiel #8
0
    def generate(self, df, idx):
        i = df.index.get_loc(idx)
        new_df = df.iloc[i - 100:i + 1, :].copy()

        # Calculating indicators
        baseline = EMA(20, CLOSE).calculate(new_df)
        first_trend_ind = SuperTrend(10, 3).calculate(new_df)
        second_trend_ind = AroonHorn(20).calculate(new_df)
        volume = SqueezeBreak(20, 20).calculate(new_df)

        baseline = EMA_FT().transform(new_df, baseline)
        first_trend_ind = SuperTrend_FT().transform(new_df, first_trend_ind)
        second_trend_ind = AroonHorn_FT().transform(new_df, second_trend_ind)
        volume = SqueezeBreak_FT().transform(new_df, volume)

        features = pd.concat(
            [baseline, first_trend_ind, second_trend_ind, volume],
            join='inner',
            axis=1).iloc[-1].tolist()

        return features
Beispiel #9
0
    def __init__(self,
                 maPeriod,
                 atrPeriod,
                 atrMultUp,
                 atrMultDown,
                 timeSeries=None):
        super(KeltnerChannels, self).__init__()

        self.maPeriod = maPeriod
        self.atrPeriod = atrPeriod
        self.atrMultUp = atrMultUp
        self.atrMultDown = atrMultDown

        self.atr = ATR(self.atrPeriod)
        self.cb = EMA(self.maPeriod)
        self.lb = []
        self.ub = []

        self.addSubIndicator(self.cb)
        self.addSubIndicator(self.atr)

        self.initialize(timeSeries)
Beispiel #10
0
class MACD(Indicator):
	def __init__(self, fastPeriod, slowPeriod, signalPeriod, timeSeries = None):
		super(MACD, self).__init__()

		self.fastPeriod = fastPeriod
		self.slowPeriod = slowPeriod
		self.signalPeriod = signalPeriod

		self.emaFast = EMA(fastPeriod)
		self.emaSlow = EMA(slowPeriod)
		self.signalLine = EMA(signalPeriod)
		self.macdLine = []

		self.addSubIndicator(self.emaFast)
		self.addSubIndicator(self.emaSlow)

		self.initialize(timeSeries)

	def _calculate(self):
		if len(self.emaFast) > 0 and len(self.emaSlow) > 0:
			self.macdLine.append(self.emaFast[-1] - self.emaSlow[-1])
			self.signalLine.addValue(self.macdLine[-1])

	def removeValue(self):
		super(MACD, self).removeValue()

		if len(self.macdLine) > 0:
			self.macdLine.pop(-1)
		self.signalLine.removeValue()

	def removeAll(self):
		super(MACD, self).removeAll()

		self.macdLine = []
		self.signalLine.removeAll()

	def getMACDLine(self):
		return self.macdLine

	def getSignalLine(self):
		return self.signalLine
Beispiel #11
0
class ChaikinOsc(SingleValueIndicator):
    def __init__(self, periodFast, periodSlow, timeSeries=None):
        super(ChaikinOsc, self).__init__()

        self.periodFast = periodFast
        self.periodSlow = periodSlow

        self.accuDist = AccuDist()

        self.emaFast = EMA(periodFast)
        self.emaSlow = EMA(periodSlow)

        self.addSubIndicator(self.accuDist)

        self.initialize(timeSeries)

    def _calculate(self):
        if len(self.accuDist) < 1:
            return

        self.emaFast.addValue(self.accuDist[-1])
        self.emaSlow.addValue(self.accuDist[-1])

        if len(self.emaFast) < 1 or len(self.emaSlow) < 1:
            return

        self.values.append(self.emaFast[-1] - self.emaSlow[-1])

    def removeValue(self):
        super(ChaikinOsc, self).removeValue()

        self.emaFast.removeValue()
        self.emaSlow.removeValue()

    def removeAll(self):
        super(ChaikinOsc, self).removeAll()

        self.emaFast.removeAll()
        self.emaSlow.removeAll()
Beispiel #12
0
    # signals = pd.Series(dm.decide(features), features.index)

    # Trying to immitate VP
    from indicators_transformer.EMA_FT import EMA_FT
    from indicators_transformer.SqueezeBreak_FT import SqueezeBreak_FT
    from indicators_transformer.AroonHorn_FT import AroonHorn_FT
    from indicators_transformer.SMI_FT import SMI_FT

    from indicators.EMA import EMA
    from indicators.SqueezeBreak import SqueezeBreak
    from indicators.AroonHorn import AroonHorn
    from indicators.SMI import SMI

    df = GBPUSD_data.get_1D()

    baseline = EMA_FT().transform(df, EMA(14, CLOSE).calculate(df))
    volume = SqueezeBreak_FT().transform(df,
                                         SqueezeBreak(14, 14).calculate(df))
    ind1 = AroonHorn_FT().transform(df, AroonHorn(20).calculate(df))
    ind2 = SMI_FT().transform(df, SMI(14, 3).calculate(df))

    signals = pd.concat([baseline, volume, ind1, ind2], axis=1)
    signals_dic = {}
    for index, row in signals.iterrows():
        if row[0] == 1 and row[1] == 1 and row[2] == 1 and row[3] == 1:
            signals_dic[index] = 1
        elif row[0] == -1 and row[1] == 1 and row[2] == -1 and row[3] == -1:
            signals_dic[index] = -1
        else:
            signals_dic[index] = 0
Beispiel #13
0
        # make everything clean
        out_series = df['EMA_FT']
        df.drop(columns=['EMA_FT'], inplace=True)

        # For test
        # df['EMA(20)'] = features
        # df['EMA(20)_transformed'] = out_series
        # df.to_csv("../test_reports/EMA_test/EMA20_transformed.csv")

        return out_series


if __name__ == "__main__":
    # Loading the data
    from data.FXDataLoader import Pair
    GBPUSD_data = Pair(GBPUSD)

    # Dataframe for test
    df = GBPUSD_data.get_1D()

    # Creating feature
    from indicators.EMA import EMA
    EMA = EMA(20, CLOSE)
    ema_values = EMA.calculate(df)

    # Transforming the Features
    ema_transformed = EMA_FT().transform(df, ema_values)

    print(ema_transformed)
Beispiel #14
0
class MassIndex(SingleValueIndicator):
    def __init__(self,
                 emaPeriod,
                 emaEmaPeriod,
                 emaRatioPeriod,
                 timeSeries=None):
        super(MassIndex, self).__init__()

        self.emaPeriod = emaPeriod
        self.emaEmaPeriod = emaEmaPeriod
        self.emaRatioPeriod = emaRatioPeriod

        self.ema = EMA(emaPeriod)
        self.emaEma = EMA(emaEmaPeriod)
        self.emaRatio = []

        self.initialize(timeSeries)

    def _calculate(self):
        self.ema.addValue(self.timeSeries[-1].getHigh() -
                          self.timeSeries[-1].getLow())

        if len(self.ema) < 1:
            return

        self.emaEma.addValue(self.ema[-1])

        if len(self.emaEma) < 1:
            return

        self.emaRatio.append(self.ema[-1] / float(self.emaEma[-1]))

        if len(self.emaRatio) < self.emaRatioPeriod:
            return

        self.values.append(sum(self.emaRatio[-self.emaRatioPeriod:]))

    def removeValue(self):
        super(MassIndex, self).removeValue()

        self.ema.removeValue()
        self.emaEma.removeValue()
        if len(self.emaRatio) > 1:
            self.emaRatio.pop(-1)

    def removeAll(self):
        super(MassIndex, self).removeAll()

        self.ema.removeAll()
        self.emaEma.removeAll()
        self.emaRatio = []