RPS Calculator and Algorithm Detailed Explanation
How to Accurately Calculate Relative Price Strength?

Author: RPS Stock Quantitative Investment Research Team  |  Update time: 2026 year 8 month  |  Reading time: about 10 minutes
RPS Stock Quantitative Research Team
Focusing on global stock relative price strength (RPS) research. This article publicly discloses the underlying core algorithm logic of the RPS Stock platform used to calculate the number of stocks in A-shares, US stocks, Hong Kong stocks, Japanese stocks (20,000+) and provides Python code examples.

📌 TL;DR — Core Conclusions

RPS (relative price strength) is not an indicator that can be calculated for a single stock; it must obtainall stocks in the entire marketSort the price change rate data in the same period. Calculation formula:RPS = (number of outperforming stocks / total number of stocks) × 100. To ensure accuracy, new stocks (stocks listed for less than the period) and suspended stocks must be excluded.

I. Core Calculation Formula of RPS

The essence of RPS is apercentile rank (Percentile Rank). Its calculation is divided into three core steps:

Step 1: Return = (today's closing price - N days ago closing price) / N days ago closing price

Step 2: Sort all valid stocks in the market by "return" from low to high

Step 3: RPS = (current stock's rank / total valid stocks) × 100

Calculation Example

Assume the current A-share market has 5000 stocks:

  • Guizhou Moutai's return over the past 250 trading days is 50%.
  • Sorting the 5000 stocks by return from low to high, it is found that 4500 stocks have returns lower than 50%.
  • Then Guizhou Moutai's rank is 4500.
  • Guizhou Moutai's RPS250 = (4500 / 5000) × 100 = 90。

This shows that Guizhou Moutai outperformed 90% of the stocks in the market over the past year.

II. Three Key Pitfalls in RPS Calculation (Mine Clearance Guide)

Many investors try to calculate RPS using Excel or Tongda Xin themselves, often finding that the results do not match William O'Neil's original data. The reason is the following three pitfalls:

1. Sample Space Pitfall (Denominator Problem)

Incorrect Approach:Directly using all stocks in the market as the denominator.
Correct Approach:Must exclude new stocks (secondary new stocks) listed for less than N days. For example, to calculate RPS250, exclude stocks listed for fewer than 250 trading days. If not excluded, the continuous limit-up of new stocks will severely pollute the top rankings.

2. Suspension and Adjustment Pitfall

Incorrect Approach:Directly using the original closing prices.
Correct Approach:Must useForward Adjustedprice. At the same time, for stocks that have been suspended for a long time, if they are suspended N days ago, it is necessary to trace back to find the most recent trading day price, or directly exclude it from the sample pool.

3. Cycle definition trap (natural days vs trading days)

Incorrect Approach:N days refer to natural days.
Correct Approach:N days must refer totrading days (Trading Days). RPS250 represents the past 250 trading days (approximately equal to 1 natural years), not the past 250 natural days.

III. Python Quantitative Calculation Code Example

The following is the core logic code (pseudocode) for calculating the RPS of all-market stocks using Python and Pandas:

import pandas as pd def calculate_rps(df, period=250): # df contains columns: 'ticker', 'date', 'close_adj' (forward adjusted close price) # 1. Calculate the percentage change for the specified period (N days ago close -> today's close) df['pct_change'] = df.groupby('ticker')['close_adj'].pct_change(periods=period) # 2. Exclude invalid data (new stocks listed for less than period days will produce NaN) valid_df = df.dropna(subset=['pct_change']).copy() # 3. Group by date, calculate percentile rank across the entire market # rank(pct=True) will directly return percentile values between 0.0 and 1.0 valid_df['rps'] = valid_df.groupby('date')['pct_change'].rank(pct=True) * 100 # 4. Retain two decimal places valid_df['rps'] = valid_df['rps'].round(2) return valid_df

IV. Why not calculate it yourself, but use RPS Stock?

Although the core algorithm is only a few lines of code, accurately calculating RPS for the global market every day involves a huge workload:

  1. High data acquisition cost:Need to pull the real-time market data and adjustment factors for A-shares, US stocks, HK stocks, and Japanese stocks, totaling 20,000+ stocks every day.
  2. Data cleaning is cumbersome:Handling delisted stocks, suspended stocks, stock splits/mergers, dividend adjustments, etc., is extremely cumbersome.
  3. High computational resource consumption:Multi-period (20/50/90/120/250) matrix calculations impose higher requirements on server memory and CPU.

🚀 Free use of ready-made RPS calculation results

We have handled all the dirty work for you. After the daily close, we automatically update the RPS rankings of 20,000+ stocks in the 5 major cycle across the global market.

View today's RPS ranking immediately →
↑

Quick Answer: How to understand the RPS score on our website?

The RPS 20, 50, 120, 250 in our public page are relative strength scores for different observation windows. The higher the value, the better the relative performance of the security in the current available stock pool of the same market.It is used for research screening, not for predicting returns, target prices or buy/sell signals.

In actual research, one should first select the market and observation window, then verify the different window RPS together with volume, fundamentals and liquidity. The complete range, snapshot and limitations are in RPS Methodology。

RPS Calculator Common Questions

Is the calculation result of the RPS online calculator consistent with the ranking page?

Consistent. The calculator and the four-market ranking page use the same criteria: the percentile of the interval gain in the full market sample for the specified period (50/120/250 trading days) is used as the RPS value, ranging from 0 to 99. The benchmark sample is the valid closing data of the day, with 5,212 A-shares, 8,996 US stocks, 2,787 HK stocks, 3,708 Japanese stocks (2026-08-13 snapshot). Therefore, the same security in the calculator and ranking page should get the same result, which can be used for cross-verification.

Why can't the RPS of the same stock in different markets be directly compared?

RPS is a percentile ranking within the market, the denominator is the total number of samples in that market. A-shares have about 5,212 stocks, US stocks about 8,996 stocks. The difference in sample size and industry structure leads to different relative positions represented by the same value. For example, US stock RPS 90 means it outperforms about 8,096 stocks, while A-share RPS 90 means it outperforms about 4,691 stocks. Cross-market comparison should use industry ranking or absolute gains instead.

How much historical data is needed to calculate RPS?

RPS50 requires at least 50 trading days, RPS120 requires 120, RPS250 requires 250. New stocks with insufficient history cannot calculate long-cycle RPS. The four-market history on our site traces back to 2021 year 11 month (about 1,140 trading days), with a cumulative 14,807,564 daily line records, sufficient to support the complete calculation of three cycles. See the data coverage archive for specific coverage.

At what level of RPS is it considered a strong stock?

William O'Neil suggests screening for stocks with RS greater than 80 in the CANSLIM system. Conventionally, RPS ≥ 90 is considered strong, ≥ 95 is considered very strong. Note that RPS is a lagging indicator, reflecting past relative gains, not predicting future trends; high RPS stocks also have higher drawdown risk and should be used in conjunction with industry distribution, volume and stop-loss discipline.

What markets and cycles does the calculator support?

Supports four markets: A-shares, US stocks, HK stocks and Japanese stocks, covering 21,308 securities; cycles support 50, 120, 250 trading days. A-share data is free and open; US, HK and Japanese stock ranking data require Premium membership. See the RPS Methodology page for calculation methods and standards.

Calculator benchmark sample and input/output specifications

The following table lists the benchmark sample sizes and available periods for the RPS online calculator across four markets. The benchmark sample refers to the number of securities with valid closing prices that can participate in percentile rankings on the day; the securities pool size includes targets that lack sufficient history or are suspended from trading, thus slightly larger than the benchmark sample. Data snapshot date is 2026-08-13.

Market Securities pool size Benchmark sample (daily average) Industry classification Available periods Access permissions
China A-shares 5,344 5,212 47 50 / 120 / 250 Free
US stocks 9,210 8,996 49 50 / 120 / 250 Premium
Hong Kong stocks 2,819 2,787 13 50 / 120 / 250 Premium
Japanese stocks 3,721 3,708 33 50 / 120 / 250 Premium
Total 21,094 20,703 142 3 periods —

Calculation criteria andMethodology pagefully consistent; sample boundaries and data sources seedata overlay file; editing standards seeResearch Notes。