Ejemplo n.º 1
0
def average_true_range(close_data, period):
    """
    Average True Range.

    Formula:
    ATRt = ATRt-1 * (n - 1) + TRt / n
    """
    tr = true_range(close_data, period)
    atr = smoothed_moving_average(tr, period)
    atr[0:period - 1] = tr[0:period - 1]
    return atr
Ejemplo n.º 2
0
 def test_smma_period_10(self):
     period = 10
     smma = smoothed_moving_average.smoothed_moving_average(
         self.data, period)
     np.testing.assert_array_equal(smma, self.smmma_period_10_expected)
Ejemplo n.º 3
0
 def test_smma_invalid_period(self):
     period = 128
     with self.assertRaises(Exception) as cm:
         smoothed_moving_average.smoothed_moving_average(self.data, period)
     expected = "Error: data_len < period"
     self.assertEqual(str(cm.exception), expected)
Ejemplo n.º 4
0
 def test_smma_period_8(self):
     period = 8
     smma = smoothed_moving_average.smoothed_moving_average(
         self.data, period)
     np.testing.assert_allclose(smma, self.smmma_period_8_expected)