code: def rsi(series, window=14):
      
  
      # 100-(100/relative_strength)
      deltas = np.diff(series)
      seed = deltas[:window + 1]
  
      # default values
      ups = seed[seed > 0].sum() / window
      downs = -seed[seed < 0].sum() / window
      rsival = np.zeros_like(series)
      rsival[:window] = 100. - 100. / (1. + ups / downs)
  
      # period values
      for i in range(window, len(series)):
          delta = deltas[i - 1]
          if delta > 0:
              upval = delta
              downval = 0
          else:
              upval = 0
              downval = -delta
  
          ups = (ups * (window - 1) + upval) / window
          downs = (downs * (window - 1.) + downval) / window
          rsival[i] = 100. - 100. / (1. + ups / downs)
  
      # return rsival
      return pd.Series(index=series.index, data=rsival)
docs: compute the n period relative strength indicator