Investment Studio > Expressions > Functions > Indicator > RS

float array[*][2] rs(float array[*][2] dc_asset, float array[*][2] dc_reference, integer days)

Returns a two-column array containing dates (first column) and corresponding Relative Strength (RS) values (second column).

dc_asset is a two-column array containing dates (first column) and corresponding daily closing prices (second column) for the asset under study. The array is assumed to be time-sorted, with earlier dates preceding later dates.

dc_reference is a two-column array containing dates (first column) and corresponding daily closing prices (second column) for a second asset, market index or similar, relative to which the strength of the first asset is to be computed.

In both arrays, automatic type conversion allows the use of date strings as arguments instead of explicit date values.

days > 0 is the length of the time frame (in terms of trading days with known closes for both asset and reference) over which each day's RS is computed.

Interpretation

RS (which should not be confused with the very different RSI) is a measure of an asset's price performance relative to another asset, market index or similar. Each day's RS value is a ratio of two price ratios:

  asset close / reference close
RS =  ¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
  asset close days ago / reference close days ago

Only days with known closes for both asset and reference count.

RS > 1 means that the current price ratio is higher than the old price ratio, i.e. the asset has outperformed the reference over the last days. If the reference is up 10% while the asset is up 20%, RS = 1.2 / 1.1 = 1.0909...

RS < 1 means that the current price ratio is lower than the old price ratio, i.e. the asset has underperformed the reference. If the reference is up 20% while the asset is up 10%, RS = 1.2 / 1.1 = 0.91666...

Subtract 1 and multiply by 100 to get a measure of over- or underperformance in percentage terms.

RS can be used to pick winning assets within a sector (using a sector index as reference), winning sectors within the market (using a broad market index as reference and sector indices as assets) or candidates for market-neutral plays (asset pairs in which one asset consistently outperforms the other, independently of the overall direction of the market; as long as this relationship holds true, going long the stronger asset while shorting the weaker one will yield a positive net, even if both assets fall).

For a real life example, consider Ericsson (NASD:ERICY) relative to Nokia (NYSE:NOK) from January 1 to December 31, 2001:

The top chart shows daily NOK (green) and ERICY (red) closes. The bottom chart shows the 10 day RS of ERICY vs. NOK (in red) and its 10 day EMA (in blue). The RS = 1 (par) level is marked in gray.

Example

Assuming standard US date format settings,

=rs({{"1/1/1990", 100}, {"1/2/1990", 110}}, {{"1/1/1990", 90}, {"1/2/1990", 80}}, 1)

returns {{32875, 1.2375}}. 32875 is the date code for 1/2/1990; 1.2375 = (110 / 80) / (100 / 90) is the 1 day RS value for that date.

The RS chart above uses the definitions

_NDAYS = 10

_REF_ASSET = match("NOK", mop("asset_symbol()", makevector(1000, 0, 1)), 0) - 1

_REF_QUOTES = asset_quotes(_REF_ASSET, "C", FROM_DATE - 3 * _NDAYS, TO_DATE)

_RS = rs(asset_quotes(SELF, "C", FROM_DATE - 3 * _NDAYS, TO_DATE), array(_REF_QUOTES), _NDAYS)

_EMA = ema(array(_RS), _NDAYS)

and the line sources

vlookup(X, array(_RS), 2, FALSE)

vlookup(X, array(_EMA), 2, FALSE)

See also ba, correl, linest, logest.