You can use other python libraries as well which are widely used libraries such as pandas_ta , TA-lib.
df.tail()
Symbol Close
Date
2022-06-24 INFY 1443.70
2022-06-27 INFY 1477.80
2022-06-28 INFY 1482.40
2022-06-29 INFY 1464.85
2022-06-30 INFY 1462.45
RSI using pandas_ta library-
df['rsi'] = df.ta.rsi(close=df['Close'], length=14, scalar=None, drift=None, offset=None)
df.tail()
Symbol Close rsi
Date
2022-06-24 INFY 1441.10 44.913298
2022-06-27 INFY 1474.60 50.446537
2022-06-28 INFY 1480.15 51.318957
2022-06-29 INFY 1463.25 48.517840
2022-06-30 INFY 1461.90 48.291087
Ref link- https://towardsdatascience.com/trading-strategy-technical-analysis-with-python-ta-lib-3ce9d6ce5614
https://github.com/twopirllc/pandas-ta
If DataFrame contains multiple symbol like df_new
contains "INFY","TCS","HDFCBANK"
symbols,RSI can be calculated using for loop
for single dataframe. Complete code below.
Code-
# symbol_lst = ["INFY","TCS","HDFCBANK"]
!pip install investpy
df = get_history(symbol="INFY",
start= date(2021,6,10),
end= date(2022,6,30),index=False,
futures=False
)
df1 = get_history(symbol="TCS",
start= date(2021,6,10),
end= date(2022,6,30),index=False,
futures=False
)
df2 = get_history(symbol="HDFCBANK",
start= date(2021,6,10),
end= date(2022,6,30),index=False,
futures=False
)
df_new = df.append([df1,df2]) #dataframe with multiple symbols
unique_symbol = df_new['Symbol'].unique()
unique_symbol.tolist()
new = [] #Created Empty lst
for item in unique_symbol:
hi = df_new.loc[df_new['Symbol'] == item]
hi["RSI"] = hi.ta.rsi(close=hi['Close'], length=14, scalar=None, drift=None, offset=None)
new.append(hi)
df_rsi = pd.concat(new, axis=0)
df_rsi.tail()