コード例 #1
0
class TestMovingAverageConvergenceDivergence:
    def setup(self):
        # Fixture Setup
        self.macd = MovingAverageConvergenceDivergence(3, 10)

    def test_name_returns_expected_string(self):
        # Arrange, Act, Assert
        assert self.macd.name == "MovingAverageConvergenceDivergence"

    def test_str_repr_returns_expected_string(self):
        # Arrange, Act, Assert
        assert str(
            self.macd
        ) == "MovingAverageConvergenceDivergence(3, 10, EXPONENTIAL)"
        assert repr(
            self.macd
        ) == "MovingAverageConvergenceDivergence(3, 10, EXPONENTIAL)"

    def test_initialized_without_inputs_returns_false(self):
        # Arrange, Act, Assert
        assert self.macd.initialized is False

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)
        self.macd.update_raw(4.00000)
        self.macd.update_raw(5.00000)
        self.macd.update_raw(6.00000)
        self.macd.update_raw(7.00000)
        self.macd.update_raw(8.00000)
        self.macd.update_raw(9.00000)
        self.macd.update_raw(10.00000)
        self.macd.update_raw(11.00000)
        self.macd.update_raw(12.00000)
        self.macd.update_raw(13.00000)
        self.macd.update_raw(14.00000)
        self.macd.update_raw(15.00000)
        self.macd.update_raw(16.00000)

        # Act, Assert
        assert self.macd.initialized is True

    def test_handle_quote_tick_updates_indicator(self):
        # Arrange
        indicator = MovingAverageConvergenceDivergence(
            3, 10, price_type=PriceType.MID)

        tick = TestStubs.quote_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_quote_tick(tick)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 0

    def test_handle_trade_tick_updates_indicator(self):
        # Arrange
        indicator = MovingAverageConvergenceDivergence(3, 10)

        tick = TestStubs.trade_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_trade_tick(tick)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 0

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = MovingAverageConvergenceDivergence(3, 10)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 0

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)

        # Act, Assert
        assert self.macd.value == 0

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)

        # Act, Assert
        assert self.macd.value == 0.7376033057851243

    def test_value_with_more_inputs_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)
        self.macd.update_raw(4.00000)
        self.macd.update_raw(5.00000)
        self.macd.update_raw(6.00000)
        self.macd.update_raw(7.00000)
        self.macd.update_raw(8.00000)
        self.macd.update_raw(9.00000)
        self.macd.update_raw(10.00000)
        self.macd.update_raw(11.00000)
        self.macd.update_raw(12.00000)
        self.macd.update_raw(13.00000)
        self.macd.update_raw(14.00000)
        self.macd.update_raw(15.00000)
        self.macd.update_raw(16.00000)

        # Act, Assert
        assert self.macd.value == 3.2782313673122907

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.macd.update_raw(1.00020)
        self.macd.update_raw(1.00030)
        self.macd.update_raw(1.00050)

        # Act
        self.macd.reset()

        # Assert
        assert not self.macd.initialized
コード例 #2
0
class MovingAverageConvergenceDivergenceTests(unittest.TestCase):
    def setUp(self):
        # Fixture Setup
        self.macd = MovingAverageConvergenceDivergence(3, 10)

    def test_name_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("MovingAverageConvergenceDivergence", self.macd.name)

    def test_str_repr_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(
            "MovingAverageConvergenceDivergence(3, 10, EXPONENTIAL)",
            str(self.macd))
        self.assertEqual(
            "MovingAverageConvergenceDivergence(3, 10, EXPONENTIAL)",
            repr(self.macd))

    def test_initialized_without_inputs_returns_false(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(False, self.macd.initialized)

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)
        self.macd.update_raw(4.00000)
        self.macd.update_raw(5.00000)
        self.macd.update_raw(6.00000)
        self.macd.update_raw(7.00000)
        self.macd.update_raw(8.00000)
        self.macd.update_raw(9.00000)
        self.macd.update_raw(10.00000)
        self.macd.update_raw(11.00000)
        self.macd.update_raw(12.00000)
        self.macd.update_raw(13.00000)
        self.macd.update_raw(14.00000)
        self.macd.update_raw(15.00000)
        self.macd.update_raw(16.00000)

        # Act
        # Assert
        self.assertEqual(True, self.macd.initialized)

    def test_handle_quote_tick_updates_indicator(self):
        # Arrange
        indicator = MovingAverageConvergenceDivergence(
            3, 10, price_type=PriceType.MID)

        tick = TestStubs.quote_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_quote_tick(tick)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(0, indicator.value)

    def test_handle_trade_tick_updates_indicator(self):
        # Arrange
        indicator = MovingAverageConvergenceDivergence(3, 10)

        tick = TestStubs.trade_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_trade_tick(tick)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(0, indicator.value)

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = MovingAverageConvergenceDivergence(3, 10)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(0, indicator.value)

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)

        # Act
        # Assert
        self.assertEqual(0, self.macd.value)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)

        # Act
        # Assert
        self.assertEqual(0.7376033057851243, self.macd.value)

    def test_value_with_more_inputs_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)
        self.macd.update_raw(4.00000)
        self.macd.update_raw(5.00000)
        self.macd.update_raw(6.00000)
        self.macd.update_raw(7.00000)
        self.macd.update_raw(8.00000)
        self.macd.update_raw(9.00000)
        self.macd.update_raw(10.00000)
        self.macd.update_raw(11.00000)
        self.macd.update_raw(12.00000)
        self.macd.update_raw(13.00000)
        self.macd.update_raw(14.00000)
        self.macd.update_raw(15.00000)
        self.macd.update_raw(16.00000)

        # Act
        # Assert
        self.assertEqual(3.2782313673122907, self.macd.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.macd.update_raw(1.00020)
        self.macd.update_raw(1.00030)
        self.macd.update_raw(1.00050)

        # Act
        self.macd.reset()

        # Assert
        self.assertFalse(self.macd.initialized)
コード例 #3
0
class MovingAverageConvergenceDivergenceTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.macd = MovingAverageConvergenceDivergence(3, 10)

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual("MovingAverageConvergenceDivergence", self.macd.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual(
            "MovingAverageConvergenceDivergence(3, 10, EXPONENTIAL)",
            str(self.macd))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(
            repr(self.macd).startswith(
                "<MovingAverageConvergenceDivergence(3, 10, EXPONENTIAL) object at"
            ))
        self.assertTrue(repr(self.macd).endswith('>'))

    def test_initialized_without_inputs_returns_false(self):
        # Act
        # Assert
        self.assertEqual(False, self.macd.initialized)

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)
        self.macd.update_raw(4.00000)
        self.macd.update_raw(5.00000)
        self.macd.update_raw(6.00000)
        self.macd.update_raw(7.00000)
        self.macd.update_raw(8.00000)
        self.macd.update_raw(9.00000)
        self.macd.update_raw(10.00000)
        self.macd.update_raw(11.00000)
        self.macd.update_raw(12.00000)
        self.macd.update_raw(13.00000)
        self.macd.update_raw(14.00000)
        self.macd.update_raw(15.00000)
        self.macd.update_raw(16.00000)

        # Act
        # Assert
        self.assertEqual(True, self.macd.initialized)

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)

        # Act
        # Assert
        self.assertEqual(0, self.macd.value)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)

        # Act
        # Assert
        self.assertEqual(0.7376033057851243, self.macd.value)

    def test_value_with_more_inputs_expected_value(self):
        # Arrange
        self.macd.update_raw(1.00000)
        self.macd.update_raw(2.00000)
        self.macd.update_raw(3.00000)
        self.macd.update_raw(4.00000)
        self.macd.update_raw(5.00000)
        self.macd.update_raw(6.00000)
        self.macd.update_raw(7.00000)
        self.macd.update_raw(8.00000)
        self.macd.update_raw(9.00000)
        self.macd.update_raw(10.00000)
        self.macd.update_raw(11.00000)
        self.macd.update_raw(12.00000)
        self.macd.update_raw(13.00000)
        self.macd.update_raw(14.00000)
        self.macd.update_raw(15.00000)
        self.macd.update_raw(16.00000)

        # Act
        # Assert
        self.assertEqual(3.2782313673122907, self.macd.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.macd.update_raw(1.00020)
        self.macd.update_raw(1.00030)
        self.macd.update_raw(1.00050)

        # Act
        self.macd.reset()  # No assertion errors.

    def test_with_battery_signal(self):
        # Arrange
        battery_signal = BatterySeries.create()
        output = []

        # Act
        for point in battery_signal:
            self.macd.update_raw(point)
            output.append(self.macd.value)

        # Assert
        self.assertEqual(len(battery_signal), len(output))