Ejemplo n.º 1
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolumeWeightedAveragePrice()

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 1.00003
Ejemplo n.º 2
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolumeWeightedAveragePrice()

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.00003, indicator.value)
Ejemplo n.º 3
0
 def setUp(self):
     # Fixture Setup
     self.vwap = VolumeWeightedAveragePrice()
Ejemplo n.º 4
0
class VolumeWeightedAveragePriceTests(unittest.TestCase):
    def setUp(self):
        # Fixture Setup
        self.vwap = VolumeWeightedAveragePrice()

    def test_name_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("VolumeWeightedAveragePrice", self.vwap.name)

    def test_str_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("VolumeWeightedAveragePrice()", str(self.vwap))
        self.assertEqual("VolumeWeightedAveragePrice()", repr(self.vwap))

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        # Act
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)

        # Assert
        self.assertEqual(True, self.vwap.initialized)

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolumeWeightedAveragePrice()

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)

        # Act
        # Assert
        self.assertEqual(1.00000, self.vwap.value)

    def test_values_with_higher_inputs_returns_expected_value(self):
        # Arrange
        # Act
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)
        self.vwap.update_raw(1.00010, 11000, UNIX_EPOCH)
        self.vwap.update_raw(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update_raw(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update_raw(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update_raw(1.00050, 0, UNIX_EPOCH)
        self.vwap.update_raw(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update_raw(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update_raw(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update_raw(1.00090, 19000, UNIX_EPOCH)

        # Assert
        self.assertEqual(1.0005076923076923, self.vwap.value)

    def test_values_with_all_lower_inputs_returns_expected_value(self):
        # Arrange
        # Act
        self.vwap.update_raw(1.00100, 20000, UNIX_EPOCH)
        self.vwap.update_raw(1.00090, 19000, UNIX_EPOCH)
        self.vwap.update_raw(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update_raw(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update_raw(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update_raw(1.00050, 15000, UNIX_EPOCH)
        self.vwap.update_raw(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update_raw(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update_raw(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update_raw(1.00010, 11000, UNIX_EPOCH)

        # Assert
        self.assertEqual(1.0006032258064514, self.vwap.value)

    def test_new_day_resets_values(self):
        # Arrange
        # Act
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)
        self.vwap.update_raw(1.00010, 11000, UNIX_EPOCH)
        self.vwap.update_raw(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update_raw(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update_raw(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update_raw(1.00050, 0, UNIX_EPOCH)
        self.vwap.update_raw(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update_raw(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update_raw(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update_raw(1.00090, 19000, UNIX_EPOCH)
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH + timedelta(1))

        # Assert
        self.assertEqual(1.00000, self.vwap.value)

    def test_new_day_with_first_volume_zero_returns_price_as_value(self):
        # Arrange
        # Act
        self.vwap.update_raw(2.00000, 10000, UNIX_EPOCH)
        self.vwap.update_raw(1.00000, 0, UNIX_EPOCH + timedelta(1))

        # Assert
        self.assertEqual(1.00000, self.vwap.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(100):
            self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)

        # Act
        self.vwap.reset()

        # Assert
        self.assertFalse(self.vwap.initialized)
        self.assertEqual(0, self.vwap.value)
Ejemplo n.º 5
0
 def setUp(self):
     # Arrange
     self.vwap = VolumeWeightedAveragePrice()
Ejemplo n.º 6
0
class VolumeWeightedAveragePriceTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.vwap = VolumeWeightedAveragePrice()

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual('VolumeWeightedAveragePrice', self.vwap.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual('VolumeWeightedAveragePrice()', str(self.vwap))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(
            repr(self.vwap).startswith(
                '<VolumeWeightedAveragePrice() object at'))
        self.assertTrue(repr(self.vwap).endswith('>'))

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        # Act
        self.vwap.update(1.00000, 10000, UNIX_EPOCH)

        # Assert
        self.assertEqual(True, self.vwap.initialized)

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.vwap.update(1.00000, 10000, UNIX_EPOCH)

        # Act
        # Assert
        self.assertEqual(1.00000, self.vwap.value)

    def test_values_with_higher_inputs_returns_expected_value(self):
        # Arrange
        # Act
        self.vwap.update(1.00000, 10000, UNIX_EPOCH)
        self.vwap.update(1.00010, 11000, UNIX_EPOCH)
        self.vwap.update(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update(1.00050, 0, UNIX_EPOCH)
        self.vwap.update(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update(1.00090, 19000, UNIX_EPOCH)

        # Assert
        self.assertEqual(1.0005076923076923, self.vwap.value)

    def test_values_with_all_lower_inputs_returns_expected_value(self):
        # Arrange
        # Act
        self.vwap.update(1.00100, 20000, UNIX_EPOCH)
        self.vwap.update(1.00090, 19000, UNIX_EPOCH)
        self.vwap.update(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update(1.00050, 15000, UNIX_EPOCH)
        self.vwap.update(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update(1.00010, 11000, UNIX_EPOCH)

        # Assert
        self.assertEqual(1.0006032258064514, self.vwap.value)

    def test_new_day_resets_values(self):
        # Arrange
        # Act
        self.vwap.update(1.00000, 10000, UNIX_EPOCH)
        self.vwap.update(1.00010, 11000, UNIX_EPOCH)
        self.vwap.update(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update(1.00050, 0, UNIX_EPOCH)
        self.vwap.update(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update(1.00090, 19000, UNIX_EPOCH)
        self.vwap.update(1.00000, 10000, UNIX_EPOCH + timedelta(1))

        # Assert
        self.assertEqual(1.00000, self.vwap.value)

    def test_new_day_with_first_volume_zero_returns_price_as_value(self):
        # Arrange
        # Act
        self.vwap.update(2.00000, 10000, UNIX_EPOCH)
        self.vwap.update(1.00000, 0, UNIX_EPOCH + timedelta(1))

        # Assert
        self.assertEqual(1.00000, self.vwap.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for i in range(100):
            self.vwap.update(1.00000, 10000, UNIX_EPOCH)

        # Act
        self.vwap.reset()  # No assertion errors.
        self.assertFalse(self.vwap.initialized)

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

        # Act
        for point in BatterySeries.create():
            self.vwap.update(point, 10000, UNIX_EPOCH)
            output.append(self.vwap.value)

        # Assert
        self.assertEqual(len(battery_signal), len(output))
Ejemplo n.º 7
0
class TestVolumeWeightedAveragePrice:
    def setup(self):
        # Fixture Setup
        self.vwap = VolumeWeightedAveragePrice()

    def test_name_returns_expected_string(self):
        # Act, Assert
        assert self.vwap.name == "VolumeWeightedAveragePrice"

    def test_str_repr_returns_expected_string(self):
        # Act, Assert
        assert str(self.vwap) == "VolumeWeightedAveragePrice()"
        assert repr(self.vwap) == "VolumeWeightedAveragePrice()"

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange, Act
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)

        # Assert
        assert self.vwap.initialized is True

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolumeWeightedAveragePrice()

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)

        # Act, Assert
        assert self.vwap.value == 1.00000

    def test_values_with_higher_inputs_returns_expected_value(self):
        # Arrange, Act
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)
        self.vwap.update_raw(1.00010, 11000, UNIX_EPOCH)
        self.vwap.update_raw(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update_raw(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update_raw(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update_raw(1.00050, 0, UNIX_EPOCH)
        self.vwap.update_raw(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update_raw(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update_raw(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update_raw(1.00090, 19000, UNIX_EPOCH)

        # Assert
        assert self.vwap.value == 1.0005076923076923

    def test_values_with_all_lower_inputs_returns_expected_value(self):
        # Arrange, Act
        self.vwap.update_raw(1.00100, 20000, UNIX_EPOCH)
        self.vwap.update_raw(1.00090, 19000, UNIX_EPOCH)
        self.vwap.update_raw(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update_raw(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update_raw(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update_raw(1.00050, 15000, UNIX_EPOCH)
        self.vwap.update_raw(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update_raw(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update_raw(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update_raw(1.00010, 11000, UNIX_EPOCH)

        # Assert
        assert self.vwap.value == 1.0006032258064514

    def test_new_day_resets_values(self):
        # Arrange, Act
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)
        self.vwap.update_raw(1.00010, 11000, UNIX_EPOCH)
        self.vwap.update_raw(1.00020, 12000, UNIX_EPOCH)
        self.vwap.update_raw(1.00030, 13000, UNIX_EPOCH)
        self.vwap.update_raw(1.00040, 14000, UNIX_EPOCH)
        self.vwap.update_raw(1.00050, 0, UNIX_EPOCH)
        self.vwap.update_raw(1.00060, 16000, UNIX_EPOCH)
        self.vwap.update_raw(1.00070, 17000, UNIX_EPOCH)
        self.vwap.update_raw(1.00080, 18000, UNIX_EPOCH)
        self.vwap.update_raw(1.00090, 19000, UNIX_EPOCH)
        self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH + timedelta(1))

        # Assert
        assert self.vwap.value == 1.00000

    def test_new_day_with_first_volume_zero_returns_price_as_value(self):
        # Arrange, Act
        self.vwap.update_raw(2.00000, 10000, UNIX_EPOCH)
        self.vwap.update_raw(1.00000, 0, UNIX_EPOCH + timedelta(1))

        # Assert
        assert self.vwap.value == 1.00000

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(100):
            self.vwap.update_raw(1.00000, 10000, UNIX_EPOCH)

        # Act
        self.vwap.reset()

        # Assert
        assert not self.vwap.initialized
        assert self.vwap.value == 0