What is RSI?
Long story short, RSI is a trend indicator, which tells us if the market is bullish or bearish.
- Based on the general assumption, RSI with 70 or above usually means that very stock is overbought and is likely to be bearish soon.
- And, RSI with 30 or less usually means that very stock is oversold and viceversa. For example, if the RSI of your choice of stock is approaching at least 30, you can assume that the market is going to become bullish soon.
- As you can see in the graph, RSI in the early december was very high, almost exceeding 70. Since this data implies that this stock was overbought, it started going down. But then, once RSI value records low 30, it started bouncing back.
RSI is a long term trend indicator.
- Here, you can see that both RSI and the closing price went up.
- So, it is very important to determine if this accompanying rise can be sustained for a longer period.
Drawback of RSI
The general value of 70 doesn't always mean it's overbought in a very strong bull market. Also, as a lot of technical indicators, RSI value is usually reliable when they conform to the long-term trend. Therefore, the RSI is most useful in an oscillating(volatile) market where the asset price is alternating between bullish and bearish movements.
Formula for RSI
#loading the data
quandl.ApiConfig.api_key = "Wdq5f9Fa6Pq-h5zJjR5w"
data = quandl.get("WIKI/AAPL", start_date="2015-01-01", end_date="2020-10-30")
def calculateRSI(data, window):
diff = data.diff(1).dropna()
up = 0*diff
down = 0*diff
up[diff>0] = diff[diff>0]
down[diff<0] = diff[diff<0]
up = up.ewm(com=14, min_periods=window).mean()
down = down.ewm(com=14, min_periods=window).mean()
rs = abs(up/down)
rsi = 100-(100/(1+rs))
RSI = rsi['Adj. Close']
rsi_df = calculateRSI(data,14)