Price Relative Strength (PRS)
get_prs(eval_history, base_history, lookback_periods=None, sma_periods=None)
Parameters
| name | type | notes |
|---|---|---|
eval_history | Iterable[Quote] | Historical quotes for evaluation. You must have the same number of periods as base_history. • See here for usage with pandas.DataFrame |
base_history | Iterable[Quote] | Iterable of the Quote class or its sub-class. |
lookback_periods | int, Optional | Number of periods (N) to lookback to compute % difference. Must be greater than 0 if specified or None. |
sma_periods | int, Optional | Number of periods (S) in the SMA lookback period for prs. Must be greater than 0. |
Historical quotes requirements
You must have at least N periods of base_history to calculate prs_percent if lookback_periods is specified; otherwise, you must specify at least S+1 periods. More than the minimum is typically specified. For this indicator, the elements must match (e.g. the nth elements must be the same date). An Exception will be thrown for mismatch dates. Historical price quotes should have a consistent frequency (day, hour, minute, etc).
base_history is an Iterable[Quote] collection of historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.
Return
PRSResults[PRSResult]
- This method returns a time series of all available indicator values for the
quotesprovided. PRSResultsis just a list ofPRSResult.- It always returns the same number of elements as there are in the historical quotes.
- It does not return a single incremental indicator value.
- The
Nperiods will haveNonevalues forprs_percentand the firstS-1periods will haveNonevalues forsmasince there’s not enough data to calculate.
PRSResult
| name | type | notes |
|---|---|---|
date | datetime | Date |
prs | float, Optional | Price Relative Strength compares eval_history to base_history |
prs_sma | float, Optional | Moving Average (SMA) of PRS over S periods |
prs_percent | float, Optional | Percent change difference between eval_history and base_history over N periods |
Utilities
See Utilities and Helpers for more information.
Example
from stock_indicators import indicators
# This method is NOT a part of the library.
history_SPX = get_historical_quotes("SPX")
history_TSLA = get_historical_quotes("TSLA")
# Calculate 14-period PRS
results = indicators.get_prs(history_SPX, history_TSLA, 14)
About Price Relative Strength (PRS)
Price Relative Strength (PRS), also called Comparative Relative Strength, shows the ratio of two quote histories, based on Close price. It is often used to compare against a market index or sector ETF. When using the optional lookback_periods, this also returns relative percent change over the specified periods. This is not the same as the more prevalent Relative Strength Index (RSI). [Discuss] 💬
