trading-signals 5.0.4 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +74 -76
  2. package/dist/index.cjs +1803 -0
  3. package/dist/index.d.cts +622 -0
  4. package/dist/index.d.ts +621 -30
  5. package/dist/index.js +1700 -32
  6. package/package.json +22 -10
  7. package/dist/ABANDS/AccelerationBands.d.ts +0 -26
  8. package/dist/ABANDS/AccelerationBands.js +0 -72
  9. package/dist/ABANDS/AccelerationBands.js.map +0 -1
  10. package/dist/AC/AC.d.ts +0 -26
  11. package/dist/AC/AC.js +0 -61
  12. package/dist/AC/AC.js.map +0 -1
  13. package/dist/ADX/ADX.d.ts +0 -22
  14. package/dist/ADX/ADX.js +0 -56
  15. package/dist/ADX/ADX.js.map +0 -1
  16. package/dist/AO/AO.d.ts +0 -21
  17. package/dist/AO/AO.js +0 -47
  18. package/dist/AO/AO.js.map +0 -1
  19. package/dist/ATR/ATR.d.ts +0 -18
  20. package/dist/ATR/ATR.js +0 -40
  21. package/dist/ATR/ATR.js.map +0 -1
  22. package/dist/BBANDS/BollingerBands.d.ts +0 -23
  23. package/dist/BBANDS/BollingerBands.js +0 -69
  24. package/dist/BBANDS/BollingerBands.js.map +0 -1
  25. package/dist/BBW/BollingerBandsWidth.d.ts +0 -13
  26. package/dist/BBW/BollingerBandsWidth.js +0 -28
  27. package/dist/BBW/BollingerBandsWidth.js.map +0 -1
  28. package/dist/CCI/CCI.d.ts +0 -21
  29. package/dist/CCI/CCI.js +0 -65
  30. package/dist/CCI/CCI.js.map +0 -1
  31. package/dist/CG/CG.d.ts +0 -21
  32. package/dist/CG/CG.js +0 -80
  33. package/dist/CG/CG.js.map +0 -1
  34. package/dist/DEMA/DEMA.d.ts +0 -18
  35. package/dist/DEMA/DEMA.js +0 -41
  36. package/dist/DEMA/DEMA.js.map +0 -1
  37. package/dist/DMA/DMA.d.ts +0 -28
  38. package/dist/DMA/DMA.js +0 -44
  39. package/dist/DMA/DMA.js.map +0 -1
  40. package/dist/DX/DX.d.ts +0 -28
  41. package/dist/DX/DX.js +0 -107
  42. package/dist/DX/DX.js.map +0 -1
  43. package/dist/EMA/EMA.d.ts +0 -20
  44. package/dist/EMA/EMA.js +0 -79
  45. package/dist/EMA/EMA.js.map +0 -1
  46. package/dist/Indicator.d.ts +0 -36
  47. package/dist/Indicator.js +0 -100
  48. package/dist/Indicator.js.map +0 -1
  49. package/dist/MA/MovingAverage.d.ts +0 -16
  50. package/dist/MA/MovingAverage.js +0 -30
  51. package/dist/MA/MovingAverage.js.map +0 -1
  52. package/dist/MA/MovingAverageTypes.d.ts +0 -5
  53. package/dist/MA/MovingAverageTypes.js +0 -2
  54. package/dist/MA/MovingAverageTypes.js.map +0 -1
  55. package/dist/MACD/MACD.d.ts +0 -41
  56. package/dist/MACD/MACD.js +0 -89
  57. package/dist/MACD/MACD.js.map +0 -1
  58. package/dist/MAD/MAD.d.ts +0 -16
  59. package/dist/MAD/MAD.js +0 -72
  60. package/dist/MAD/MAD.js.map +0 -1
  61. package/dist/MOM/MOM.d.ts +0 -16
  62. package/dist/MOM/MOM.js +0 -48
  63. package/dist/MOM/MOM.js.map +0 -1
  64. package/dist/OBV/OBV.d.ts +0 -11
  65. package/dist/OBV/OBV.js +0 -33
  66. package/dist/OBV/OBV.js.map +0 -1
  67. package/dist/ROC/ROC.d.ts +0 -14
  68. package/dist/ROC/ROC.js +0 -33
  69. package/dist/ROC/ROC.js.map +0 -1
  70. package/dist/RSI/RSI.d.ts +0 -21
  71. package/dist/RSI/RSI.js +0 -88
  72. package/dist/RSI/RSI.js.map +0 -1
  73. package/dist/SMA/SMA.d.ts +0 -11
  74. package/dist/SMA/SMA.js +0 -42
  75. package/dist/SMA/SMA.js.map +0 -1
  76. package/dist/STOCH/StochasticOscillator.d.ts +0 -37
  77. package/dist/STOCH/StochasticOscillator.js +0 -98
  78. package/dist/STOCH/StochasticOscillator.js.map +0 -1
  79. package/dist/STOCH/StochasticRSI.d.ts +0 -17
  80. package/dist/STOCH/StochasticRSI.js +0 -60
  81. package/dist/STOCH/StochasticRSI.js.map +0 -1
  82. package/dist/TR/TR.d.ts +0 -13
  83. package/dist/TR/TR.js +0 -46
  84. package/dist/TR/TR.js.map +0 -1
  85. package/dist/WMA/WMA.d.ts +0 -14
  86. package/dist/WMA/WMA.js +0 -59
  87. package/dist/WMA/WMA.js.map +0 -1
  88. package/dist/WSMA/WSMA.d.ts +0 -19
  89. package/dist/WSMA/WSMA.js +0 -63
  90. package/dist/WSMA/WSMA.js.map +0 -1
  91. package/dist/error/NotEnoughDataError.d.ts +0 -3
  92. package/dist/error/NotEnoughDataError.js +0 -8
  93. package/dist/error/NotEnoughDataError.js.map +0 -1
  94. package/dist/error/index.d.ts +0 -1
  95. package/dist/error/index.js +0 -2
  96. package/dist/error/index.js.map +0 -1
  97. package/dist/index.js.map +0 -1
  98. package/dist/util/BandsResult.d.ts +0 -11
  99. package/dist/util/BandsResult.js +0 -2
  100. package/dist/util/BandsResult.js.map +0 -1
  101. package/dist/util/HighLowClose.d.ts +0 -27
  102. package/dist/util/HighLowClose.js +0 -2
  103. package/dist/util/HighLowClose.js.map +0 -1
  104. package/dist/util/Period.d.ts +0 -30
  105. package/dist/util/Period.js +0 -59
  106. package/dist/util/Period.js.map +0 -1
  107. package/dist/util/getAverage.d.ts +0 -3
  108. package/dist/util/getAverage.js +0 -11
  109. package/dist/util/getAverage.js.map +0 -1
  110. package/dist/util/getFixedArray.d.ts +0 -1
  111. package/dist/util/getFixedArray.js +0 -14
  112. package/dist/util/getFixedArray.js.map +0 -1
  113. package/dist/util/getMaximum.d.ts +0 -2
  114. package/dist/util/getMaximum.js +0 -11
  115. package/dist/util/getMaximum.js.map +0 -1
  116. package/dist/util/getMinimum.d.ts +0 -2
  117. package/dist/util/getMinimum.js +0 -11
  118. package/dist/util/getMinimum.js.map +0 -1
  119. package/dist/util/getStandardDeviation.d.ts +0 -3
  120. package/dist/util/getStandardDeviation.js +0 -14
  121. package/dist/util/getStandardDeviation.js.map +0 -1
  122. package/dist/util/index.d.ts +0 -8
  123. package/dist/util/index.js +0 -9
  124. package/dist/util/index.js.map +0 -1
package/README.md CHANGED
@@ -12,62 +12,6 @@ The main focus of this library is on the accuracy of calculations, but using the
12
12
 
13
13
  All indicators can be updated over time by streaming data (prices or candles) to the `update` method. Some indicators also provide `static` batch methods for further performance improvements when providing data up-front during a backtest or historical data import.
14
14
 
15
- ## Benefits & Features
16
-
17
- - **Accurate.** Indicators with intervals will return a result only when the period is reached.
18
- - **Convenient.** Indicators with intervals will save their all-time highs and lows.
19
- - **Fast.** If you need high throughput, you can use the included [faster implementations][2].
20
- - **Flexible.** All advanced indicators support different smoothing overlays (WSMA, etc.).
21
- - **Live.** It allows for the replacement of values, enabling live charting.
22
- - **Modern.** Uses ECMAScript Modules (ESM) syntax.
23
- - **Precise.** Better accuracy than calculating with primitive numbers thanks to [big.js][1].
24
- - **Robust.** Checked against common division by zero mistakes.
25
- - **Tested.** Code coverage is 100%. No surprises when using it.
26
- - **Typed.** Source code is 100% TypeScript. No need to install external typings.
27
- - **Verified.** All results are verified with [other libraries](#alternatives) to guarantee correctness.
28
- - **Versatile.** Indicators can be updated up-front or by streaming prices.
29
-
30
- ## Technical Indicator Types
31
-
32
- - Trend indicators: Measure the direction of a trend (uptrend, downtrend or sideways trend)
33
- - Volume indicators: Measure the strength of a trend (based on volume)
34
- - Volatility indicators: Measure how much disagreement there is in the market based on price (statistical measure of its dispersion)
35
- - Momentum indicators: Measure the strength of a trend (based on price / speed of price movement)
36
-
37
- ## Supported Technical Indicators
38
-
39
- 1. Acceleration Bands (ABANDS)
40
- 1. Accelerator Oscillator (AC)
41
- 1. Average Directional Index (ADX)
42
- 1. Average True Range (ATR)
43
- 1. Awesome Oscillator (AO)
44
- 1. Bollinger Bands (BBANDS)
45
- 1. Bollinger Bands Width (BBW)
46
- 1. Center of Gravity (CG)
47
- 1. Commodity Channel Index (CCI)
48
- 1. Directional Movement Index (DMI / DX)
49
- 1. Double Exponential Moving Average (DEMA)
50
- 1. Dual Moving Average (DMA)
51
- 1. Exponential Moving Average (EMA)
52
- 1. Mean Absolute Deviation (MAD)
53
- 1. Momentum (MOM / MTM)
54
- 1. Moving Average Convergence Divergence (MACD)
55
- 1. On-Balance Volume (OBV)
56
- 1. Rate-of-Change (ROC)
57
- 1. Relative Strength Index (RSI)
58
- 1. Simple Moving Average (SMA)
59
- 1. Stochastic Oscillator (STOCH)
60
- 1. Stochastic RSI (STOCHRSI)
61
- 1. True Range (TR)
62
- 1. Weighted Moving Average (WMA)
63
- 1. Wilder's Smoothed Moving Average (WSMA / WWS / SMMA / MEMA)
64
-
65
- Utility Methods:
66
-
67
- 1. Average / Mean
68
- 1. Standard Deviation
69
- 1. Rolling Standard Deviation
70
-
71
15
  ## Usage
72
16
 
73
17
  ```typescript
@@ -75,35 +19,48 @@ import {Big, SMA} from 'trading-signals';
75
19
 
76
20
  const sma = new SMA(3);
77
21
 
78
- // You can add numbers individually:
79
- sma.update(40);
80
- sma.update(30);
81
- sma.update(20);
22
+ // You can add values individually:
23
+ sma.add(40);
24
+ sma.add(30);
25
+ sma.add(20);
82
26
 
83
- // You can add multiple numbers at once:
27
+ // You can add multiple values at once:
84
28
  sma.updates([20, 40, 80]);
85
29
 
86
- // You can add strings:
87
- sma.update('10');
30
+ // You can add stringified values:
31
+ sma.add('10');
88
32
 
89
- // You can replace a previous value (useful for live charts):
33
+ // You can replace a previous value (useful for live charting):
90
34
  sma.replace('40');
91
35
 
92
36
  // You can add arbitrary-precision decimals:
93
- sma.update(new Big(30));
37
+ sma.add(new Big(30.0009));
38
+
39
+ // You can check if an indicator is stable:
40
+ console.log(sma.isStable); // true
94
41
 
95
- // You can get the result in various formats:
96
- console.log(sma.getResult().toFixed(2)); // "40.00"
97
- console.log(sma.getResult().toFixed(4)); // "40.0000"
42
+ // If an indicator is stable, you can get its result:
43
+ console.log(sma.getResult()?.toFixed()); // "50.0003"
44
+
45
+ // You can also get the result without optional chaining:
46
+ console.log(sma.getResultOrThrow().toFixed()); // "50.0003"
47
+
48
+ // Various precisions are available too:
49
+ console.log(sma.getResultOrThrow().toFixed(2)); // "50.00"
50
+ console.log(sma.getResultOrThrow().toFixed(4)); // "50.0003"
51
+
52
+ // Each indicator also includes convenient features such as "lowest" and "highest" lifetime values:
53
+ console.log(sma.lowest?.toFixed(2)); // "23.33"
54
+ console.log(sma.highest?.toFixed(2)); // "53.33"
98
55
  ```
99
56
 
100
- ### When to use `update(...)`?
57
+ ### When to use `add(...)`?
101
58
 
102
- You have to call an indicator's `update` method to enter input data. The update method may or may not return a result from the indicator depending on whether the minimum amount of input data has been reached.
59
+ To input data, you need to call the indicator's `add` method. Depending on whether the minimum required input data for the interval has been reached, the `add` method may or may not return a result from the indicator.
103
60
 
104
- ### When to use `getResult()`?
61
+ ### When to use `getResultOrThrow()`?
105
62
 
106
- You can call `getResult()` at any point in time, but it throws errors unless an indicator has received the minimum amount of data. If you call `getResult()`, before an indicator has received the required amount of input values, a `NotEnoughDataError` will be thrown.
63
+ You can call `getResultOrThrow()` at any point in time, but it throws errors unless an indicator has received the minimum amount of data. If you call `getResultOrThrow()`, before an indicator has received the required amount of input values, a `NotEnoughDataError` will be thrown.
107
64
 
108
65
  **Example:**
109
66
 
@@ -119,7 +76,7 @@ sma.update(40);
119
76
 
120
77
  try {
121
78
  // We will get an error, because the minimum amount of inputs is 3
122
- sma.getResult();
79
+ sma.getResultOrThrow();
123
80
  } catch (error) {
124
81
  console.log(error.constructor.name); // "NotEnoughDataError"
125
82
  }
@@ -128,11 +85,52 @@ try {
128
85
  sma.update(70);
129
86
 
130
87
  // Now, we will receive a proper result
131
- console.log(sma.getResult().valueOf()); // "40"
88
+ console.log(sma.getResultOrThrow().valueOf()); // "40"
132
89
  ```
133
90
 
134
91
  Most of the time, the minimum amount of data depends on the interval / time period used.
135
92
 
93
+ ## Technical Indicator Types
94
+
95
+ - Trend indicators: Measure the direction of a trend (uptrend, downtrend or sideways trend)
96
+ - Volume indicators: Measure the strength of a trend (based on volume)
97
+ - Volatility indicators: Measure how much disagreement there is in the market based on price (statistical measure of its dispersion)
98
+ - Momentum indicators: Measure the strength of a trend (based on price / speed of price movement)
99
+
100
+ ## Supported Technical Indicators
101
+
102
+ 1. Acceleration Bands (ABANDS)
103
+ 1. Accelerator Oscillator (AC)
104
+ 1. Average Directional Index (ADX)
105
+ 1. Average True Range (ATR)
106
+ 1. Awesome Oscillator (AO)
107
+ 1. Bollinger Bands (BBANDS)
108
+ 1. Bollinger Bands Width (BBW)
109
+ 1. Center of Gravity (CG)
110
+ 1. Commodity Channel Index (CCI)
111
+ 1. Directional Movement Index (DMI / DX)
112
+ 1. Double Exponential Moving Average (DEMA)
113
+ 1. Dual Moving Average (DMA)
114
+ 1. Exponential Moving Average (EMA)
115
+ 1. Mean Absolute Deviation (MAD)
116
+ 1. Momentum (MOM / MTM)
117
+ 1. Moving Average Convergence Divergence (MACD)
118
+ 1. On-Balance Volume (OBV)
119
+ 1. Rate-of-Change (ROC)
120
+ 1. Relative Strength Index (RSI)
121
+ 1. Simple Moving Average (SMA)
122
+ 1. Stochastic Oscillator (STOCH)
123
+ 1. Stochastic RSI (STOCHRSI)
124
+ 1. True Range (TR)
125
+ 1. Weighted Moving Average (WMA)
126
+ 1. Wilder's Smoothed Moving Average (WSMA / WWS / SMMA / MEMA)
127
+
128
+ Utility Methods:
129
+
130
+ 1. Average / Mean
131
+ 1. Standard Deviation
132
+ 1. Rolling Standard Deviation
133
+
136
134
  ## Performance
137
135
 
138
136
  ### Arbitrary-precision decimal arithmetic
@@ -165,12 +163,12 @@ fasterStochRSI.update(4);
165
163
  fasterStochRSI.update(5);
166
164
  fasterStochRSI.update(6);
167
165
 
168
- console.log(fasterStochRSI.getResult());
166
+ console.log(fasterStochRSI.getResultOrThrow());
169
167
  ```
170
168
 
171
169
  ### Benchmarks
172
170
 
173
- You can run `yarn start:benchmark` to see the runtime performance of each technical indicator on your machine. This will give you an understanding of which indicators can be calculated faster than others.
171
+ You can run `npm run start:benchmark` to see the runtime performance of each technical indicator on your machine. This will give you an understanding of which indicators can be calculated faster than others.
174
172
 
175
173
  ## Disclaimer
176
174