Exemple #1
0
 def test_from_com(self, type_, com):
     from_com = EWMA.from_center_of_mass(
         inputs=[USEquityPricing.close],
         window_length=20,
         center_of_mass=com,
     )
     implied_com = self.decay_rate_to_com(from_com.params['decay_rate'])
     assert_almost_equal(com, implied_com)
Exemple #2
0
 def test_from_halflife(self, type_, halflife):
     from_hl = EWMA.from_halflife(
         inputs=[USEquityPricing.close],
         window_length=20,
         halflife=halflife,
     )
     implied_hl = self.decay_rate_to_halflife(from_hl.params['decay_rate'])
     assert_almost_equal(halflife, implied_hl)
Exemple #3
0
    def test_ewm_stats(self, window_length):

        def ewma_name(decay_rate):
            return 'ewma_%s' % decay_rate

        def ewmstd_name(decay_rate):
            return 'ewmstd_%s' % decay_rate

        decay_rates = [0.25, 0.5, 0.75]
        ewmas = {
            ewma_name(decay_rate): EWMA(
                inputs=(USEquityPricing.close,),
                window_length=window_length,
                decay_rate=decay_rate,
            )
            for decay_rate in decay_rates
        }

        ewmstds = {
            ewmstd_name(decay_rate): EWMSTD(
                inputs=(USEquityPricing.close,),
                window_length=window_length,
                decay_rate=decay_rate,
            )
            for decay_rate in decay_rates
        }

        all_results = self.engine.run_pipeline(
            Pipeline(columns=merge(ewmas, ewmstds)),
            self.dates[window_length],
            self.dates[-1],
        )

        for decay_rate in decay_rates:
            ewma_result = all_results[ewma_name(decay_rate)].unstack()
            ewma_expected = self.expected_ewma(window_length, decay_rate)
            assert_frame_equal(ewma_result, ewma_expected)

            ewmstd_result = all_results[ewmstd_name(decay_rate)].unstack()
            ewmstd_expected = self.expected_ewmstd(window_length, decay_rate)
            assert_frame_equal(ewmstd_result, ewmstd_expected)