コード例 #1
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolatilityRatio(10, 100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.0, indicator.value)
コード例 #2
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolatilityRatio(10, 100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 1.0
コード例 #3
0
 def setup(self):
     # Fixture Setup
     self.vcr = VolatilityRatio(10, 100)
コード例 #4
0
class TestVolatilityCompressionRatio:
    def setup(self):
        # Fixture Setup
        self.vcr = VolatilityRatio(10, 100)

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

    def test_str_repr_returns_expected_string(self):
        # Arrange, Act, Assert
        assert str(self.vcr) == "VolatilityRatio(10, 100, SIMPLE, True, 0.0)"
        assert repr(self.vcr) == "VolatilityRatio(10, 100, SIMPLE, True, 0.0)"

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange, Act
        for _i in range(100):
            self.vcr.update_raw(1.00000, 1.00000, 1.00000)

        # Assert
        assert self.vcr.initialized is True

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolatilityRatio(10, 100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_no_inputs_returns_none(self):
        # Arrange, Act, Assert
        assert self.vcr.value == 0

    def test_value_with_epsilon_inputs_returns_expected_value(self):
        # Arrange
        epsilon = sys.float_info.epsilon
        self.vcr.update_raw(epsilon, epsilon, epsilon)

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

    def test_value_with_one_ones_input_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00000, 1.00000, 1.00000)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)

        # Act, Assert
        assert self.vcr.value == 1.0

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)

        # Act, Assert
        assert self.vcr.value == 1.0

    def test_value_with_close_on_high_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000
        factor = 0

        # Act
        for _i in range(1000):
            high += 0.00010 + factor
            low += 0.00010 + factor
            factor += 0.00001
            close = high
            self.vcr.update_raw(high, low, close)

        # Assert
        assert self.vcr.value == pytest.approx(0.9552015928322548, 2)

    def test_value_with_close_on_low_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000
        factor = 0

        # Act
        for _i in range(1000):
            high -= 0.00010 + factor
            low -= 0.00010 + factor
            factor -= 0.00002
            close = low
            self.vcr.update_raw(high, low, close)

        # Assert
        assert self.vcr.value == 0.9547511312217188

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(1000):
            self.vcr.update_raw(1.00010, 1.00000, 1.00005)

        # Act
        self.vcr.reset()

        # Assert
        assert not self.vcr.initialized
        assert self.vcr.value == 0
コード例 #5
0
class VolatilityCompressionRatioTests(unittest.TestCase):
    def setUp(self):
        # Fixture Setup
        self.vcr = VolatilityRatio(10, 100)

    def test_name_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("VolatilityRatio", self.vcr.name)

    def test_str_repr_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("VolatilityRatio(10, 100, SIMPLE, True, 0.0)",
                         str(self.vcr))
        self.assertEqual("VolatilityRatio(10, 100, SIMPLE, True, 0.0)",
                         repr(self.vcr))

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        # Act
        for _i in range(100):
            self.vcr.update_raw(1.00000, 1.00000, 1.00000)

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

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = VolatilityRatio(10, 100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_no_inputs_returns_none(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(0, self.vcr.value)

    def test_value_with_epsilon_inputs_returns_expected_value(self):
        # Arrange
        epsilon = sys.float_info.epsilon
        self.vcr.update_raw(epsilon, epsilon, epsilon)

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

    def test_value_with_one_ones_input_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00000, 1.00000, 1.00000)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)

        # Act
        # Assert
        self.assertEqual(1.0, self.vcr.value)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)

        # Act
        # Assert
        self.assertEqual(1.0, self.vcr.value)

    def test_value_with_close_on_high_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000
        factor = 0

        # Act
        for _i in range(1000):
            high += 0.00010 + factor
            low += 0.00010 + factor
            factor += 0.00001
            close = high
            self.vcr.update_raw(high, low, close)

        # Assert
        self.assertEqual(0.9552015928322548, self.vcr.value, 2)

    def test_value_with_close_on_low_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000
        factor = 0

        # Act
        for _i in range(1000):
            high -= 0.00010 + factor
            low -= 0.00010 + factor
            factor -= 0.00002
            close = low
            self.vcr.update_raw(high, low, close)

        # Assert
        self.assertEqual(0.9547511312217188, self.vcr.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(1000):
            self.vcr.update_raw(1.00010, 1.00000, 1.00005)

        # Act
        self.vcr.reset()

        # Assert
        self.assertFalse(self.vcr.initialized)
        self.assertEqual(0, self.vcr.value)
コード例 #6
0
 def setUp(self):
     # Arrange
     self.vcr = VolatilityRatio(10, 100)
コード例 #7
0
class VolatilityCompressionRatioTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.vcr = VolatilityRatio(10, 100)

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual("VolatilityRatio", self.vcr.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("VolatilityRatio(10, 100, SIMPLE, True, 0.0)", str(self.vcr))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(repr(self.vcr).startswith("<VolatilityRatio(10, 100, SIMPLE, True, 0.0) object at"))
        self.assertTrue(repr(self.vcr).endswith(">"))

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Act
        for _i in range(100):
            self.vcr.update_raw(1.00000, 1.00000, 1.00000)

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

    def test_value_with_no_inputs_returns_none(self):
        # Act
        # Assert
        self.assertEqual(0.0, self.vcr.value)

    def test_value_with_epsilon_inputs_returns_expected_value(self):
        # Arrange
        epsilon = sys.float_info.epsilon
        self.vcr.update_raw(epsilon, epsilon, epsilon)

        # Act
        # Assert
        self.assertEqual(0.0, self.vcr.value)

    def test_value_with_one_ones_input_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00000, 1.00000, 1.00000)

        # Act
        # Assert
        self.assertEqual(0.0, self.vcr.value)

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)

        # Act
        # Assert
        self.assertEqual(1.0, self.vcr.value)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)
        self.vcr.update_raw(1.00020, 1.00000, 1.00010)

        # Act
        # Assert
        self.assertEqual(1.0, self.vcr.value)

    def test_value_with_close_on_high_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000
        factor = 0.0

        # Act
        for _i in range(1000):
            high += 0.00010 + factor
            low += 0.00010 + factor
            factor += 0.00001
            close = high
            self.vcr.update_raw(high, low, close)

        # Assert
        self.assertEqual(0.9552015928322548, self.vcr.value, 2)

    def test_value_with_close_on_low_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000
        factor = 0.0

        # Act
        for _i in range(1000):
            high -= 0.00010 + factor
            low -= 0.00010 + factor
            factor -= 0.00002
            close = low
            self.vcr.update_raw(high, low, close)

        # Assert
        self.assertEqual(0.9547511312217188, self.vcr.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(1000):
            self.vcr.update_raw(1.00010, 1.00000, 1.00005)

        # Act
        self.vcr.reset()

        # Assert
        self.assertEqual(0.0, self.vcr.value)  # No assertion errors.

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

        # Act
        for point in BatterySeries.create():
            self.vcr.update_raw(point, sys.float_info.epsilon, sys.float_info.epsilon)
            output.append(self.vcr.value)

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