예제 #1
0
 def test_multiple_talib_with_args(self):
     zipline_transforms = [ta.MA(timeperiod=10),
                           ta.MA(timeperiod=25)]
     talib_fn = talib.abstract.MA
     algo = TALIBAlgorithm(talib=zipline_transforms)
     algo.run(self.source)
     # Test if computed values match those computed by pandas rolling mean.
     sid = 0
     talib_values = np.array([x[sid] for x in
                              algo.talib_results[zipline_transforms[0]]])
     np.testing.assert_array_equal(talib_values,
                                   pd.rolling_mean(self.panel[0]['price'],
                                                   10).values)
     talib_values = np.array([x[sid] for x in
                              algo.talib_results[zipline_transforms[1]]])
     np.testing.assert_array_equal(talib_values,
                                   pd.rolling_mean(self.panel[0]['price'],
                                                   25).values)
     for t in zipline_transforms:
         talib_result = np.array(algo.talib_results[t][-1])
         talib_data = dict()
         data = t.window
         # TODO: Figure out if we are clobbering the tests by this
         # protection against empty windows
         if not data:
             continue
         for key in ['open', 'high', 'low', 'volume']:
             if key in data:
                 talib_data[key] = data[key][0].values
         talib_data['close'] = data['price'][0].values
         expected_result = talib_fn(talib_data, **t.call_kwargs)[-1]
         np.testing.assert_allclose(talib_result, expected_result)
예제 #2
0
    def test_talib_with_minute_data(self):

        ma_one_day_minutes = ta.MA(timeperiod=10, bars='minute')

        # Assert that the BatchTransform window length is enough to cover
        # the amount of minutes in the timeperiod.

        # Here, 10 minutes only needs a window length of 1.
        self.assertEquals(1, ma_one_day_minutes.window_length)

        # With minutes greater than the 390, i.e. one trading day, we should
        # have a window_length of two days.
        ma_two_day_minutes = ta.MA(timeperiod=490, bars='minute')
        self.assertEquals(2, ma_two_day_minutes.window_length)