IBD Style Relative Strength Percentile Ranking of Stocks (i.e. 0-99 Score). (Approx 3.9 average deviation score)
I also made a TradingView indicator, updated to use data generated here: https://www.tradingview.com/script/pziQwiT2/
Stocks: https://github.com/Fred6725/rs-log/blob/main/output/rs_stocks.csv
Industries: https://github.com/Fred6725/rs-log/blob/main/output/rs_industries.csv
Unfortunately the close prices loaded from the price history API are not always split adjusted. So if a stock had a split recently there is a chance the relative strength value will be wrong...
Yearly performance of stock divided by SPY performance during the same period (SPY
by default).
RS Score for Stocks = 40% * P3 + 20% * P6 + 20% * P9 + 20% * P12
RS Score for SPY = 40% * P3 + 20% * P6 + 20% * P9 + 20% * P12
With P3 the performance of the 3 last month. (P3 = Close/Close[63], for 63 days back)
Formula: RS Score = (1 + RS Score for Stocks) / (1 + RS Score for SPY)
Then all stocks are ranked from largest to smallest and a percentile is assigned from 99 to 0.
Tickers from ftp://ftp.nasdaqtrader.com/symboldirectory/nasdaqtraded.txt disregarding ETFs and all stocks where the industry and sector information couldn't be retrieved from yahoo finance.
- Open the latest successful run here: https://github.com/maximbelyayev/relative-strength/actions/workflows/exe.yml
- Download
exe-package
at the bottom (need to be logged in into github) - Exctract the
relative-strength
folder and enter it- If needed open
config.yaml
and put in your preferences
- If needed open
- Run
relative-strength.exe
- Open
config.yaml
and put in your preferences - Install requirements:
python -m pip install -r requirements.txt
- Run
relative-strength.py
Instead of running relative-strength.py
you can also:
- Run
rs_data.py
to aggregate the price data - Run
rs_ranking.py
to calculate the relative strength rankings
- in the
output
folder you will find:- the list of ranked stocks:
rs_stocks.csv
- the list of ranked industries:
rs_industries.csv
- the list of ranked stocks:
You can create a config_private.yaml
next to config.yaml
and overwrite some parameters like API_KEY
. That way you don't get conflicts when pulling a new version.
Can be switched with the field DATA_SOURCE
(Benchmark: Loads 1500 Stocks in 20m)
- Is default, no config necessary.
(Benchmark: Loads 1500 Stocks in 18m)
- Create TDAmeritrade Developer Account and App
- Put in your
API_KEY
inconfig.yaml
and changeDATA_SOURCE
.