Explanation: 1. Fetch candle data with interval of 1 minute from 10:00 to 10:14. 2. Make a list of close prices, gain prices and loss prices 3. Calculate RS by dividing the mean of gain_prices and loss_prices and then feed to RSI formula.
Seems to be straight forward formula but result is off. According to Kite it should be 47.64 but I am getting 52.5210. Where am I doing wrong?
import numpy as np
from datetime import datetime
from utility.config import ACCESS_TOKEN, API_KEY
k = KiteConnect(api_key=API_KEY)
history = k.historical_data(instrument_token,
datetime(2021, 8, 20, 10, 0, 0),
datetime(2021, 8, 20, 10, 14, 0),
close_list = [i['close'] for i in history]
gain_list = list()
loss_list = list()
for index, i in enumerate(close_list):
if index > 0:
change = i - close_list[index - 1]
if change > 0:
elif change < 0:
rs = np.mean(gain_list) / np.mean(loss_list)
rsi = 100 - (100 / (1 + rs))
How did you resolve it using pandas?