Learn R Programming

PortfolioTesteR (version 0.1.4)

calc_stochrsi: Stochastic RSI (StochRSI) for multiple price series

Description

Computes Stochastic RSI (%K) per column over a rolling window, returning values in [0, 1]. For each symbol, RSI is computed with TTR::RSI() over rsi_length periods; then StochRSI is \((RSI_t - \min RSI_{t-L+1:t}) / (\max RSI_{t-L+1:t} - \min RSI_{t-L+1:t})\), where \(L\) is stoch_length. If the range is zero the value is handled per on_const_window (default "zero").

Usage

calc_stochrsi(
  data,
  length = 14L,
  rsi_length = NULL,
  stoch_length = NULL,
  on_const_window = c("zero", "na")
)

Value

A data.table with Date and symbol columns containing StochRSI in [0, 1], with leading NAs for warmup.

Arguments

data

A data.frame or data.table with a Date column and one price column per symbol (wide format).

length

Integer lookback used when rsi_length/stoch_length are NULL. Default 14.

rsi_length

Optional integer RSI lookback. Default: length.

stoch_length

Optional integer stochastic window. Default: length.

on_const_window

How to handle windows where maxRSI == minRSI? One of "zero" (set to 0), "na" (leave NA). Default "zero".

See Also

TTR::RSI(), calc_momentum(), calc_moving_average(), filter_top_n(), weight_by_risk_parity()

Examples

Run this code
data(sample_prices_weekly)
s <- calc_stochrsi(sample_prices_weekly, length = 14)
head(s)

Run the code above in your browser using DataLab