Relative Strength Index (RSI)

Introduction

The Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements. Developed by J. Welles Wilder Jr. in 1978, the RSI is primarily used to identify overbought and oversold conditions in a market, helping traders make informed decisions about potential reversals.

Calculation of RSI

The RSI is calculated using the following steps:

  1. Calculate the Average Gain and Average Loss:

    • Average Gain = (Sum of Gains over n periods) / n
    • Average Loss = (Sum of Losses over n periods) / n
  2. Calculate the Relative Strength (RS):

mathematical expression or equation
  1. Calculate the RSI:
mathematical expression or equation

Where n is typically set to 14 periods.

Example Calculation

Assume we have the following closing prices for a stock over 14 days:

DayClosing Price
1$44
2$46
3$45
4$47
5$48
6$50
7$49
8$51
9$50
10$52
11$51
12$53
13$54
14$56
  1. Calculate Daily Gains and Losses:

    • Days with gains:

      • Day 2: $46 - $44 = $2
      • Day 4: $47 - $45 = $2
      • Day 5: $48 - $47 = $1
      • Day 6: $50 - $48 = $2
      • Day 8: $51 - $49 = $2
      • Day 10: $52 - $50 = $2
      • Day 12: $53 - $51 = $2
      • Day 13: $54 - $53 = $1
      • Day 14: $56 - $54 = $2
    • Days with losses:

      • Day 3: $45 - $46 = -$1
      • Day 7: $49 - $50 = -$1
      • Day 9: $50 - $51 = -$1
      • Day 11: $51 - $52 = -$1
  2. Calculate Average Gain and Average Loss:

    • Average Gain = (2 + 2 + 1 + 2 + 2 + 2 + 2 + 1 + 2) / 14 ≈ 1.43
    • Average Loss = (1 + 1 + 1 + 1) / 14 ≈ 0.29
  3. Calculate RS:

mathematical expression or equation
  1. Calculate RSI:
mathematical expression or equation

Python Code

import pandas as pd

def calculate_rsi(data, window=14):
    """Calculate the Relative Strength Index (RSI) for a given data series."""
    # Calculate the price differences
    delta = data['Close'].diff()
    
    # Calculate gains and losses
    gain = (delta.where(delta > 0, 0)).rolling(window=window).mean()
    loss = (-delta.where(delta < 0, 0)).rolling(window=window).mean()
    
    # Calculate the Relative Strength (RS)
    rs = gain / loss
    
    # Calculate the RSI
    rsi = 100 - (100 / (1 + rs))
    
    return rsi

Interpretation of RSI

  • Overbought Conditions: An RSI above 70 generally indicates that the asset is overbought and may be due for a price correction.
  • Oversold Conditions: An RSI below 30 indicates that the asset is oversold and might be undervalued, suggesting a potential buying opportunity.
  • Divergence: When the price moves in the opposite direction of the RSI, it may signal an impending reversal.

Analogy

Think of the RSI like a temperature gauge for a bullish or bearish market. A temperature reading above 70 degrees represents a hot market (overbought), where traders might consider it too hot to handle. Conversely, a reading below 30 degrees indicates a cold market (oversold), where things may be undervalued and could warm up soon. Just as a temperature gauge helps us understand whether we need to bundle up or cool down, the RSI helps traders assess market conditions and make informed decisions.

Conclusion

The Relative Strength Index is a valuable momentum indicator that provides insights into price trends, potential reversals, and market conditions. By understanding and applying the RSI, traders can make better-informed trading decisions.


References