RSI values not matching Kite daily candles (off by 0.02)

Tannu
Hello, I am implementing RSI using Wilder’s smoothing in Python and I am trying to match the values shown on Kite/TradingView.

Environment: Python 3.9, pandas/numpy

Indicator: RSI (period = 14)

Data: Daily OHLCV candles from Kite Connect API

Code logic:

Seed average gain/loss with SMA of first period values

Apply Wilder’s recursive smoothing

Round RSI to 2 decimals at the end

For minute candles, my RSI matches Kite exactly. But for daily candles, I consistently see a small difference of about 0.02. Example:

My RSI = 67.47

Kite RSI = 67.49

I have already tried:

Rounding inside the smoothing loop

Rounding only at the end

Using adjusted OHLC data

Checking for missing days in daily candles

Still, the difference of 0.02 persists.

Is this difference expected due to Kite’s internal rounding/precision, or is there a specific adjustment needed for daily candles to match Kite/TradingView exactly?
Here is my code:-

def _calc_rsi(df: pd.DataFrame, period: int, uid: str) -> Dict[str, pd.Series]:
close = pd.to_numeric(df["close"], errors="coerce").astype(float).ffill().bfill()
delta = close.diff()

gain = delta.clip(lower=0)
loss = -delta.clip(upper=0)


avg_gain = [np.nan] * len(close)
avg_loss = [np.nan] * len(close)

avg_gain[period] = gain.iloc[:period].mean()
avg_loss[period] = loss.iloc[:period].mean()


for i in range(period + 1, len(close)):
avg_gain[i] = (avg_gain[i - 1] * (period - 1) + gain.iloc[i]) / period
avg_loss[i] = (avg_loss[i - 1] * (period - 1) + loss.iloc[i]) / period


avg_gain = pd.Series(avg_gain, index=close.index)
avg_loss = pd.Series(avg_loss, index=close.index)

rs = avg_gain / avg_loss
rsi = 100 - (100 / (1 + rs))
rsi = rsi.round(2)

df[uid] = rsi
return {uid: df[uid]}
  • salim_chisty
    The small difference of about 0.02 between your calculated RSI and the value displayed on Kite/TradingView is expected. This variation arises due to minor differences in data aggregation timing, internal rounding precision, and the specific seeding method used for Wilder’s smoothing. Please note that the calculations on Kite are provided by the charting vendor.
    For more details, you can refer to the materials provided here. If the difference remains consistently negligible, it is likely due to rounding off.
Sign In or Register to comment.