How to calculate relative strength of a stock against another stock or index using python ?
Relative strength is the ratio of one asset’s price to another asset or index, observed continuously over time. The ratio oscillates up and down. Rising values indicate outperformance; falling values indicate underperformance. Assuming you have the data for the stock (df_stock) and index (df_index), with “Close” column containing closing prices, the following is the Python code you can run.
# df_stock and df_index already exist and are aligned
relative_strength = df_stock['Close'] / df_index['Close']