def test_vwap(self, name, add_custom_events):
        vwap = MovingVWAP(
            market_aware=True,
            window_length=2
        )

        if add_custom_events:
            self.source = self.intersperse_custom_events(self.source)

        transformed = list(vwap.transform(self.source))

        # Output values.  Unprocessed custom events will not have a field
        # corresponding to the transform hash.
        tnfm_vals = [message[vwap.get_hash()] for message in transformed
                     if message.type != DATASOURCE_TYPE.CUSTOM]
        # "Hand calculated" values.
        expected = [
            (10.0 * 100) / 100.0,
            ((10.0 * 100) + (10.0 * 100)) / (200.0),
            # We should drop the first event here.
            ((10.0 * 100) + (11.0 * 100)) / (200.0),
            # We should drop the second event here.
            ((11.0 * 100) + (11.0 * 300)) / (400.0)
        ]

        # Output should match the expected.
        self.assertEquals(tnfm_vals, expected)
Exemple #2
0
    def test_vwap(self, name, add_custom_events):
        vwap = MovingVWAP(market_aware=True, window_length=2)

        if add_custom_events:
            self.source = self.intersperse_custom_events(self.source)

        transformed = list(vwap.transform(self.source))

        # Output values.  Unprocessed custom events will not have a field
        # corresponding to the transform hash.
        tnfm_vals = [
            message[vwap.get_hash()] for message in transformed
            if message.type != DATASOURCE_TYPE.CUSTOM
        ]
        # "Hand calculated" values.
        expected = [
            (10.0 * 100) / 100.0,
            ((10.0 * 100) + (10.0 * 100)) / (200.0),
            # We should drop the first event here.
            ((10.0 * 100) + (11.0 * 100)) / (200.0),
            # We should drop the second event here.
            ((11.0 * 100) + (11.0 * 300)) / (400.0)
        ]

        # Output should match the expected.
        self.assertEquals(tnfm_vals, expected)
Exemple #3
0
    def test_vwap(self):
        vwap = MovingVWAP(market_aware=True, window_length=2)
        transformed = list(vwap.transform(self.source))

        # Output values
        tnfm_vals = [message[vwap.get_hash()] for message in transformed]
        # "Hand calculated" values.
        expected = [
            (10.0 * 100) / 100.0,
            ((10.0 * 100) + (10.0 * 100)) / (200.0),
            # We should drop the first event here.
            ((10.0 * 100) + (11.0 * 100)) / (200.0),
            # We should drop the second event here.
            ((11.0 * 100) + (11.0 * 300)) / (400.0),
        ]

        # Output should match the expected.
        self.assertEquals(tnfm_vals, expected)
Exemple #4
0
    def test_vwap(self):
        vwap = MovingVWAP(market_aware=True, window_length=2)
        transformed = list(vwap.transform(self.source))

        # Output values
        tnfm_vals = [message[vwap.get_hash()] for message in transformed]
        # "Hand calculated" values.
        expected = [
            (10.0 * 100) / 100.0,
            ((10.0 * 100) + (10.0 * 100)) / (200.0),
            # We should drop the first event here.
            ((10.0 * 100) + (11.0 * 100)) / (200.0),
            # We should drop the second event here.
            ((11.0 * 100) + (11.0 * 300)) / (400.0)
        ]

        # Output should match the expected.
        self.assertEquals(tnfm_vals, expected)
Exemple #5
0
    def test_vwap(self):

        vwap = MovingVWAP(market_aware=False, delta=timedelta(days=2))
        transformed = list(vwap.transform(self.source))

        # Output values
        tnfm_vals = [message.tnfm_value for message in transformed]
        # "Hand calculated" values.
        expected = [
            (10.0 * 100) / 100.0,
            ((10.0 * 100) + (10.0 * 100)) / (200.0),
            # We should drop the first event here.
            ((10.0 * 100) + (11.0 * 100)) / (200.0),
            # We should drop the second event here.
            ((11.0 * 100) + (11.0 * 300)) / (400.0)
        ]

        # Output should match the expected.
        assert tnfm_vals == expected
Exemple #6
0
    def test_vwap(self):

        vwap = MovingVWAP(
            market_aware=False,
            delta=timedelta(days=2)
        )
        transformed = list(vwap.transform(self.source))

        # Output values
        tnfm_vals = [message.tnfm_value for message in transformed]
        # "Hand calculated" values.
        expected = [
            (10.0 * 100) / 100.0,
            ((10.0 * 100) + (10.0 * 100)) / (200.0),
            # We should drop the first event here.
            ((10.0 * 100) + (11.0 * 100)) / (200.0),
            # We should drop the second event here.
            ((11.0 * 100) + (11.0 * 300)) / (400.0)
        ]

        # Output should match the expected.
        assert tnfm_vals == expected