Skip to content

Percentile Nearest Rank #17

@mrjbq7

Description

@mrjbq7

Received this issue request:

TA-Lib/ta-lib-python#687

Hello,
I'd like to have similar to TradingView a percentile nearest rank.

I have done it with Numpy and a rolling window until now but its slow compared to anything else in my code and also isn't supported by Numba.

Below is the code so far.

Would be great if this could be added, thanks!

def strided_app(a, L): 
    nrows = a.size-L+1
    n = a.strides[0]
    strided = np.lib.stride_tricks.as_strided(a, shape=(nrows, L), strides=(n, n))
    return strided


# Compute rolling percentiles
perup = np.percentile(strided_app(per_source, window), 60, axis=1, method="nearest")
perdown = np.percentile(strided_app(per_source, window), 45, axis=1, method="nearest")

perup = np.concatenate((np.full(window - 1, np.nan), perup)) 
perdown = np.concatenate((np.full(window - 1, np.nan), perdown))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions