Relative Strength (RS) Ratings
Relevant source files
The following files were used as context for generating this wiki page:
Relative Strength (RS) Ratings provide a cross-sectional percentile rank of a stock's price performance compared to the NIFTY 500 benchmark. The system calculates these ratings locally using front-weighted scores across multiple time horizons to identify market leadership.
The ratings are computed during the enrichment phase of the data pipeline and are published as part of the daily scanner snapshot. A stock receives a rating between 1 and 99, where a higher number indicates stronger performance relative to the liquid universe. Sources: build_rs_ratings.py:1-5, README.md:377-380
Calculation Methodology
The calculation engine evaluates price performance over four specific horizons. It applies a higher weight to recent performance to capture momentum shifts accurately.
Weights and Horizons
The system uses the following configuration for time windows and their respective weights:
| Horizon | Trading Sessions | Weight |
|---|---|---|
| One Month | 21 | 40% |
| Three Month | 63 | 20% |
| Six Month | 126 | 20% |
| Twelve Month | 252 | 20% |
Sources: build_rs_ratings.py:16-27
Scoring Formulas
- Horizon Ratio: For each window, the ratio is calculated as
(Stock_Price_Ratio / Benchmark_Price_Ratio). Sources: build_rs_ratings.py:122 - Front-Weighted Score: The aggregate score is the sum of weighted horizon ratios. Sources: build_rs_ratings.py:77-80
- Percentile Rank: Scores are mapped to a 1–99 scale using the formula:
1 + (strictly_lower_scores / total_eligible) * 98. The result is rounded to the nearest integer and clipped to stay within the 1-99 range. Sources: build_rs_ratings.py:86-90, build_rs_ratings.py:124
System Logic and Data Flow
The build_rs_ratings.py script executes the calculation logic. It requires a breadth_universe_snapshot.json file to identify the eligible liquid universe.
The diagram shows the sequential process from loading benchmark data to generating the final ranked JSON artifact. A rating is only generated if the stock has at least 260 aligned trading sessions with the benchmark and its latest data matches the benchmark's current session. Sources: build_rs_ratings.py:28, build_rs_ratings.py:53-61, build_rs_ratings.py:94-110
Pipeline Integration
Relative Strength calculation is a Phase 4 (Enrichment) task. It depends on the outputs of the Breadth analysis (Phase 4) and OHLCV fetching (Phase 2).
Execution Sequence
The RS calculation script specifically uses the breadth_eligible universe to ensure ratings are only generated for liquid, tradable securities. Sources: src/edl_pipeline/artifacts.py:93-107, src/edl_pipeline/runner.py:382-390, README.md:278-281
Frontend and Screening Usage
The frontend screener uses RS ratings to filter for momentum leaders. Users can select different horizons (1 month, 3 month, 12 month) or the overall front-weighted rating.
Condition Configuration
The RS_RATING condition is defined in the native conditions catalog:
- ID:
RS_RATING - Parameters:
window: The horizon to check (ONE_MONTH, THREE_MONTH, TWELVE_MONTH, or front_weighted).comparison: Comparison operator (ABOVE or BELOW).value: The percentile threshold (default 80).
Sources: frontend/src/data/nativeConditions.json:522-570
Data Structure in Artifacts
The final ratings are stored in the ratings key of rs_rating_daily.json:
{
"symbol": {
"one_month": 95,
"three_month": 92,
"six_month": 88,
"twelve_month": 85,
"front_weighted": 93
}
}
Sources: build_rs_ratings.py:112-115, tests/test_integrity.py:255-259
Validation and Integrity
The pipeline runner validates the RS ratings artifact before publication. A refresh fails if no breadth-eligible symbols have 260 aligned sessions or if the benchmark file is missing. The validator ensures the ratings key contains a non-empty dictionary and checks for the presence of the as_of_date. Sources: build_rs_ratings.py:116-118, src/edl_pipeline/artifacts.py:195-197, tests/test_integrity.py:302-315
Relative Strength ratings provide a standardized, comparative metric that filters market noise, focusing on stocks that are outperforming the broader market index across multiple timeframes.