Пример #1
0
    def testSecurityMovingStandardDeviation(self):
        window = 10
        std = SecurityMovingStandardDeviation(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]))

            std.push(data)

            if i <= 1:
                continue

            if i < window:
                start = 0
            else:
                start = i + 1 - window

            value = std.value
            for name in value.index():
                expected = math.sqrt(
                    np.var(self.dataSet[name]['close'][start:(i + 1)]) *
                    (i + 1. - start) / (i - start))
                calculated = value[name]
                self.assertAlmostEqual(
                    expected, calculated, 12, 'at index {0}\n'
                    'expected:   {1:.12f}\n'
                    'calculated: {2:.12f}'.format(i, expected, calculated))
Пример #2
0
def MSTD(window, x='x', closed="right"):
    if isinstance(window, int):
        return SecurityMovingStandardDeviation(window, x)
    elif isinstance(window, str):
        return SecurityTimeMovingStandardDeviation(window, x, closed)
    else:
        raise ValueError("wrong window format <{0}>".format(window))
Пример #3
0
def MSTD(window, x='x'):
    return SecurityMovingStandardDeviation(window, x)
Пример #4
0
def MSTD(window, dependency='x'):
    return SecurityMovingStandardDeviation(window, dependency)