This project is part of the @thi.ng/umbrella monorepo.
Transducers for statistical / technical analysis. This is a support package for @thi.ng/transducers.
This package provides a set of transducers for technical (financial) and statistical analysis and replaces the older @thi.ng/indicators package.
The transducers provided here accept an optional input iterable, which
allows them them to be used directly instead of having to wrap their
call in one of the transducer execution functions (i.e. transduce()
,
iterator()
). If executed this way, the functions will return a
transforming ES6 iterator (generator) instead of a transducer.
- Bollinger Bands
- Donchian Channel
- EMA (Exponential Moving Average)
- HMA (Hull Moving Average)
- MACD (Moving Average Convergence/Divergence)
- Momentum
- ROC (Rate of change)
- RSI (Relative Strength Index)
- SD (Standard Deviation)
- SMA (Simple Moving Average)
- Stochastic oscillator
- TRIX (Triple smoothed EMA)
- WMA (Weighted Moving Average)
STABLE - used in production
Search or submit any issues for this package
yarn add @thi.ng/transducers-stats
ES module import:
<script type="module" src="https://cdn.skypack.dev/@thi.ng/transducers-stats"></script>
For Node.js REPL:
# with flag only for < v16
node --experimental-repl-await
> const transducersStats = await import("@thi.ng/transducers-stats");
Package sizes (gzipped, pre-treeshake): ESM: 1.59 KB
Several demos in this repo's /examples directory are using this package.
A selection:
Screenshot | Description | Live demo | Source |
---|---|---|---|
Basic crypto-currency candle chart with multiple moving averages plots | Demo | Source | |
Fork-join worker-based raymarch renderer (JS/CPU only) | Demo | Source |
import * as tx from "@thi.ng/transducers";
import * as stats from "@thi.ng/transducers-stats";
// Simple moving average (SMA) (sliding window size 5)
// if an input is given (as is the case here), then returns
// a transforming iterator instead of transducer
[...stats.sma(5, [1,2,3,4,5,10,11,12,13,14,9,8,7,6,5])]
// [ 3, 4.8, 6.6, 8.4, 10.2, 12, 11.8, 11.2, 10.2, 8.8, 7 ]
// compute multiple stats at once
tx.transduce(
tx.comp(
tx.multiplexObj({
sma: stats.sma(5),
ema: stats.ema(5),
wma: stats.wma(5)
}),
// ignore first `period-1` values
// (because MAs require at least `period` inputs to warm up)
tx.drop(4)
),
tx.push(),
[1,2,3,4,5,10,11,12,13,14,9,8,7,6,5]
);
// [ { wma: 3.6666666666666665, ema: 3, sma: 3 },
// { wma: 6, ema: 5.333333333333333, sma: 4.8 },
// { wma: 8.066666666666666, ema: 7.222222222222221, sma: 6.6 },
// { wma: 9.866666666666667, ema: 8.814814814814815, sma: 8.4 },
// { wma: 11.4, ema: 10.209876543209877, sma: 10.2 },
// { wma: 12.666666666666666, ema: 11.473251028806585, sma: 12 },
// { wma: 11.666666666666666, ema: 10.64883401920439, sma: 11.8 },
// { wma: 10.4, ema: 9.76588934613626, sma: 11.2 },
// { wma: 9, ema: 8.843926230757507, sma: 10.2 },
// { wma: 7.6, ema: 7.895950820505004, sma: 8.8 },
// { wma: 6.333333333333333, ema: 6.93063388033667, sma: 7 } ]
Karsten Schmidt
If this project contributes to an academic publication, please cite it as:
@misc{thing-transducers-stats,
title = "@thi.ng/transducers-stats",
author = "Karsten Schmidt",
note = "https://thi.ng/transducers-stats",
year = 2017
}
© 2017 - 2021 Karsten Schmidt // Apache Software License 2.0