All problems
RSI Value
Problem
Compute the Relative Strength Index over the last period price changes using simple averages: gain = mean of positive changes, loss = mean of absolute negative changes, RSI = 100 - 100 / (1 + gain/loss).
Return 100.0 when the average loss is zero, and None if period is not positive or there are not enough prices.
Hint
RSI above 70 is often read as overbought; below 30 as oversold.
Test cases
case 1
in: [[1,2,3,4,5],2]
expected: 100
case 2
in: [[5,4,3,2],2]
expected: 0
case 3
in: [[10,11,10,12],2]
expected: 66.66666666666666
case 4
in: [[5],2]
expected: null
Starter codePython
def rsi(prices, period):
# Your code here
pass4 test cases · run your code against them in the editor