Non-recursive formula for RSI

70 Views Asked by At

I would like to compute RSI for some data. The interval for calculation is 14 time periods.

RSI is calculated by

$$ RSI_j = 100 - \frac{100}{1+RS_j}; $$

where

$$ RS_j = \frac{avg\ gain_j}{avg\ loss_j} $$

The formula for the first average gain $avg \ gain_1$ and first average loss $avg \ loss_1$ are following: $$ avg\ gain_1 = \frac{\sum_{k=1}^{14} gain_k}{14} $$

$$ avg\ loss_1 = \frac{\sum_{k=1}^{14} loss_k}{14} $$

All other average gains and losses are computed by:

$$ avg\ gain_j = \frac{13 \cdot avg \ gain_{j-1} + gain_j}{14} $$

$$ avg\ loss_j = \frac{13 \cdot avg \ loss_{j-1} + loss_j}{14} $$

The first RSI1 is easy to compute following the equation above. Furthermore, to get all the following RSIs one must know the value of previous one. The formula is recursive.

What I am interested in is a general formula for j-th $RSI_j$ using only the first $RSI_1$.

Any ideas? Thanks!

UPDATE:

I found answer to analytical (non-recursive) formula here.