You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importpandasaspdimporttalib# Create a sample DataFrame with 10 columnsdata= {
'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 valuesprint(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
importpandasaspdimporttalib# Create a sample DataFrame with 10 columnsdata= {
'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 valuesprint(sma)
Additional Information
TA-Lib Version: 0.4.26
Operating System: Ubuntu 22.04.2 LTS
Python Version: Python 3.10.6
The text was updated successfully, but these errors were encountered:
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: ***@***.***>
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: