I have a data frame "Hist" in which I'd like to add another level for different RSI calculations from the ta library. This is an excerpt my current data frame with stock prices:
Hist.head()
Date AAPL AMC AYX
6/15/2020 85.75 5.80 142.94
6/16/2020 88.02 5.56 145.69
6/17/2020 87.90 5.42 150.99
6/18/2020 87.93 5.63 160.78
6/19/2020 87.43 5.52 163.56
And this is an example of the data frame I'd like to create using a loop of the RSI method for both 5 day and 14 day results:
indicator_rsi = RSIIndicator(close=Hist["Ticker"], window=5) # Calculates RSI for 5 days
Hist['RSI_5'] = indicator_rsi.rsi()
Stock Prices RSI_5 RSI_14
Date AAPL AMC AYX AAPL AMC AYX AAPL AMC AYX
6/15/2020 85.75 5.80 142.94 ## ## ## ## ## ##
6/16/2020 88.02 5.56 145.69 ## ## ## ## ## ##
6/17/2020 87.90 5.42 150.99 ## ## ## ## ## ##
6/18/2020 87.93 5.63 160.78 ## ## ## ## ## ##
6/19/2020 87.43 5.52 163.56 ## ## ## ## ## ##
IIUC, you can try something like this:
Output:
Here, I am using
pd.concat
withaxis=1
and thekeys
parameter to create a multiindex for the column headers. These numbers are simulated using rolling mean calculation not your actual RSIIndicator function.