Skip to content

Commit

Permalink
Improved RSI code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gbeced committed Apr 22, 2018
1 parent 10bb582 commit e6bf301
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 23 deletions.
17 changes: 0 additions & 17 deletions pyalgotrade/technical/rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ def avg_gain_loss(values, begin, end):
return (gain/float(rangeLen-1), loss/float(rangeLen-1))


def rsi(values, period):
assert(period > 1)
if len(values) < period + 1:
return None

avgGain, avgLoss = avg_gain_loss(values, 0, period)
for i in xrange(period, len(values)):
gain, loss = gain_loss_one(values[i-1], values[i])
avgGain = (avgGain * (period - 1) + gain) / float(period)
avgLoss = (avgLoss * (period - 1) + loss) / float(period)

if avgLoss == 0:
return 100
rs = avgGain / avgLoss
return 100 - 100 / (1 + rs)


class RSIEventWindow(technical.EventWindow):
def __init__(self, period):
assert(period > 1)
Expand Down
6 changes: 0 additions & 6 deletions testcases/technical_rsi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ def testDateTimes(self):
for i in range(len(rsi)):
self.assertEqual(rsi.getDateTimes()[i], None)

def testRSIFunc(self):
values = [44.3389, 44.0902, 44.1497, 43.6124, 44.3278, 44.8264, 45.0955, 45.4245, 45.8433, 46.0826, 45.8931, 46.0328, 45.6140, 46.2820, 46.2820]
self.assertEqual(round(rsi.rsi(values, 14), 8), 70.53278948)
values = [44.3389, 44.0902, 44.1497, 43.6124, 44.3278, 44.8264, 45.0955, 45.4245, 45.8433, 46.0826, 45.8931, 46.0328, 45.6140, 46.2820, 46.2820, 46.0028, 46.0328, 46.4116, 46.2222, 45.6439, 46.2122, 46.2521, 45.7137, 46.4515, 45.7835, 45.3548, 44.0288, 44.1783, 44.2181, 44.5672, 43.4205, 42.6628, 43.1314]
self.assertEqual(round(rsi.rsi(values, 14), 8), 37.77295211)

def testRSI_Bounded(self):
values = [44.3389, 44.0902, 44.1497, 43.6124, 44.3278, 44.8264, 45.0955, 45.4245, 45.8433, 46.0826, 45.8931, 46.0328, 45.6140, 46.2820, 46.2820]
rsi = self.__buildRSI(values, 14, 1)
Expand Down

0 comments on commit e6bf301

Please sign in to comment.