How can i calculate RSI.

I have taken live data subscription from Zerodha now i want same value of RSI as we get on zerodha kite chart.

Plz helps me !!
  • sujith
    You need to generate candles at your end and then do the calculations.
    You can get started from here.
  • SafeInvest
    here i attach a function fro calculating rsi. If you want to create your strategy using RSI than contact me i will provide testing with backtesting.

    def rsi(df, n):
    "function to calculate RSI"
    delta = df["close"].diff().dropna()
    u = delta * 0
    d = u.copy()
    u[delta > 0] = delta[delta > 0]
    d[delta < 0] = -delta[delta < 0]
    u[u.index[n-1]] = np.mean( u[:n]) # first value is average of gains
    u = u.drop(u.index[:(n-1)])
    d[d.index[n-1]] = np.mean( d[:n]) # first value is average of losses
    d = d.drop(d.index[:(n-1)])
    rs = u.ewm(com=n,min_periods=n).mean()/d.ewm(com=n,min_periods=n).mean()
    df['RSI'] = 100 - 100 / (1+rs)
    return df
Sign In or Register to comment.