Calculating the RSI of a stock using Python


I have written a code using python, taking database from the db server to calculate the RSI of a stock, but the values are not matching. The correct value is 79.14 but i am getting 77.5 . This formula calculates the RS
First Average Gain = Sum of Gains over the past 14 periods / 14.
First Average Loss = Sum of Losses over the past 14 periods / 14
RS = Average Gain / Average Loss

RSI is :- (RSI) = 100 – 100 / (1 + RS)

can any one let me know if this is the correct formula or anything else.

The formula of RSI is:

RSI ​=100 − (100 / (1 + avg_gain / avg_loss​)​)

That means you are using the right formula to calculate your values.

The problem lies elsewhere. For example, sometimes if you use for or while loops, it could happen that you use ‘<’ instead of ‘<=’.
Is the procedure to read data from db-server right?

Sometimes it is helpful to post the whole code so that others could advice you efficiently!