Esempio n. 1
0
    def test_downsample_non_windowed_factor(self):
        sma = SimpleMovingAverage(
            inputs=[TestingDataSet.float_col],
            window_length=5,
        )

        self.check_downsampled_term(((sma + sma) / 2).rank())
Esempio n. 2
0
 def test_downsample_nonwindowed_classifier(self):
     sma = SimpleMovingAverage(
         inputs=[TestingDataSet.float_col],
         window_length=5,
     )
     self.check_downsampled_term(sma.quantiles(5))
Esempio n. 3
0
 def test_downsample_nonwindowed_filter(self):
     sma = SimpleMovingAverage(
         inputs=[TestingDataSet.float_col],
         window_length=5,
     )
     self.check_downsampled_term(sma > 5)
Esempio n. 4
0
 def test_downsample_windowed_filter(self):
     sma = SimpleMovingAverage(
         inputs=[TestingDataSet.float_col],
         window_length=5,
     )
     self.check_downsampled_term(All(inputs=[sma.top(4)], window_length=5))
Esempio n. 5
0
 def test_downsample_windowed_factor(self):
     self.check_downsampled_term(
         SimpleMovingAverage(
             inputs=[TestingDataSet.float_col],
             window_length=5,
         ))
Esempio n. 6
0
    def test_window_safety_of_slices(self):
        """
        Test that slices correctly inherit the `window_safe` property of the
        term from which they are derived.
        """
        col = self.col
        my_asset = self.asset_finder.retrieve_asset(self.sids[0])

        # SimpleMovingAverage is not window safe.
        sma = SimpleMovingAverage(inputs=[self.col], window_length=10)
        sma_slice = sma[my_asset]

        class UsesSlicedInput(CustomFactor):
            window_length = 1
            inputs = [sma_slice]

            def compute(self, today, assets, out, sma_slice):
                pass

        with self.assertRaises(NonWindowSafeInput):
            self.run_pipeline(
                Pipeline(columns={'uses_sliced_input': UsesSlicedInput()}),
                self.pipeline_start_date,
                self.pipeline_end_date,
            )

        # Make sure that slices of custom factors are not window safe.
        class MyUnsafeFactor(CustomFactor):
            window_length = 1
            inputs = [col]

            def compute(self, today, assets, out, col):
                pass

        my_unsafe_factor = MyUnsafeFactor()
        my_unsafe_factor_slice = my_unsafe_factor[my_asset]

        class UsesSlicedInput(CustomFactor):
            window_length = 1
            inputs = [my_unsafe_factor_slice]

            def compute(self, today, assets, out, my_unsafe_factor_slice):
                pass

        with self.assertRaises(NonWindowSafeInput):
            self.run_pipeline(
                Pipeline(columns={'uses_sliced_input': UsesSlicedInput()}),
                self.pipeline_start_date,
                self.pipeline_end_date,
            )

        # Create a window safe factor.
        class MySafeFactor(CustomFactor):
            window_length = 1
            inputs = [col]
            window_safe = True

            def compute(self, today, assets, out, col):
                pass

        my_safe_factor = MySafeFactor()
        my_safe_factor_slice = my_safe_factor[my_asset]

        # Make sure that correlations are not safe if either the factor *or*
        # the target slice are not window safe.
        with self.assertRaises(NonWindowSafeInput):
            my_unsafe_factor.pearsonr(
                target=my_safe_factor_slice,
                correlation_length=10,
            )

        with self.assertRaises(NonWindowSafeInput):
            my_safe_factor.pearsonr(
                target=my_unsafe_factor_slice,
                correlation_length=10,
            )
Esempio n. 7
0
 def test_downsample_nonwindowed_classifier(self):
     sma = SimpleMovingAverage(
         inputs=[TestingDataSet.float_col],
         window_length=5,
     )
     self.check_downsampled_term(sma.quantiles(5))
Esempio n. 8
0
 def test_downsample_windowed_filter(self):
     sma = SimpleMovingAverage(
         inputs=[TestingDataSet.float_col],
         window_length=5,
     )
     self.check_downsampled_term(All(inputs=[sma.top(4)], window_length=5))