Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSI Indicator Requires 1 More Value Than the ‘timeperiod’ Specifies #603

Open
TrainedPro opened this issue Jul 7, 2023 · 1 comment

Comments

@TrainedPro
Copy link

Summary:

The RSI (Relative Strength Index) indicator in the TA-Lib library requires one more value than the specified 'timeperiod'. This behavior differs from other indicators such as the SMA (Simple Moving Average), which only requires the specified number of values. This discrepancy in behavior may lead to confusion when using the RSI indicator and should be documented for clarity.

Steps to Reproduce:

  1. Import the TA-Lib library.
  2. Create a sample DataFrame with a single column.
  3. Calculate the RSI with a window size of 'timeperiod - 1' using the talib.RSI() function.
  4. Print the RSI values.

Code

import pandas as pd
import talib

# Create a sample DataFrame with 10 columns
data = {
    'col1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
}

df = pd.DataFrame(data)

# Calculate the RSI with a window size of 'timeperiod - 1'
rsi = talib.RSI(df['col1'], timeperiod=9)

# Print the RSI values
print(rsi)

Actual Behaviour

If timeperiod values are in dataframe, it would return Nan, the above code that has timeperiod + 1 values would return the proper value.

Expected Behaviour

The RSI calculation should produce valid results using the specified timeperiod without requiring an additional value. This should be inline with other function such as SMA. Code has been provided for SMA below.

Code

import pandas as pd
import talib

# Create a sample DataFrame with 10 columns
data = {
    'col1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
}

df = pd.DataFrame(data)

# Calculate the SMA with a window size of 9 (10 - 1)
sma = talib.SMA(df['col1'], timeperiod=9)

# Print the SMA values
print(sma)

Additional Information

  • TA-Lib Version: 0.4.26
  • Operating System: Ubuntu 22.04.2 LTS
  • Python Version: Python 3.10.6
@mrjbq7
Copy link
Collaborator

mrjbq7 commented Jul 7, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants