def testSecurityMovingQuantile(self): window = 10 mq = SecurityMovingQuantile(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])) mq.push(data) if i < window: start = 0 else: start = i + 1 - window if i < 1: continue value = mq.value for name in value.index(): con = self.dataSet[name]['close'][start:(i + 1)] sorted_con = sorted(con) expected = sorted_con.index( self.dataSet[name]['close'][i]) / (len(sorted_con) - 1.) calculated = value[name] self.assertAlmostEqual( expected, calculated, 12, 'at index {0}\n' 'expected: {1:.12f}\n' 'calculated: {2:.12f}'.format(i, expected, calculated))
def MQUANTILE(window, x='x'): return SecurityMovingQuantile(window, x)
def MQUANTILE(window, dependency='x'): return SecurityMovingQuantile(window, dependency)