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

        for i in range(len(self.aapl['close'])):
            data = {'aapl': {'close': self.aapl['close'][i], 'open': self.aapl['open'][i]}}
            data['ibm'] = {'close': self.ibm['close'][i], 'open': self.ibm['open'][i]}
            ma1.push(data)
            if i < 10:
                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):
            _ = SecurityMovingMinimum(window, ['close', 'open'])
Exemple #2
0
    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') + SecurityMovingMinimum(
            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)
Exemple #3
0
def MIN(window, dependency='x'):
    return SecurityMovingMinimum(window, dependency)
def MIN(window, dependency='x', symbolList=None):
    return SecurityMovingMinimum(window, dependency, symbolList)