コード例 #1
0
    def testMACD(self):
        macd = MACD(short_win=5, long_win=10, dependency='close')
        short_average = XAverage(window=5, dependency='close')
        long_average = XAverage(window=10, dependency='close')

        for i, value in enumerate(self.sample):
            macd.push(dict(close=value))
            short_average.push(dict(close=value))
            long_average.push(dict(close=value))
            expected = short_average.result() - long_average.result()

            calculated = macd.result()
            self.assertAlmostEqual(
                expected, calculated, 10, "at index {0:d}\n"
                "expected x-average:   {1:f}\n"
                "calculated x-average: {2:f}".format(i, expected, calculated))
コード例 #2
0
    def testEMAMACD(self):
        fast = 5
        slow = 10
        ema_window = 10
        macd = MACD(fast, slow, 'close')
        ema_macd = XAverage(ema_window, macd)

        macd_diff = macd - ema_macd

        for i, value in enumerate(self.sample):
            macd.push(dict(close=value))
            ema_macd.push(dict(close=value))
            macd_diff.push(dict(close=value))
            expected = macd.value - ema_macd.value
            calculated = macd_diff.value
            self.assertAlmostEqual(
                expected, calculated, 10, "at index {0:d}\n"
                "expected ema macd diff:   {1:f}\n"
                "calculated ema macd diff: {2:f}".format(
                    i, expected, calculated))