def testSecurityMovingMinimum(self):
        window = 10
        ma1 = SecurityMovingMin(window, ['close'])

        for i in range(len(self.aapl['close'])):
            data = dict(aapl=dict(close=self.aapl['close'][i],
                                  open=self.aapl['open'][i]),
                        ibm=dict(close=self.ibm['close'][i],
                                 open=self.ibm['open'][i]))
            ma1.push(data)
            if i < window:
                start = 0
            else:
                start = i + 1 - window

            value = ma1.value
            for name in value.index():
                expected = np.min(self.dataSet[name]['close'][start:(i + 1)])
                calculated = value[name]
                self.assertAlmostEqual(
                    expected, calculated, 12, 'at index {0}\n'
                    'expected:   {1:.12f}\n'
                    'calculated: {2:.12f}'.format(i, expected, calculated))

        with self.assertRaises(ValueError):
            _ = SecurityMovingMin(window, ['close', 'open'])
    def testTransformWithoutCategory(self):
        test_df = pd.DataFrame({'b': [4, 5, 6, 7, 6, 5, 4],
                                'c': [9, 8, 7, 6, 5, 4, 3]},
                               index=[1, 2, 3, 4, 5, 6, 7],
                               dtype=float)

        expression = SecurityMovingMax(20, 'b') + SecurityMovingMin(20, 'c')
        calculated = expression.transform(test_df, name='new_factor')
        expected = [13., 13., 13., 13., 12., 11., 10.]
        np.testing.assert_array_almost_equal(calculated['new_factor'], expected)
Exemplo n.º 3
0
def MMIN(window, x='x'):
    return SecurityMovingMin(window, x)
Exemplo n.º 4
0
def MMIN(window, dependency='x'):
    return SecurityMovingMin(window, dependency)