Skip to main content

Module rsi

Module rsi 

Source
Expand description

§Relative Strength Index (RSI)

Wilder RSI on closes:

change[i] = close[i] − close[i−1]
avg_gain, avg_loss: Wilder smooth over `period` (first seed = SMA of gains/losses)
RS  = avg_gain / avg_loss
RSI = 100 − 100 / (1 + RS)

Default pack: period 14 (RsiParams::period_14).


§Trading perspective

RegionHabit (classic, not a rule)
RSI > 70“Overbought” screen
RSI < 30“Oversold” screen
DivergencesPrice vs RSI direction stories

§Engineering perspective

Same TA layers: RsiParamsValidatedRsi / rsiRsiStatersi_solution. Warm-up bars are None until the Wilder seed is ready (index period first possible).

§Word problem

Fourteen closes are flat then one up-bar. Is RSI defined on the last bar of a 15-long series?

Yes after seed: first RSI appears at index period (needs period changes ⇒ period+1 closes).

use finance_solution::stocks::ta::{rsi, RsiParams};
let mut c: Vec<f64> = (0..15).map(|i| 100.0 + i as f64).collect();
let s = rsi(&c, RsiParams::period_14()).unwrap();
assert!(s.rsi[14].is_some());
assert!(s.rsi[13].is_none());

Structs§

RsiParams
RSI lookback pack (Wilder).
RsiSeries
RsiSolution
RsiState
Incremental Wilder RSI.
ValidatedRsi
Validated RSI config.

Functions§

rsi
rsi_solution
Examples