def testSecurityMovingRSI(self): window = 10 rsi = SecurityMovingRSI(window, ['close']) pos_avg = SecurityMovingPositiveDifferenceAverage(window, ['close']) neg_avg = SecurityMovingNegativeDifferenceAverage(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])) rsi.push(data) pos_avg.push(data) neg_avg.push(data) value = rsi.value if i > 0: for name in value.index(): expected = pos_avg.value[name] / ( pos_avg.value[name] - neg_avg.value[name]) * 100 calculated = value[name] self.assertAlmostEqual( expected, calculated, 12, 'at index {0}\n' 'expected: {1:.12f}\n' 'calculated: {2:.12f}'.format(i, expected, calculated))
def testSecurityMovingRSI(self): window = 10 rsi = SecurityMovingRSI(window, ['close']) pos_avg = SecurityMovingPositiveDifferenceAverage(window, ['close']) neg_avg = SecurityMovingNegativeDifferenceAverage(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]} rsi.push(data) pos_avg.push(data) neg_avg.push(data) value = rsi.value if i > 0: for name in value.index: expected = pos_avg.value[name] / (pos_avg.value[name] - neg_avg.value[name]) * 100 calculated = value[name] self.assertAlmostEqual(expected, calculated, 12, 'at index {0}\n' 'expected: {1:.12f}\n' 'calculated: {2:.12f}'.format(i, expected, calculated))
def RSI(window, dependency='x'): return SecurityMovingRSI(window, dependency)
def RSI(window, x='x'): return SecurityMovingRSI(window, x)
def RSI(window, dependency='x', symbolList=None): return SecurityMovingRSI(window, dependency, symbolList)