UNPKG

@thi.ng/transducers-stats

Version:

Transducers for statistical / technical analysis

28 lines (27 loc) 718 B
import { comp } from "@thi.ng/transducers/comp"; import { drop } from "@thi.ng/transducers/drop"; import { iterator1 } from "@thi.ng/transducers/iterator"; import { map } from "@thi.ng/transducers/map"; import { multiplex } from "@thi.ng/transducers/multiplex"; import { momentum } from "./momentum.js"; import { sma } from "./sma.js"; function rsi(period, src) { return src ? iterator1(rsi(period), src) : comp( momentum(1), multiplex( comp( map((x) => x > 0 ? x : 0), sma(period) ), comp( map((x) => x < 0 ? -x : 0), sma(period) ) ), drop(period - 1), map((hl) => 100 - 100 / (1 + hl[0] / Math.max(1e-6, hl[1]))) ); } export { rsi };