Open TrainedPro opened 1 year ago
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
data = { 'col1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], }
df = pd.DataFrame(data)
rsi = talib.RSI(df['col1'], timeperiod=9)
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
data = { 'col1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], }
df = pd.DataFrame(data)
sma = talib.SMA(df['col1'], timeperiod=9)
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