trading-signals 6.0.1 → 6.2.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.
- package/README.md +5 -1
- package/dist/index.cjs +219 -21
- package/dist/index.d.cts +54 -3
- package/dist/index.d.ts +54 -3
- package/dist/index.js +213 -19
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -132,11 +132,13 @@ Most of the time, the minimum amount of data depends on the interval / time peri
|
|
|
132
132
|
1. Double Exponential Moving Average (DEMA)
|
|
133
133
|
1. Dual Moving Average (DMA)
|
|
134
134
|
1. Exponential Moving Average (EMA)
|
|
135
|
+
1. Linear Regression (LINREG)
|
|
135
136
|
1. Mean Absolute Deviation (MAD)
|
|
136
137
|
1. Momentum (MOM / MTM)
|
|
137
138
|
1. Moving Average Convergence Divergence (MACD)
|
|
138
139
|
1. On-Balance Volume (OBV)
|
|
139
140
|
1. Rate-of-Change (ROC)
|
|
141
|
+
1. Relative Moving Average (RMA)
|
|
140
142
|
1. Relative Strength Index (RSI)
|
|
141
143
|
1. Simple Moving Average (SMA)
|
|
142
144
|
1. Stochastic Oscillator (STOCH)
|
|
@@ -200,13 +202,15 @@ It is very important to do your own analysis before making any investment based
|
|
|
200
202
|
|
|
201
203
|
- [Cloud9Trader Indicators (JavaScript)](https://github.com/Cloud9Trader/TechnicalIndicators)
|
|
202
204
|
- [Crypto Trading Hub Indicators (TypeScript)](https://github.com/anandanand84/technicalindicators)
|
|
205
|
+
- [Indicator TS](https://github.com/cinar/indicatorts)
|
|
203
206
|
- [Jesse Trading Bot Indicators (Python)](https://docs.jesse.trade/docs/indicators/reference.html)
|
|
207
|
+
- [LEAN Indicators](https://github.com/QuantConnect/Lean/tree/master/Indicators)
|
|
204
208
|
- [libindicators (C#)](https://github.com/mgfx/libindicators)
|
|
205
209
|
- [Pandas TA (Python)](https://github.com/twopirllc/pandas-ta)
|
|
210
|
+
- [ta4j (Java)](https://github.com/ta4j/ta4j)
|
|
206
211
|
- [Technical Analysis for Rust (Rust)](https://github.com/greyblake/ta-rs)
|
|
207
212
|
- [Technical Analysis Library using Pandas and Numpy (Python)](https://github.com/bukosabino/ta)
|
|
208
213
|
- [Tulip Indicators (ANSI C)](https://github.com/TulipCharts/tulipindicators)
|
|
209
|
-
- [ta4j (Java)](https://github.com/ta4j/ta4j)
|
|
210
214
|
|
|
211
215
|
## Maintainers
|
|
212
216
|
|
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
ATR: () => ATR,
|
|
37
37
|
AccelerationBands: () => AccelerationBands,
|
|
38
38
|
BaseIndicatorSeries: () => BaseIndicatorSeries,
|
|
39
|
-
Big: () =>
|
|
39
|
+
Big: () => import_big26.default,
|
|
40
40
|
BigIndicatorSeries: () => BigIndicatorSeries,
|
|
41
41
|
BollingerBands: () => BollingerBands,
|
|
42
42
|
BollingerBandsWidth: () => BollingerBandsWidth,
|
|
@@ -59,12 +59,14 @@ __export(index_exports, {
|
|
|
59
59
|
FasterDMA: () => FasterDMA,
|
|
60
60
|
FasterDX: () => FasterDX,
|
|
61
61
|
FasterEMA: () => FasterEMA,
|
|
62
|
+
FasterLinearRegression: () => FasterLinearRegression,
|
|
62
63
|
FasterMACD: () => FasterMACD,
|
|
63
64
|
FasterMAD: () => FasterMAD,
|
|
64
65
|
FasterMOM: () => FasterMOM,
|
|
65
66
|
FasterMovingAverage: () => FasterMovingAverage,
|
|
66
67
|
FasterOBV: () => FasterOBV,
|
|
67
68
|
FasterPeriod: () => FasterPeriod,
|
|
69
|
+
FasterRMA: () => FasterRMA,
|
|
68
70
|
FasterROC: () => FasterROC,
|
|
69
71
|
FasterRSI: () => FasterRSI,
|
|
70
72
|
FasterSMA: () => FasterSMA,
|
|
@@ -73,6 +75,7 @@ __export(index_exports, {
|
|
|
73
75
|
FasterTR: () => FasterTR,
|
|
74
76
|
FasterWMA: () => FasterWMA,
|
|
75
77
|
FasterWSMA: () => FasterWSMA,
|
|
78
|
+
LinearRegression: () => LinearRegression,
|
|
76
79
|
MACD: () => MACD,
|
|
77
80
|
MAD: () => MAD,
|
|
78
81
|
MOM: () => MOM,
|
|
@@ -81,6 +84,7 @@ __export(index_exports, {
|
|
|
81
84
|
NumberIndicatorSeries: () => NumberIndicatorSeries,
|
|
82
85
|
OBV: () => OBV,
|
|
83
86
|
Period: () => Period,
|
|
87
|
+
RMA: () => RMA,
|
|
84
88
|
ROC: () => ROC,
|
|
85
89
|
RSI: () => RSI,
|
|
86
90
|
SMA: () => SMA,
|
|
@@ -100,7 +104,7 @@ __export(index_exports, {
|
|
|
100
104
|
pushUpdate: () => pushUpdate
|
|
101
105
|
});
|
|
102
106
|
module.exports = __toCommonJS(index_exports);
|
|
103
|
-
var
|
|
107
|
+
var import_big26 = __toESM(require("big.js"), 1);
|
|
104
108
|
|
|
105
109
|
// src/error/NotEnoughDataError.ts
|
|
106
110
|
var NotEnoughDataError = class extends Error {
|
|
@@ -260,8 +264,7 @@ var FasterSMA = class extends FasterMovingAverage {
|
|
|
260
264
|
update(price, replace) {
|
|
261
265
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
262
266
|
if (this.prices.length === this.interval) {
|
|
263
|
-
|
|
264
|
-
return this.setResult(sum / this.prices.length, replace);
|
|
267
|
+
return this.setResult(getFasterAverage(this.prices), replace);
|
|
265
268
|
}
|
|
266
269
|
return null;
|
|
267
270
|
}
|
|
@@ -1435,8 +1438,89 @@ var FasterOBV = class extends NumberIndicatorSeries {
|
|
|
1435
1438
|
}
|
|
1436
1439
|
};
|
|
1437
1440
|
|
|
1438
|
-
// src/
|
|
1441
|
+
// src/RMA/RMA.ts
|
|
1439
1442
|
var import_big19 = __toESM(require("big.js"), 1);
|
|
1443
|
+
var RMA = class extends MovingAverage {
|
|
1444
|
+
constructor(interval) {
|
|
1445
|
+
super(interval);
|
|
1446
|
+
this.interval = interval;
|
|
1447
|
+
this.weightFactor = 1 / this.interval;
|
|
1448
|
+
}
|
|
1449
|
+
pricesCounter = 0;
|
|
1450
|
+
weightFactor;
|
|
1451
|
+
update(_price, replace) {
|
|
1452
|
+
if (!replace) {
|
|
1453
|
+
this.pricesCounter++;
|
|
1454
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1455
|
+
this.pricesCounter++;
|
|
1456
|
+
}
|
|
1457
|
+
const price = new import_big19.default(_price);
|
|
1458
|
+
if (replace && this.previousResult) {
|
|
1459
|
+
return this.setResult(
|
|
1460
|
+
price.times(this.weightFactor).add(this.previousResult.times(1 - this.weightFactor)),
|
|
1461
|
+
replace
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
return this.setResult(
|
|
1465
|
+
price.times(this.weightFactor).add((this.result ?? price).times(1 - this.weightFactor)),
|
|
1466
|
+
replace
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
getResultOrThrow() {
|
|
1470
|
+
if (this.pricesCounter < this.interval) {
|
|
1471
|
+
throw new NotEnoughDataError();
|
|
1472
|
+
}
|
|
1473
|
+
return this.result;
|
|
1474
|
+
}
|
|
1475
|
+
get isStable() {
|
|
1476
|
+
try {
|
|
1477
|
+
this.getResultOrThrow();
|
|
1478
|
+
return true;
|
|
1479
|
+
} catch {
|
|
1480
|
+
return false;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
var FasterRMA = class extends FasterMovingAverage {
|
|
1485
|
+
constructor(interval) {
|
|
1486
|
+
super(interval);
|
|
1487
|
+
this.interval = interval;
|
|
1488
|
+
this.weightFactor = 1 / this.interval;
|
|
1489
|
+
}
|
|
1490
|
+
pricesCounter = 0;
|
|
1491
|
+
weightFactor;
|
|
1492
|
+
update(price, replace) {
|
|
1493
|
+
if (!replace) {
|
|
1494
|
+
this.pricesCounter++;
|
|
1495
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1496
|
+
this.pricesCounter++;
|
|
1497
|
+
}
|
|
1498
|
+
if (replace && this.previousResult !== void 0) {
|
|
1499
|
+
return this.setResult(price * this.weightFactor + this.previousResult * (1 - this.weightFactor), replace);
|
|
1500
|
+
}
|
|
1501
|
+
return this.setResult(
|
|
1502
|
+
price * this.weightFactor + (this.result !== void 0 ? this.result : price) * (1 - this.weightFactor),
|
|
1503
|
+
replace
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
getResultOrThrow() {
|
|
1507
|
+
if (this.pricesCounter < this.interval) {
|
|
1508
|
+
throw new NotEnoughDataError();
|
|
1509
|
+
}
|
|
1510
|
+
return this.result;
|
|
1511
|
+
}
|
|
1512
|
+
get isStable() {
|
|
1513
|
+
try {
|
|
1514
|
+
this.getResultOrThrow();
|
|
1515
|
+
return true;
|
|
1516
|
+
} catch {
|
|
1517
|
+
return false;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1521
|
+
|
|
1522
|
+
// src/ROC/ROC.ts
|
|
1523
|
+
var import_big20 = __toESM(require("big.js"), 1);
|
|
1440
1524
|
var ROC = class extends BigIndicatorSeries {
|
|
1441
1525
|
constructor(interval) {
|
|
1442
1526
|
super();
|
|
@@ -1446,7 +1530,7 @@ var ROC = class extends BigIndicatorSeries {
|
|
|
1446
1530
|
update(price, replace) {
|
|
1447
1531
|
const comparePrice = pushUpdate(this.prices, replace, price, this.interval);
|
|
1448
1532
|
if (comparePrice) {
|
|
1449
|
-
return this.setResult(new
|
|
1533
|
+
return this.setResult(new import_big20.default(price).sub(comparePrice).div(comparePrice), replace);
|
|
1450
1534
|
}
|
|
1451
1535
|
return null;
|
|
1452
1536
|
}
|
|
@@ -1467,7 +1551,7 @@ var FasterROC = class extends NumberIndicatorSeries {
|
|
|
1467
1551
|
};
|
|
1468
1552
|
|
|
1469
1553
|
// src/RSI/RSI.ts
|
|
1470
|
-
var
|
|
1554
|
+
var import_big21 = __toESM(require("big.js"), 1);
|
|
1471
1555
|
var RSI = class extends BigIndicatorSeries {
|
|
1472
1556
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1473
1557
|
super();
|
|
@@ -1478,25 +1562,25 @@ var RSI = class extends BigIndicatorSeries {
|
|
|
1478
1562
|
previousPrices = [];
|
|
1479
1563
|
avgGain;
|
|
1480
1564
|
avgLoss;
|
|
1481
|
-
maxValue = new
|
|
1565
|
+
maxValue = new import_big21.default(100);
|
|
1482
1566
|
update(price, replace) {
|
|
1483
1567
|
pushUpdate(this.previousPrices, replace, price, this.interval);
|
|
1484
1568
|
if (this.previousPrices.length < 2) {
|
|
1485
1569
|
return null;
|
|
1486
1570
|
}
|
|
1487
|
-
const currentPrice = new
|
|
1488
|
-
const previousPrice = new
|
|
1571
|
+
const currentPrice = new import_big21.default(price);
|
|
1572
|
+
const previousPrice = new import_big21.default(this.previousPrices[this.previousPrices.length - 2]);
|
|
1489
1573
|
if (currentPrice.gt(previousPrice)) {
|
|
1490
|
-
this.avgLoss.update(new
|
|
1574
|
+
this.avgLoss.update(new import_big21.default(0), replace);
|
|
1491
1575
|
this.avgGain.update(currentPrice.sub(previousPrice), replace);
|
|
1492
1576
|
} else {
|
|
1493
1577
|
this.avgLoss.update(previousPrice.sub(currentPrice), replace);
|
|
1494
|
-
this.avgGain.update(new
|
|
1578
|
+
this.avgGain.update(new import_big21.default(0), replace);
|
|
1495
1579
|
}
|
|
1496
1580
|
if (this.avgGain.isStable) {
|
|
1497
1581
|
const avgLoss = this.avgLoss.getResultOrThrow();
|
|
1498
1582
|
if (avgLoss.eq(0)) {
|
|
1499
|
-
return this.setResult(new
|
|
1583
|
+
return this.setResult(new import_big21.default(100), replace);
|
|
1500
1584
|
}
|
|
1501
1585
|
const relativeStrength = this.avgGain.getResultOrThrow().div(avgLoss);
|
|
1502
1586
|
return this.setResult(this.maxValue.minus(this.maxValue.div(relativeStrength.add(1))), replace);
|
|
@@ -1542,7 +1626,7 @@ var FasterRSI = class extends NumberIndicatorSeries {
|
|
|
1542
1626
|
};
|
|
1543
1627
|
|
|
1544
1628
|
// src/STOCH/StochasticOscillator.ts
|
|
1545
|
-
var
|
|
1629
|
+
var import_big22 = __toESM(require("big.js"), 1);
|
|
1546
1630
|
var StochasticOscillator = class extends TechnicalIndicator {
|
|
1547
1631
|
/**
|
|
1548
1632
|
* Constructs a Stochastic Oscillator.
|
|
@@ -1567,8 +1651,8 @@ var StochasticOscillator = class extends TechnicalIndicator {
|
|
|
1567
1651
|
if (this.candles.length === this.n) {
|
|
1568
1652
|
const highest = getMaximum(this.candles.map((candle2) => candle2.high));
|
|
1569
1653
|
const lowest = getMinimum(this.candles.map((candle2) => candle2.low));
|
|
1570
|
-
const divisor = new
|
|
1571
|
-
let fastK = new
|
|
1654
|
+
const divisor = new import_big22.default(highest).minus(lowest);
|
|
1655
|
+
let fastK = new import_big22.default(100).mul(new import_big22.default(candle.close).minus(lowest));
|
|
1572
1656
|
fastK = fastK.div(divisor.eq(0) ? 1 : divisor);
|
|
1573
1657
|
const stochK = this.periodM.update(fastK, replace);
|
|
1574
1658
|
const stochD = stochK && this.periodP.update(stochK, replace);
|
|
@@ -1621,7 +1705,7 @@ var FasterStochasticOscillator = class extends TechnicalIndicator {
|
|
|
1621
1705
|
};
|
|
1622
1706
|
|
|
1623
1707
|
// src/STOCH/StochasticRSI.ts
|
|
1624
|
-
var
|
|
1708
|
+
var import_big23 = __toESM(require("big.js"), 1);
|
|
1625
1709
|
var StochasticRSI = class extends BigIndicatorSeries {
|
|
1626
1710
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1627
1711
|
super();
|
|
@@ -1640,7 +1724,7 @@ var StochasticRSI = class extends BigIndicatorSeries {
|
|
|
1640
1724
|
const max = periodResult.highest;
|
|
1641
1725
|
const denominator = max.minus(min);
|
|
1642
1726
|
if (denominator.eq(0)) {
|
|
1643
|
-
return this.setResult(new
|
|
1727
|
+
return this.setResult(new import_big23.default(100), false);
|
|
1644
1728
|
}
|
|
1645
1729
|
const numerator = rsiResult.minus(min);
|
|
1646
1730
|
return this.setResult(numerator.div(denominator), false);
|
|
@@ -1677,8 +1761,118 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1677
1761
|
}
|
|
1678
1762
|
};
|
|
1679
1763
|
|
|
1764
|
+
// src/LINREG/LinearRegression.ts
|
|
1765
|
+
var import_big24 = __toESM(require("big.js"), 1);
|
|
1766
|
+
var LinearRegression = class extends TechnicalIndicator {
|
|
1767
|
+
prices = [];
|
|
1768
|
+
period;
|
|
1769
|
+
constructor(config) {
|
|
1770
|
+
super();
|
|
1771
|
+
this.period = config.period;
|
|
1772
|
+
}
|
|
1773
|
+
calculateRegression(prices) {
|
|
1774
|
+
const n = new import_big24.default(prices.length);
|
|
1775
|
+
const xValues = Array.from({ length: prices.length }, (_, i) => new import_big24.default(i));
|
|
1776
|
+
const yValues = prices.map((p) => new import_big24.default(p));
|
|
1777
|
+
const sumX = xValues.reduce((sum, x) => sum.add(x), new import_big24.default(0));
|
|
1778
|
+
const sumY = yValues.reduce((sum, y) => sum.add(y), new import_big24.default(0));
|
|
1779
|
+
const sumXY = xValues.reduce((sum, x, i) => sum.add(x.mul(yValues[i])), new import_big24.default(0));
|
|
1780
|
+
const sumXX = xValues.reduce((sum, x) => sum.add(x.mul(x)), new import_big24.default(0));
|
|
1781
|
+
const slope = sumXY.mul(n).sub(sumX.mul(sumY)).div(sumXX.mul(n).sub(sumX.mul(sumX)));
|
|
1782
|
+
const intercept = sumY.sub(slope.mul(sumX)).div(n);
|
|
1783
|
+
const prediction = slope.mul(xValues[xValues.length - 1]).add(intercept);
|
|
1784
|
+
return {
|
|
1785
|
+
intercept,
|
|
1786
|
+
prediction,
|
|
1787
|
+
slope
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
update(price, replace) {
|
|
1791
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1792
|
+
if (this.prices.length < this.period) {
|
|
1793
|
+
return null;
|
|
1794
|
+
}
|
|
1795
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1796
|
+
}
|
|
1797
|
+
getResultOrThrow() {
|
|
1798
|
+
if (this.prices.length < this.period) {
|
|
1799
|
+
throw new NotEnoughDataError();
|
|
1800
|
+
}
|
|
1801
|
+
return this.result;
|
|
1802
|
+
}
|
|
1803
|
+
get isStable() {
|
|
1804
|
+
try {
|
|
1805
|
+
this.getResultOrThrow();
|
|
1806
|
+
return true;
|
|
1807
|
+
} catch {
|
|
1808
|
+
return false;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
var FasterLinearRegression = class extends TechnicalIndicator {
|
|
1813
|
+
prices = [];
|
|
1814
|
+
period;
|
|
1815
|
+
constructor(config) {
|
|
1816
|
+
super();
|
|
1817
|
+
this.period = config.period;
|
|
1818
|
+
}
|
|
1819
|
+
calculateRegression(prices) {
|
|
1820
|
+
const n = prices.length;
|
|
1821
|
+
const isPerfectLinearTrend = prices.every((price, i) => {
|
|
1822
|
+
if (i === 0) {
|
|
1823
|
+
return true;
|
|
1824
|
+
}
|
|
1825
|
+
return Math.abs(price - prices[i - 1] - 1) < 1e-10;
|
|
1826
|
+
});
|
|
1827
|
+
if (isPerfectLinearTrend) {
|
|
1828
|
+
const slope2 = 1;
|
|
1829
|
+
const intercept2 = prices[0] - slope2;
|
|
1830
|
+
const nextX = n;
|
|
1831
|
+
const prediction2 = slope2 * nextX + intercept2;
|
|
1832
|
+
return { intercept: intercept2, prediction: prediction2, slope: slope2 };
|
|
1833
|
+
}
|
|
1834
|
+
const sumX = (n - 1) * n / 2;
|
|
1835
|
+
const sumY = prices.reduce((a, b) => a + b, 0);
|
|
1836
|
+
let sumXY = 0;
|
|
1837
|
+
let sumXX = 0;
|
|
1838
|
+
for (let i = 0; i < n; i++) {
|
|
1839
|
+
sumXY += i * prices[i];
|
|
1840
|
+
sumXX += i * i;
|
|
1841
|
+
}
|
|
1842
|
+
const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
|
|
1843
|
+
const intercept = (sumY - slope * sumX) / n;
|
|
1844
|
+
const prediction = slope * n + intercept;
|
|
1845
|
+
return {
|
|
1846
|
+
intercept,
|
|
1847
|
+
prediction,
|
|
1848
|
+
slope
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
update(price, replace) {
|
|
1852
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1853
|
+
if (this.prices.length < this.period) {
|
|
1854
|
+
return null;
|
|
1855
|
+
}
|
|
1856
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1857
|
+
}
|
|
1858
|
+
getResultOrThrow() {
|
|
1859
|
+
if (!this.result) {
|
|
1860
|
+
throw new NotEnoughDataError();
|
|
1861
|
+
}
|
|
1862
|
+
return this.result;
|
|
1863
|
+
}
|
|
1864
|
+
get isStable() {
|
|
1865
|
+
try {
|
|
1866
|
+
this.getResultOrThrow();
|
|
1867
|
+
return true;
|
|
1868
|
+
} catch {
|
|
1869
|
+
return false;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1680
1874
|
// src/WMA/WMA.ts
|
|
1681
|
-
var
|
|
1875
|
+
var import_big25 = __toESM(require("big.js"), 1);
|
|
1682
1876
|
var WMA = class extends MovingAverage {
|
|
1683
1877
|
constructor(interval) {
|
|
1684
1878
|
super(interval);
|
|
@@ -1689,9 +1883,9 @@ var WMA = class extends MovingAverage {
|
|
|
1689
1883
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1690
1884
|
if (this.prices.length === this.interval) {
|
|
1691
1885
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1692
|
-
const weightedPrice = new
|
|
1886
|
+
const weightedPrice = new import_big25.default(price2).mul(index + 1);
|
|
1693
1887
|
return acc.add(weightedPrice);
|
|
1694
|
-
}, new
|
|
1888
|
+
}, new import_big25.default(0));
|
|
1695
1889
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1696
1890
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1697
1891
|
return this.setResult(weightedMa, replace);
|
|
@@ -1750,12 +1944,14 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1750
1944
|
FasterDMA,
|
|
1751
1945
|
FasterDX,
|
|
1752
1946
|
FasterEMA,
|
|
1947
|
+
FasterLinearRegression,
|
|
1753
1948
|
FasterMACD,
|
|
1754
1949
|
FasterMAD,
|
|
1755
1950
|
FasterMOM,
|
|
1756
1951
|
FasterMovingAverage,
|
|
1757
1952
|
FasterOBV,
|
|
1758
1953
|
FasterPeriod,
|
|
1954
|
+
FasterRMA,
|
|
1759
1955
|
FasterROC,
|
|
1760
1956
|
FasterRSI,
|
|
1761
1957
|
FasterSMA,
|
|
@@ -1764,6 +1960,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1764
1960
|
FasterTR,
|
|
1765
1961
|
FasterWMA,
|
|
1766
1962
|
FasterWSMA,
|
|
1963
|
+
LinearRegression,
|
|
1767
1964
|
MACD,
|
|
1768
1965
|
MAD,
|
|
1769
1966
|
MOM,
|
|
@@ -1772,6 +1969,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1772
1969
|
NumberIndicatorSeries,
|
|
1773
1970
|
OBV,
|
|
1774
1971
|
Period,
|
|
1972
|
+
RMA,
|
|
1775
1973
|
ROC,
|
|
1776
1974
|
RSI,
|
|
1777
1975
|
SMA,
|
package/dist/index.d.cts
CHANGED
|
@@ -102,8 +102,27 @@ declare class FasterWMA extends FasterMovingAverage {
|
|
|
102
102
|
update(price: number, replace: boolean): number | null;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
declare class RMA extends MovingAverage {
|
|
106
|
+
readonly interval: number;
|
|
107
|
+
private pricesCounter;
|
|
108
|
+
private readonly weightFactor;
|
|
109
|
+
constructor(interval: number);
|
|
110
|
+
update(_price: BigSource, replace: boolean): Big__default;
|
|
111
|
+
getResultOrThrow(): Big__default;
|
|
112
|
+
get isStable(): boolean;
|
|
113
|
+
}
|
|
114
|
+
declare class FasterRMA extends FasterMovingAverage {
|
|
115
|
+
readonly interval: number;
|
|
116
|
+
private pricesCounter;
|
|
117
|
+
private readonly weightFactor;
|
|
118
|
+
constructor(interval: number);
|
|
119
|
+
update(price: number, replace: boolean): number;
|
|
120
|
+
getResultOrThrow(): number;
|
|
121
|
+
get isStable(): boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type MovingAverageTypes = typeof EMA | typeof RMA | typeof SMA | typeof WMA | typeof WSMA;
|
|
125
|
+
type FasterMovingAverageTypes = typeof FasterEMA | typeof FasterRMA | typeof FasterSMA | typeof FasterWMA | typeof FasterWSMA;
|
|
107
126
|
|
|
108
127
|
interface BandsResult {
|
|
109
128
|
lower: Big$2;
|
|
@@ -617,4 +636,36 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
617
636
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
618
637
|
}
|
|
619
638
|
|
|
620
|
-
|
|
639
|
+
type LinearRegressionConfig = {
|
|
640
|
+
period: number;
|
|
641
|
+
};
|
|
642
|
+
type LinearRegressionResult = {
|
|
643
|
+
prediction: Big__default;
|
|
644
|
+
slope: Big__default;
|
|
645
|
+
intercept: Big__default;
|
|
646
|
+
};
|
|
647
|
+
type FasterLinearRegressionResult = {
|
|
648
|
+
prediction: number;
|
|
649
|
+
slope: number;
|
|
650
|
+
intercept: number;
|
|
651
|
+
};
|
|
652
|
+
declare class LinearRegression extends TechnicalIndicator<LinearRegressionResult, BigSource> {
|
|
653
|
+
readonly prices: BigSource[];
|
|
654
|
+
private readonly period;
|
|
655
|
+
constructor(config: LinearRegressionConfig);
|
|
656
|
+
private calculateRegression;
|
|
657
|
+
update(price: BigSource, replace: boolean): LinearRegressionResult | null;
|
|
658
|
+
getResultOrThrow(): LinearRegressionResult;
|
|
659
|
+
get isStable(): boolean;
|
|
660
|
+
}
|
|
661
|
+
declare class FasterLinearRegression extends TechnicalIndicator<FasterLinearRegressionResult, number> {
|
|
662
|
+
readonly prices: number[];
|
|
663
|
+
private readonly period;
|
|
664
|
+
constructor(config: LinearRegressionConfig);
|
|
665
|
+
private calculateRegression;
|
|
666
|
+
update(price: number, replace: boolean): FasterLinearRegressionResult | null;
|
|
667
|
+
getResultOrThrow(): FasterLinearRegressionResult;
|
|
668
|
+
get isStable(): boolean;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterLinearRegression, type FasterLinearRegressionResult, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseNumber, type HighLowNumber, LinearRegression, type LinearRegressionConfig, type LinearRegressionResult, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseNumber, type OpenHighLowCloseVolume, type OpenHighLowCloseVolumeNumber, Period, type PeriodResult, RMA, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TR, TechnicalIndicator, WMA, WSMA, getAverage, getFasterAverage, getFasterStandardDeviation, getMaximum, getMinimum, getStandardDeviation, getStreaks, pushUpdate };
|
package/dist/index.d.ts
CHANGED
|
@@ -102,8 +102,27 @@ declare class FasterWMA extends FasterMovingAverage {
|
|
|
102
102
|
update(price: number, replace: boolean): number | null;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
declare class RMA extends MovingAverage {
|
|
106
|
+
readonly interval: number;
|
|
107
|
+
private pricesCounter;
|
|
108
|
+
private readonly weightFactor;
|
|
109
|
+
constructor(interval: number);
|
|
110
|
+
update(_price: BigSource, replace: boolean): Big__default;
|
|
111
|
+
getResultOrThrow(): Big__default;
|
|
112
|
+
get isStable(): boolean;
|
|
113
|
+
}
|
|
114
|
+
declare class FasterRMA extends FasterMovingAverage {
|
|
115
|
+
readonly interval: number;
|
|
116
|
+
private pricesCounter;
|
|
117
|
+
private readonly weightFactor;
|
|
118
|
+
constructor(interval: number);
|
|
119
|
+
update(price: number, replace: boolean): number;
|
|
120
|
+
getResultOrThrow(): number;
|
|
121
|
+
get isStable(): boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type MovingAverageTypes = typeof EMA | typeof RMA | typeof SMA | typeof WMA | typeof WSMA;
|
|
125
|
+
type FasterMovingAverageTypes = typeof FasterEMA | typeof FasterRMA | typeof FasterSMA | typeof FasterWMA | typeof FasterWSMA;
|
|
107
126
|
|
|
108
127
|
interface BandsResult {
|
|
109
128
|
lower: Big$2;
|
|
@@ -617,4 +636,36 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
617
636
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
618
637
|
}
|
|
619
638
|
|
|
620
|
-
|
|
639
|
+
type LinearRegressionConfig = {
|
|
640
|
+
period: number;
|
|
641
|
+
};
|
|
642
|
+
type LinearRegressionResult = {
|
|
643
|
+
prediction: Big__default;
|
|
644
|
+
slope: Big__default;
|
|
645
|
+
intercept: Big__default;
|
|
646
|
+
};
|
|
647
|
+
type FasterLinearRegressionResult = {
|
|
648
|
+
prediction: number;
|
|
649
|
+
slope: number;
|
|
650
|
+
intercept: number;
|
|
651
|
+
};
|
|
652
|
+
declare class LinearRegression extends TechnicalIndicator<LinearRegressionResult, BigSource> {
|
|
653
|
+
readonly prices: BigSource[];
|
|
654
|
+
private readonly period;
|
|
655
|
+
constructor(config: LinearRegressionConfig);
|
|
656
|
+
private calculateRegression;
|
|
657
|
+
update(price: BigSource, replace: boolean): LinearRegressionResult | null;
|
|
658
|
+
getResultOrThrow(): LinearRegressionResult;
|
|
659
|
+
get isStable(): boolean;
|
|
660
|
+
}
|
|
661
|
+
declare class FasterLinearRegression extends TechnicalIndicator<FasterLinearRegressionResult, number> {
|
|
662
|
+
readonly prices: number[];
|
|
663
|
+
private readonly period;
|
|
664
|
+
constructor(config: LinearRegressionConfig);
|
|
665
|
+
private calculateRegression;
|
|
666
|
+
update(price: number, replace: boolean): FasterLinearRegressionResult | null;
|
|
667
|
+
getResultOrThrow(): FasterLinearRegressionResult;
|
|
668
|
+
get isStable(): boolean;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterLinearRegression, type FasterLinearRegressionResult, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseNumber, type HighLowNumber, LinearRegression, type LinearRegressionConfig, type LinearRegressionResult, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseNumber, type OpenHighLowCloseVolume, type OpenHighLowCloseVolumeNumber, Period, type PeriodResult, RMA, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TR, TechnicalIndicator, WMA, WSMA, getAverage, getFasterAverage, getFasterStandardDeviation, getMaximum, getMinimum, getStandardDeviation, getStreaks, pushUpdate };
|
package/dist/index.js
CHANGED
|
@@ -159,8 +159,7 @@ var FasterSMA = class extends FasterMovingAverage {
|
|
|
159
159
|
update(price, replace) {
|
|
160
160
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
161
161
|
if (this.prices.length === this.interval) {
|
|
162
|
-
|
|
163
|
-
return this.setResult(sum / this.prices.length, replace);
|
|
162
|
+
return this.setResult(getFasterAverage(this.prices), replace);
|
|
164
163
|
}
|
|
165
164
|
return null;
|
|
166
165
|
}
|
|
@@ -1334,8 +1333,89 @@ var FasterOBV = class extends NumberIndicatorSeries {
|
|
|
1334
1333
|
}
|
|
1335
1334
|
};
|
|
1336
1335
|
|
|
1337
|
-
// src/
|
|
1336
|
+
// src/RMA/RMA.ts
|
|
1338
1337
|
import Big19 from "big.js";
|
|
1338
|
+
var RMA = class extends MovingAverage {
|
|
1339
|
+
constructor(interval) {
|
|
1340
|
+
super(interval);
|
|
1341
|
+
this.interval = interval;
|
|
1342
|
+
this.weightFactor = 1 / this.interval;
|
|
1343
|
+
}
|
|
1344
|
+
pricesCounter = 0;
|
|
1345
|
+
weightFactor;
|
|
1346
|
+
update(_price, replace) {
|
|
1347
|
+
if (!replace) {
|
|
1348
|
+
this.pricesCounter++;
|
|
1349
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1350
|
+
this.pricesCounter++;
|
|
1351
|
+
}
|
|
1352
|
+
const price = new Big19(_price);
|
|
1353
|
+
if (replace && this.previousResult) {
|
|
1354
|
+
return this.setResult(
|
|
1355
|
+
price.times(this.weightFactor).add(this.previousResult.times(1 - this.weightFactor)),
|
|
1356
|
+
replace
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
return this.setResult(
|
|
1360
|
+
price.times(this.weightFactor).add((this.result ?? price).times(1 - this.weightFactor)),
|
|
1361
|
+
replace
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
getResultOrThrow() {
|
|
1365
|
+
if (this.pricesCounter < this.interval) {
|
|
1366
|
+
throw new NotEnoughDataError();
|
|
1367
|
+
}
|
|
1368
|
+
return this.result;
|
|
1369
|
+
}
|
|
1370
|
+
get isStable() {
|
|
1371
|
+
try {
|
|
1372
|
+
this.getResultOrThrow();
|
|
1373
|
+
return true;
|
|
1374
|
+
} catch {
|
|
1375
|
+
return false;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
var FasterRMA = class extends FasterMovingAverage {
|
|
1380
|
+
constructor(interval) {
|
|
1381
|
+
super(interval);
|
|
1382
|
+
this.interval = interval;
|
|
1383
|
+
this.weightFactor = 1 / this.interval;
|
|
1384
|
+
}
|
|
1385
|
+
pricesCounter = 0;
|
|
1386
|
+
weightFactor;
|
|
1387
|
+
update(price, replace) {
|
|
1388
|
+
if (!replace) {
|
|
1389
|
+
this.pricesCounter++;
|
|
1390
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1391
|
+
this.pricesCounter++;
|
|
1392
|
+
}
|
|
1393
|
+
if (replace && this.previousResult !== void 0) {
|
|
1394
|
+
return this.setResult(price * this.weightFactor + this.previousResult * (1 - this.weightFactor), replace);
|
|
1395
|
+
}
|
|
1396
|
+
return this.setResult(
|
|
1397
|
+
price * this.weightFactor + (this.result !== void 0 ? this.result : price) * (1 - this.weightFactor),
|
|
1398
|
+
replace
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
getResultOrThrow() {
|
|
1402
|
+
if (this.pricesCounter < this.interval) {
|
|
1403
|
+
throw new NotEnoughDataError();
|
|
1404
|
+
}
|
|
1405
|
+
return this.result;
|
|
1406
|
+
}
|
|
1407
|
+
get isStable() {
|
|
1408
|
+
try {
|
|
1409
|
+
this.getResultOrThrow();
|
|
1410
|
+
return true;
|
|
1411
|
+
} catch {
|
|
1412
|
+
return false;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
// src/ROC/ROC.ts
|
|
1418
|
+
import Big20 from "big.js";
|
|
1339
1419
|
var ROC = class extends BigIndicatorSeries {
|
|
1340
1420
|
constructor(interval) {
|
|
1341
1421
|
super();
|
|
@@ -1345,7 +1425,7 @@ var ROC = class extends BigIndicatorSeries {
|
|
|
1345
1425
|
update(price, replace) {
|
|
1346
1426
|
const comparePrice = pushUpdate(this.prices, replace, price, this.interval);
|
|
1347
1427
|
if (comparePrice) {
|
|
1348
|
-
return this.setResult(new
|
|
1428
|
+
return this.setResult(new Big20(price).sub(comparePrice).div(comparePrice), replace);
|
|
1349
1429
|
}
|
|
1350
1430
|
return null;
|
|
1351
1431
|
}
|
|
@@ -1366,7 +1446,7 @@ var FasterROC = class extends NumberIndicatorSeries {
|
|
|
1366
1446
|
};
|
|
1367
1447
|
|
|
1368
1448
|
// src/RSI/RSI.ts
|
|
1369
|
-
import
|
|
1449
|
+
import Big21 from "big.js";
|
|
1370
1450
|
var RSI = class extends BigIndicatorSeries {
|
|
1371
1451
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1372
1452
|
super();
|
|
@@ -1377,25 +1457,25 @@ var RSI = class extends BigIndicatorSeries {
|
|
|
1377
1457
|
previousPrices = [];
|
|
1378
1458
|
avgGain;
|
|
1379
1459
|
avgLoss;
|
|
1380
|
-
maxValue = new
|
|
1460
|
+
maxValue = new Big21(100);
|
|
1381
1461
|
update(price, replace) {
|
|
1382
1462
|
pushUpdate(this.previousPrices, replace, price, this.interval);
|
|
1383
1463
|
if (this.previousPrices.length < 2) {
|
|
1384
1464
|
return null;
|
|
1385
1465
|
}
|
|
1386
|
-
const currentPrice = new
|
|
1387
|
-
const previousPrice = new
|
|
1466
|
+
const currentPrice = new Big21(price);
|
|
1467
|
+
const previousPrice = new Big21(this.previousPrices[this.previousPrices.length - 2]);
|
|
1388
1468
|
if (currentPrice.gt(previousPrice)) {
|
|
1389
|
-
this.avgLoss.update(new
|
|
1469
|
+
this.avgLoss.update(new Big21(0), replace);
|
|
1390
1470
|
this.avgGain.update(currentPrice.sub(previousPrice), replace);
|
|
1391
1471
|
} else {
|
|
1392
1472
|
this.avgLoss.update(previousPrice.sub(currentPrice), replace);
|
|
1393
|
-
this.avgGain.update(new
|
|
1473
|
+
this.avgGain.update(new Big21(0), replace);
|
|
1394
1474
|
}
|
|
1395
1475
|
if (this.avgGain.isStable) {
|
|
1396
1476
|
const avgLoss = this.avgLoss.getResultOrThrow();
|
|
1397
1477
|
if (avgLoss.eq(0)) {
|
|
1398
|
-
return this.setResult(new
|
|
1478
|
+
return this.setResult(new Big21(100), replace);
|
|
1399
1479
|
}
|
|
1400
1480
|
const relativeStrength = this.avgGain.getResultOrThrow().div(avgLoss);
|
|
1401
1481
|
return this.setResult(this.maxValue.minus(this.maxValue.div(relativeStrength.add(1))), replace);
|
|
@@ -1441,7 +1521,7 @@ var FasterRSI = class extends NumberIndicatorSeries {
|
|
|
1441
1521
|
};
|
|
1442
1522
|
|
|
1443
1523
|
// src/STOCH/StochasticOscillator.ts
|
|
1444
|
-
import
|
|
1524
|
+
import Big22 from "big.js";
|
|
1445
1525
|
var StochasticOscillator = class extends TechnicalIndicator {
|
|
1446
1526
|
/**
|
|
1447
1527
|
* Constructs a Stochastic Oscillator.
|
|
@@ -1466,8 +1546,8 @@ var StochasticOscillator = class extends TechnicalIndicator {
|
|
|
1466
1546
|
if (this.candles.length === this.n) {
|
|
1467
1547
|
const highest = getMaximum(this.candles.map((candle2) => candle2.high));
|
|
1468
1548
|
const lowest = getMinimum(this.candles.map((candle2) => candle2.low));
|
|
1469
|
-
const divisor = new
|
|
1470
|
-
let fastK = new
|
|
1549
|
+
const divisor = new Big22(highest).minus(lowest);
|
|
1550
|
+
let fastK = new Big22(100).mul(new Big22(candle.close).minus(lowest));
|
|
1471
1551
|
fastK = fastK.div(divisor.eq(0) ? 1 : divisor);
|
|
1472
1552
|
const stochK = this.periodM.update(fastK, replace);
|
|
1473
1553
|
const stochD = stochK && this.periodP.update(stochK, replace);
|
|
@@ -1520,7 +1600,7 @@ var FasterStochasticOscillator = class extends TechnicalIndicator {
|
|
|
1520
1600
|
};
|
|
1521
1601
|
|
|
1522
1602
|
// src/STOCH/StochasticRSI.ts
|
|
1523
|
-
import
|
|
1603
|
+
import Big23 from "big.js";
|
|
1524
1604
|
var StochasticRSI = class extends BigIndicatorSeries {
|
|
1525
1605
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1526
1606
|
super();
|
|
@@ -1539,7 +1619,7 @@ var StochasticRSI = class extends BigIndicatorSeries {
|
|
|
1539
1619
|
const max = periodResult.highest;
|
|
1540
1620
|
const denominator = max.minus(min);
|
|
1541
1621
|
if (denominator.eq(0)) {
|
|
1542
|
-
return this.setResult(new
|
|
1622
|
+
return this.setResult(new Big23(100), false);
|
|
1543
1623
|
}
|
|
1544
1624
|
const numerator = rsiResult.minus(min);
|
|
1545
1625
|
return this.setResult(numerator.div(denominator), false);
|
|
@@ -1576,8 +1656,118 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1576
1656
|
}
|
|
1577
1657
|
};
|
|
1578
1658
|
|
|
1659
|
+
// src/LINREG/LinearRegression.ts
|
|
1660
|
+
import Big24 from "big.js";
|
|
1661
|
+
var LinearRegression = class extends TechnicalIndicator {
|
|
1662
|
+
prices = [];
|
|
1663
|
+
period;
|
|
1664
|
+
constructor(config) {
|
|
1665
|
+
super();
|
|
1666
|
+
this.period = config.period;
|
|
1667
|
+
}
|
|
1668
|
+
calculateRegression(prices) {
|
|
1669
|
+
const n = new Big24(prices.length);
|
|
1670
|
+
const xValues = Array.from({ length: prices.length }, (_, i) => new Big24(i));
|
|
1671
|
+
const yValues = prices.map((p) => new Big24(p));
|
|
1672
|
+
const sumX = xValues.reduce((sum, x) => sum.add(x), new Big24(0));
|
|
1673
|
+
const sumY = yValues.reduce((sum, y) => sum.add(y), new Big24(0));
|
|
1674
|
+
const sumXY = xValues.reduce((sum, x, i) => sum.add(x.mul(yValues[i])), new Big24(0));
|
|
1675
|
+
const sumXX = xValues.reduce((sum, x) => sum.add(x.mul(x)), new Big24(0));
|
|
1676
|
+
const slope = sumXY.mul(n).sub(sumX.mul(sumY)).div(sumXX.mul(n).sub(sumX.mul(sumX)));
|
|
1677
|
+
const intercept = sumY.sub(slope.mul(sumX)).div(n);
|
|
1678
|
+
const prediction = slope.mul(xValues[xValues.length - 1]).add(intercept);
|
|
1679
|
+
return {
|
|
1680
|
+
intercept,
|
|
1681
|
+
prediction,
|
|
1682
|
+
slope
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
update(price, replace) {
|
|
1686
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1687
|
+
if (this.prices.length < this.period) {
|
|
1688
|
+
return null;
|
|
1689
|
+
}
|
|
1690
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1691
|
+
}
|
|
1692
|
+
getResultOrThrow() {
|
|
1693
|
+
if (this.prices.length < this.period) {
|
|
1694
|
+
throw new NotEnoughDataError();
|
|
1695
|
+
}
|
|
1696
|
+
return this.result;
|
|
1697
|
+
}
|
|
1698
|
+
get isStable() {
|
|
1699
|
+
try {
|
|
1700
|
+
this.getResultOrThrow();
|
|
1701
|
+
return true;
|
|
1702
|
+
} catch {
|
|
1703
|
+
return false;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
var FasterLinearRegression = class extends TechnicalIndicator {
|
|
1708
|
+
prices = [];
|
|
1709
|
+
period;
|
|
1710
|
+
constructor(config) {
|
|
1711
|
+
super();
|
|
1712
|
+
this.period = config.period;
|
|
1713
|
+
}
|
|
1714
|
+
calculateRegression(prices) {
|
|
1715
|
+
const n = prices.length;
|
|
1716
|
+
const isPerfectLinearTrend = prices.every((price, i) => {
|
|
1717
|
+
if (i === 0) {
|
|
1718
|
+
return true;
|
|
1719
|
+
}
|
|
1720
|
+
return Math.abs(price - prices[i - 1] - 1) < 1e-10;
|
|
1721
|
+
});
|
|
1722
|
+
if (isPerfectLinearTrend) {
|
|
1723
|
+
const slope2 = 1;
|
|
1724
|
+
const intercept2 = prices[0] - slope2;
|
|
1725
|
+
const nextX = n;
|
|
1726
|
+
const prediction2 = slope2 * nextX + intercept2;
|
|
1727
|
+
return { intercept: intercept2, prediction: prediction2, slope: slope2 };
|
|
1728
|
+
}
|
|
1729
|
+
const sumX = (n - 1) * n / 2;
|
|
1730
|
+
const sumY = prices.reduce((a, b) => a + b, 0);
|
|
1731
|
+
let sumXY = 0;
|
|
1732
|
+
let sumXX = 0;
|
|
1733
|
+
for (let i = 0; i < n; i++) {
|
|
1734
|
+
sumXY += i * prices[i];
|
|
1735
|
+
sumXX += i * i;
|
|
1736
|
+
}
|
|
1737
|
+
const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
|
|
1738
|
+
const intercept = (sumY - slope * sumX) / n;
|
|
1739
|
+
const prediction = slope * n + intercept;
|
|
1740
|
+
return {
|
|
1741
|
+
intercept,
|
|
1742
|
+
prediction,
|
|
1743
|
+
slope
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
update(price, replace) {
|
|
1747
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1748
|
+
if (this.prices.length < this.period) {
|
|
1749
|
+
return null;
|
|
1750
|
+
}
|
|
1751
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1752
|
+
}
|
|
1753
|
+
getResultOrThrow() {
|
|
1754
|
+
if (!this.result) {
|
|
1755
|
+
throw new NotEnoughDataError();
|
|
1756
|
+
}
|
|
1757
|
+
return this.result;
|
|
1758
|
+
}
|
|
1759
|
+
get isStable() {
|
|
1760
|
+
try {
|
|
1761
|
+
this.getResultOrThrow();
|
|
1762
|
+
return true;
|
|
1763
|
+
} catch {
|
|
1764
|
+
return false;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1579
1769
|
// src/WMA/WMA.ts
|
|
1580
|
-
import
|
|
1770
|
+
import Big25 from "big.js";
|
|
1581
1771
|
var WMA = class extends MovingAverage {
|
|
1582
1772
|
constructor(interval) {
|
|
1583
1773
|
super(interval);
|
|
@@ -1588,9 +1778,9 @@ var WMA = class extends MovingAverage {
|
|
|
1588
1778
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1589
1779
|
if (this.prices.length === this.interval) {
|
|
1590
1780
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1591
|
-
const weightedPrice = new
|
|
1781
|
+
const weightedPrice = new Big25(price2).mul(index + 1);
|
|
1592
1782
|
return acc.add(weightedPrice);
|
|
1593
|
-
}, new
|
|
1783
|
+
}, new Big25(0));
|
|
1594
1784
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1595
1785
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1596
1786
|
return this.setResult(weightedMa, replace);
|
|
@@ -1648,12 +1838,14 @@ export {
|
|
|
1648
1838
|
FasterDMA,
|
|
1649
1839
|
FasterDX,
|
|
1650
1840
|
FasterEMA,
|
|
1841
|
+
FasterLinearRegression,
|
|
1651
1842
|
FasterMACD,
|
|
1652
1843
|
FasterMAD,
|
|
1653
1844
|
FasterMOM,
|
|
1654
1845
|
FasterMovingAverage,
|
|
1655
1846
|
FasterOBV,
|
|
1656
1847
|
FasterPeriod,
|
|
1848
|
+
FasterRMA,
|
|
1657
1849
|
FasterROC,
|
|
1658
1850
|
FasterRSI,
|
|
1659
1851
|
FasterSMA,
|
|
@@ -1662,6 +1854,7 @@ export {
|
|
|
1662
1854
|
FasterTR,
|
|
1663
1855
|
FasterWMA,
|
|
1664
1856
|
FasterWSMA,
|
|
1857
|
+
LinearRegression,
|
|
1665
1858
|
MACD,
|
|
1666
1859
|
MAD,
|
|
1667
1860
|
MOM,
|
|
@@ -1670,6 +1863,7 @@ export {
|
|
|
1670
1863
|
NumberIndicatorSeries,
|
|
1671
1864
|
OBV,
|
|
1672
1865
|
Period,
|
|
1866
|
+
RMA,
|
|
1673
1867
|
ROC,
|
|
1674
1868
|
RSI,
|
|
1675
1869
|
SMA,
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@vitest/coverage-v8": "^1.1.1",
|
|
16
16
|
"benchmark": "^2.1.4",
|
|
17
17
|
"dependency-cruiser": "^16.9.0",
|
|
18
|
-
"eslint": "^8.
|
|
18
|
+
"eslint": "^8.57.0",
|
|
19
19
|
"generate-changelog": "^1.8.0",
|
|
20
20
|
"husky": "^4.3.8",
|
|
21
21
|
"lint-staged": "^15.0.2",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"fix:code": "npm run lint:code -- --fix",
|
|
88
88
|
"fix:other": "npm run prettier -- --write",
|
|
89
89
|
"lint": "npm run lint:types && npm run lint:code && npm run lint:other",
|
|
90
|
-
"lint:code": "eslint
|
|
90
|
+
"lint:code": "eslint .",
|
|
91
91
|
"lint:other": "npm run prettier -- --list-different",
|
|
92
92
|
"lint:types": "tsc --noEmit",
|
|
93
93
|
"postversion": "git push origin && git push origin --tags && npm publish",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"test:types": "npm run lint:types"
|
|
105
105
|
},
|
|
106
106
|
"type": "module",
|
|
107
|
-
"version": "6.0
|
|
107
|
+
"version": "6.2.0"
|
|
108
108
|
}
|