From c2be21929a7e48d591f85ae2cf67ff0ae3c28828 Mon Sep 17 00:00:00 2001 From: Benny Neugebauer Date: Mon, 3 Jan 2022 21:48:12 +0100 Subject: [PATCH] refactor: Sort supported technical indicators --- README.md | 2 +- src/start/startBenchmark.ts | 52 ++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 431b3cc4b..0ba708cea 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,13 @@ All indicators can be updated over time by streaming data (prices or candles) to 1. Mean Absolute Deviation (MAD) 1. Momentum (MOM / MTM) 1. Moving Average Convergence Divergence (MACD) +1. On-Balance Volume (OBV) 1. Rate-of-Change (ROC) 1. Relative Strength Index (RSI) 1. Simple Moving Average (SMA) 1. Stochastic Oscillator (STOCH) 1. Stochastic RSI (STOCHRSI) 1. True Range (TR) -1. On-Balance Volume (OBV) 1. Wilder's Smoothed Moving Average (WSMA / WMA / WWS / SMMA / MEMA) Utility Methods: diff --git a/src/start/startBenchmark.ts b/src/start/startBenchmark.ts index 11c64ef65..650980fe4 100644 --- a/src/start/startBenchmark.ts +++ b/src/start/startBenchmark.ts @@ -61,73 +61,73 @@ import { const shortInterval = 10; const interval = 20; const longInterval = 40; -const prices: number[] = candles.map(candle => parseInt(candle.close, 10)); -const openHighLowCloseVolumes: OpenHighLowCloseVolumeNumber[] = candles.map(candle => ({ - close: parseInt(candle.close, 10), - high: parseInt(candle.high, 10), - low: parseInt(candle.low, 10), - open: parseInt(candle.open, 10), - volume: parseInt(candle.volume, 10), +const prices: number[] = candles.map(candle => parseFloat(candle.close)); +const floatCandles: OpenHighLowCloseVolumeNumber[] = candles.map(candle => ({ + close: parseFloat(candle.close), + high: parseFloat(candle.high), + low: parseFloat(candle.low), + open: parseFloat(candle.open), + volume: parseFloat(candle.volume), })); new Benchmark.Suite('Technical Indicators') .add('AccelerationBands', () => { const accBands = new AccelerationBands(interval, 4); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { accBands.update(candle); } }) .add('FasterAccelerationBands', () => { const fasterAccBands = new FasterAccelerationBands(interval, 4); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterAccBands.update(candle); } }) .add('AC', () => { const ac = new AC(shortInterval, longInterval, interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { ac.update(candle); } }) .add('FasterAC', () => { const fasterAC = new FasterAC(shortInterval, longInterval, interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterAC.update(candle); } }) .add('ADX', () => { const adx = new ADX(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { adx.update(candle); } }) .add('FasterADX', () => { const fasterADX = new FasterADX(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterADX.update(candle); } }) .add('AO', () => { const ao = new AO(shortInterval, interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { ao.update(candle); } }) .add('FasterAO', () => { const fasterAO = new FasterAO(shortInterval, interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterAO.update(candle); } }) .add('ATR', () => { const atr = new ATR(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { atr.update(candle); } }) .add('FasterATR', () => { const fasterATR = new FasterATR(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterATR.update(candle); } }) @@ -157,13 +157,13 @@ new Benchmark.Suite('Technical Indicators') }) .add('CCI', () => { const cci = new CCI(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { cci.update(candle); } }) .add('FasterCCI', () => { const fasterCCI = new FasterCCI(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterCCI.update(candle); } }) @@ -205,13 +205,13 @@ new Benchmark.Suite('Technical Indicators') }) .add('DX', () => { const dx = new DX(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { dx.update(candle); } }) .add('FasterDX', () => { const fasterDX = new FasterDX(interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterDX.update(candle); } }) @@ -270,13 +270,13 @@ new Benchmark.Suite('Technical Indicators') }) .add('OBV', () => { const obv = new OBV(); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { obv.update(candle); } }) .add('FasterOBV', () => { const fasterOBV = new FasterOBV(); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterOBV.update(candle); } }) @@ -336,7 +336,7 @@ new Benchmark.Suite('Technical Indicators') }) .add('FasterStochasticOscillator', () => { const fasterStoch = new FasterStochasticOscillator(shortInterval, interval, interval); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterStoch.update(candle); } }) @@ -354,13 +354,13 @@ new Benchmark.Suite('Technical Indicators') }) .add('TR', () => { const tr = new TR(); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { tr.update(candle); } }) .add('FasterTR', () => { const fasterTR = new FasterTR(); - for (const candle of openHighLowCloseVolumes) { + for (const candle of floatCandles) { fasterTR.update(candle); } })