def testSecurityMovingVariance(self): window = 10 var = SecurityMovingVariance(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])) var.push(data) if i <= 1: continue if i < window: start = 0 else: start = i + 1 - window value = var.value for name in value.index(): expected = 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))
def MVARIANCE(window, dependency='x'): return SecurityMovingVariance(window, dependency)
def MVARIANCE(window, x='x'): return SecurityMovingVariance(window, x)
def VARIANCE(window, dependency='x', symbolList=None): return SecurityMovingVariance(window, dependency, symbolList)