Skip to content
This repository was archived by the owner on Feb 19, 2022. It is now read-only.
This repository was archived by the owner on Feb 19, 2022. It is now read-only.

Calculation RSI (wrong) #6

Description

@jorgeog96

Hello guys, I am using: Python 3.6

Before, I implemented this RSI formula and pass df['Close'] prices and compute the result inside a numpy array:

def rsiFunc(prices, n=14):
    deltas = np.diff(prices)
    seed = deltas[:n+1]
    up = seed[seed>=0].sum()/n
    down = -seed[seed<0].sum()/n
    rs = up/down
    rsi = np.zeros_like(prices)
    rsi[:n] = 100. - 100./(1.+rs)

    for i in range(n, len(prices)):
         delta = deltas[i-1] # cause the diff is 1 shorter

        if delta>0:
            upval = delta
           downval = 0.
       else:
           upval = 0.
          downval = -delta

        up = (up*(n-1) + upval)/n
        down = (down*(n-1) + downval)/n

        rs = up/down
        rsi[i] = 100. - 100./(1.+rs)

    return rsi

Using this, I called my function:

      rsi = rsiFunc(df['Close'],14)

And the result something like this (example, 5 last elements of the array):

  [52.40554313 54.57421201 54.57421201 52.37816137 57.20738346]

But now using your RSI formula and the same df I obtain the following result using the exact same data before: (last 3 elements)

  0.398692 0.398692 0.478656

What is happening?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions