-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Comments
I believe time period matches the definition of RSI in most formulas. I would expect n=1 to use two observations. On Jul 6, 2023, at 7:09 PM, TrainedPro ***@***.***> wrote:
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:
Import the TA-Lib library.
Create a sample DataFrame with a single column.
Calculate the RSI with a window size of 'timeperiod - 1' using the talib.RSI() function.
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
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
I think the equivalent of talib rsi is : and for sma : This may help to understand why rsi needs 1 value more than the period. You can find more on rsi formulae here : https://www.macroption.com/rsi-calculation/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
talib.RSI()
function.Code
Actual Behaviour
If
timeperiod
values are in dataframe, it would return Nan, the above code that hastimeperiod + 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
Additional Information
The text was updated successfully, but these errors were encountered: