def relative_strength_index(data, period):
catch_errors.check_for_period_error(data, period)<EOL>period = int(period)<EOL>changes = [data_tup[<NUM_LIT:1>] - data_tup[<NUM_LIT:0>] for data_tup in zip(data[::<NUM_LIT:1>], data[<NUM_LIT:1>::<NUM_LIT:1>])]<EOL>filtered_gain = [val < <NUM_LIT:0> for val in changes]<EOL>gains = [<NUM_LIT:0> if filtered_gain[idx] is True else changes[idx] for idx in range(<NUM_LIT:0>, len(filtered_gain))]<EOL>filtered_loss = [val > <NUM_LIT:0> for val in changes]<EOL>losses = [<NUM_LIT:0> if filtered_loss[idx] is True else abs(changes[idx]) for idx in range(<NUM_LIT:0>, len(filtered_loss))]<EOL>avg_gain = np.mean(gains[:period])<EOL>avg_loss = np.mean(losses[:period])<EOL>rsi = []<EOL>if avg_loss == <NUM_LIT:0>:<EOL><INDENT>rsi.append(<NUM_LIT:100>)<EOL><DEDENT>else:<EOL><INDENT>rs = avg_gain / avg_loss<EOL>rsi.append(<NUM_LIT:100> - (<NUM_LIT:100> / (<NUM_LIT:1> + rs)))<EOL><DEDENT>for idx in range(<NUM_LIT:1>, len(data) - period):<EOL><INDENT>avg_gain = ((avg_gain * (period - <NUM_LIT:1>) +<EOL>gains[idx + (period - <NUM_LIT:1>)]) / period)<EOL>avg_loss = ((avg_loss * (period - <NUM_LIT:1>) +<EOL>losses[idx + (period - <NUM_LIT:1>)]) / period)<EOL>if avg_loss == <NUM_LIT:0>:<EOL><INDENT>rsi.append(<NUM_LIT:100>)<EOL><DEDENT>else:<EOL><INDENT>rs = avg_gain / avg_loss<EOL>rsi.append(<NUM_LIT:100> - (<NUM_LIT:100> / (<NUM_LIT:1> + rs)))<EOL><DEDENT><DEDENT>rsi = fill_for_noncomputable_vals(data, rsi)<EOL>return rsi<EOL>
Relative Strength Index.

Formula:
RSI = 100 - (100 / 1 + (prevGain/prevLoss))