trading-signals 6.1.0 → 6.3.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 +2 -0
- package/dist/index.cjs +144 -12
- package/dist/index.d.cts +49 -3
- package/dist/index.d.ts +49 -3
- package/dist/index.js +140 -10
- package/package.json +20 -20
package/README.md
CHANGED
|
@@ -132,6 +132,7 @@ 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)
|
|
@@ -201,6 +202,7 @@ It is very important to do your own analysis before making any investment based
|
|
|
201
202
|
|
|
202
203
|
- [Cloud9Trader Indicators (JavaScript)](https://github.com/Cloud9Trader/TechnicalIndicators)
|
|
203
204
|
- [Crypto Trading Hub Indicators (TypeScript)](https://github.com/anandanand84/technicalindicators)
|
|
205
|
+
- [Indicator TS](https://github.com/cinar/indicatorts)
|
|
204
206
|
- [Jesse Trading Bot Indicators (Python)](https://docs.jesse.trade/docs/indicators/reference.html)
|
|
205
207
|
- [LEAN Indicators](https://github.com/QuantConnect/Lean/tree/master/Indicators)
|
|
206
208
|
- [libindicators (C#)](https://github.com/mgfx/libindicators)
|
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,6 +59,7 @@ __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,
|
|
@@ -74,6 +75,7 @@ __export(index_exports, {
|
|
|
74
75
|
FasterTR: () => FasterTR,
|
|
75
76
|
FasterWMA: () => FasterWMA,
|
|
76
77
|
FasterWSMA: () => FasterWSMA,
|
|
78
|
+
LinearRegression: () => LinearRegression,
|
|
77
79
|
MACD: () => MACD,
|
|
78
80
|
MAD: () => MAD,
|
|
79
81
|
MOM: () => MOM,
|
|
@@ -102,7 +104,7 @@ __export(index_exports, {
|
|
|
102
104
|
pushUpdate: () => pushUpdate
|
|
103
105
|
});
|
|
104
106
|
module.exports = __toCommonJS(index_exports);
|
|
105
|
-
var
|
|
107
|
+
var import_big26 = __toESM(require("big.js"), 1);
|
|
106
108
|
|
|
107
109
|
// src/error/NotEnoughDataError.ts
|
|
108
110
|
var NotEnoughDataError = class extends Error {
|
|
@@ -1705,11 +1707,15 @@ var FasterStochasticOscillator = class extends TechnicalIndicator {
|
|
|
1705
1707
|
// src/STOCH/StochasticRSI.ts
|
|
1706
1708
|
var import_big23 = __toESM(require("big.js"), 1);
|
|
1707
1709
|
var StochasticRSI = class extends BigIndicatorSeries {
|
|
1708
|
-
constructor(interval,
|
|
1710
|
+
constructor(interval, SmoothingRSI = WSMA, smoothing = {
|
|
1711
|
+
d: new SMA(3),
|
|
1712
|
+
k: new SMA(3)
|
|
1713
|
+
}) {
|
|
1709
1714
|
super();
|
|
1710
1715
|
this.interval = interval;
|
|
1716
|
+
this.smoothing = smoothing;
|
|
1711
1717
|
this.period = new Period(interval);
|
|
1712
|
-
this.rsi = new RSI(interval,
|
|
1718
|
+
this.rsi = new RSI(interval, SmoothingRSI);
|
|
1713
1719
|
}
|
|
1714
1720
|
period;
|
|
1715
1721
|
rsi;
|
|
@@ -1722,21 +1728,30 @@ var StochasticRSI = class extends BigIndicatorSeries {
|
|
|
1722
1728
|
const max = periodResult.highest;
|
|
1723
1729
|
const denominator = max.minus(min);
|
|
1724
1730
|
if (denominator.eq(0)) {
|
|
1725
|
-
return this.setResult(new import_big23.default(100),
|
|
1731
|
+
return this.setResult(new import_big23.default(100), replace);
|
|
1726
1732
|
}
|
|
1727
1733
|
const numerator = rsiResult.minus(min);
|
|
1728
|
-
|
|
1734
|
+
const stochRSI = numerator.div(denominator);
|
|
1735
|
+
const k = this.smoothing.k.update(stochRSI, replace);
|
|
1736
|
+
if (k) {
|
|
1737
|
+
this.smoothing.d.update(k, replace);
|
|
1738
|
+
}
|
|
1739
|
+
return this.setResult(stochRSI, replace);
|
|
1729
1740
|
}
|
|
1730
1741
|
}
|
|
1731
1742
|
return null;
|
|
1732
1743
|
}
|
|
1733
1744
|
};
|
|
1734
1745
|
var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
1735
|
-
constructor(interval,
|
|
1746
|
+
constructor(interval, SmoothingRSI = FasterWSMA, smoothing = {
|
|
1747
|
+
d: new FasterSMA(3),
|
|
1748
|
+
k: new FasterSMA(3)
|
|
1749
|
+
}) {
|
|
1736
1750
|
super();
|
|
1737
1751
|
this.interval = interval;
|
|
1752
|
+
this.smoothing = smoothing;
|
|
1738
1753
|
this.period = new FasterPeriod(interval);
|
|
1739
|
-
this.rsi = new FasterRSI(interval,
|
|
1754
|
+
this.rsi = new FasterRSI(interval, SmoothingRSI);
|
|
1740
1755
|
}
|
|
1741
1756
|
period;
|
|
1742
1757
|
rsi;
|
|
@@ -1752,15 +1767,130 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1752
1767
|
return this.setResult(100, replace);
|
|
1753
1768
|
}
|
|
1754
1769
|
const numerator = rsiResult - min;
|
|
1755
|
-
|
|
1770
|
+
const stochRSI = numerator / denominator;
|
|
1771
|
+
const k = this.smoothing.k.update(stochRSI, replace);
|
|
1772
|
+
if (k) {
|
|
1773
|
+
this.smoothing.d.update(k, replace);
|
|
1774
|
+
}
|
|
1775
|
+
return this.setResult(stochRSI, replace);
|
|
1756
1776
|
}
|
|
1757
1777
|
}
|
|
1758
1778
|
return null;
|
|
1759
1779
|
}
|
|
1760
1780
|
};
|
|
1761
1781
|
|
|
1762
|
-
// src/
|
|
1782
|
+
// src/LINREG/LinearRegression.ts
|
|
1763
1783
|
var import_big24 = __toESM(require("big.js"), 1);
|
|
1784
|
+
var LinearRegression = class extends TechnicalIndicator {
|
|
1785
|
+
prices = [];
|
|
1786
|
+
period;
|
|
1787
|
+
constructor(config) {
|
|
1788
|
+
super();
|
|
1789
|
+
this.period = config.period;
|
|
1790
|
+
}
|
|
1791
|
+
calculateRegression(prices) {
|
|
1792
|
+
const n = new import_big24.default(prices.length);
|
|
1793
|
+
const xValues = Array.from({ length: prices.length }, (_, i) => new import_big24.default(i));
|
|
1794
|
+
const yValues = prices.map((p) => new import_big24.default(p));
|
|
1795
|
+
const sumX = xValues.reduce((sum, x) => sum.add(x), new import_big24.default(0));
|
|
1796
|
+
const sumY = yValues.reduce((sum, y) => sum.add(y), new import_big24.default(0));
|
|
1797
|
+
const sumXY = xValues.reduce((sum, x, i) => sum.add(x.mul(yValues[i])), new import_big24.default(0));
|
|
1798
|
+
const sumXX = xValues.reduce((sum, x) => sum.add(x.mul(x)), new import_big24.default(0));
|
|
1799
|
+
const slope = sumXY.mul(n).sub(sumX.mul(sumY)).div(sumXX.mul(n).sub(sumX.mul(sumX)));
|
|
1800
|
+
const intercept = sumY.sub(slope.mul(sumX)).div(n);
|
|
1801
|
+
const prediction = slope.mul(xValues[xValues.length - 1]).add(intercept);
|
|
1802
|
+
return {
|
|
1803
|
+
intercept,
|
|
1804
|
+
prediction,
|
|
1805
|
+
slope
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1808
|
+
update(price, replace) {
|
|
1809
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1810
|
+
if (this.prices.length < this.period) {
|
|
1811
|
+
return null;
|
|
1812
|
+
}
|
|
1813
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1814
|
+
}
|
|
1815
|
+
getResultOrThrow() {
|
|
1816
|
+
if (this.prices.length < this.period) {
|
|
1817
|
+
throw new NotEnoughDataError();
|
|
1818
|
+
}
|
|
1819
|
+
return this.result;
|
|
1820
|
+
}
|
|
1821
|
+
get isStable() {
|
|
1822
|
+
try {
|
|
1823
|
+
this.getResultOrThrow();
|
|
1824
|
+
return true;
|
|
1825
|
+
} catch {
|
|
1826
|
+
return false;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
var FasterLinearRegression = class extends TechnicalIndicator {
|
|
1831
|
+
prices = [];
|
|
1832
|
+
period;
|
|
1833
|
+
constructor(config) {
|
|
1834
|
+
super();
|
|
1835
|
+
this.period = config.period;
|
|
1836
|
+
}
|
|
1837
|
+
calculateRegression(prices) {
|
|
1838
|
+
const n = prices.length;
|
|
1839
|
+
const isPerfectLinearTrend = prices.every((price, i) => {
|
|
1840
|
+
if (i === 0) {
|
|
1841
|
+
return true;
|
|
1842
|
+
}
|
|
1843
|
+
return Math.abs(price - prices[i - 1] - 1) < 1e-10;
|
|
1844
|
+
});
|
|
1845
|
+
if (isPerfectLinearTrend) {
|
|
1846
|
+
const slope2 = 1;
|
|
1847
|
+
const intercept2 = prices[0] - slope2;
|
|
1848
|
+
const nextX = n;
|
|
1849
|
+
const prediction2 = slope2 * nextX + intercept2;
|
|
1850
|
+
return { intercept: intercept2, prediction: prediction2, slope: slope2 };
|
|
1851
|
+
}
|
|
1852
|
+
const sumX = (n - 1) * n / 2;
|
|
1853
|
+
const sumY = prices.reduce((a, b) => a + b, 0);
|
|
1854
|
+
let sumXY = 0;
|
|
1855
|
+
let sumXX = 0;
|
|
1856
|
+
for (let i = 0; i < n; i++) {
|
|
1857
|
+
sumXY += i * prices[i];
|
|
1858
|
+
sumXX += i * i;
|
|
1859
|
+
}
|
|
1860
|
+
const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
|
|
1861
|
+
const intercept = (sumY - slope * sumX) / n;
|
|
1862
|
+
const prediction = slope * n + intercept;
|
|
1863
|
+
return {
|
|
1864
|
+
intercept,
|
|
1865
|
+
prediction,
|
|
1866
|
+
slope
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
update(price, replace) {
|
|
1870
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1871
|
+
if (this.prices.length < this.period) {
|
|
1872
|
+
return null;
|
|
1873
|
+
}
|
|
1874
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1875
|
+
}
|
|
1876
|
+
getResultOrThrow() {
|
|
1877
|
+
if (!this.result) {
|
|
1878
|
+
throw new NotEnoughDataError();
|
|
1879
|
+
}
|
|
1880
|
+
return this.result;
|
|
1881
|
+
}
|
|
1882
|
+
get isStable() {
|
|
1883
|
+
try {
|
|
1884
|
+
this.getResultOrThrow();
|
|
1885
|
+
return true;
|
|
1886
|
+
} catch {
|
|
1887
|
+
return false;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
|
|
1892
|
+
// src/WMA/WMA.ts
|
|
1893
|
+
var import_big25 = __toESM(require("big.js"), 1);
|
|
1764
1894
|
var WMA = class extends MovingAverage {
|
|
1765
1895
|
constructor(interval) {
|
|
1766
1896
|
super(interval);
|
|
@@ -1771,9 +1901,9 @@ var WMA = class extends MovingAverage {
|
|
|
1771
1901
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1772
1902
|
if (this.prices.length === this.interval) {
|
|
1773
1903
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1774
|
-
const weightedPrice = new
|
|
1904
|
+
const weightedPrice = new import_big25.default(price2).mul(index + 1);
|
|
1775
1905
|
return acc.add(weightedPrice);
|
|
1776
|
-
}, new
|
|
1906
|
+
}, new import_big25.default(0));
|
|
1777
1907
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1778
1908
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1779
1909
|
return this.setResult(weightedMa, replace);
|
|
@@ -1832,6 +1962,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1832
1962
|
FasterDMA,
|
|
1833
1963
|
FasterDX,
|
|
1834
1964
|
FasterEMA,
|
|
1965
|
+
FasterLinearRegression,
|
|
1835
1966
|
FasterMACD,
|
|
1836
1967
|
FasterMAD,
|
|
1837
1968
|
FasterMOM,
|
|
@@ -1847,6 +1978,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1847
1978
|
FasterTR,
|
|
1848
1979
|
FasterWMA,
|
|
1849
1980
|
FasterWSMA,
|
|
1981
|
+
LinearRegression,
|
|
1850
1982
|
MACD,
|
|
1851
1983
|
MAD,
|
|
1852
1984
|
MOM,
|
package/dist/index.d.cts
CHANGED
|
@@ -612,16 +612,30 @@ declare class FasterStochasticOscillator extends TechnicalIndicator<FasterStocha
|
|
|
612
612
|
|
|
613
613
|
declare class StochasticRSI extends BigIndicatorSeries {
|
|
614
614
|
readonly interval: number;
|
|
615
|
+
readonly smoothing: {
|
|
616
|
+
readonly k: MovingAverage;
|
|
617
|
+
readonly d: MovingAverage;
|
|
618
|
+
};
|
|
615
619
|
private readonly period;
|
|
616
620
|
private readonly rsi;
|
|
617
|
-
constructor(interval: number,
|
|
621
|
+
constructor(interval: number, SmoothingRSI?: MovingAverageTypes, smoothing?: {
|
|
622
|
+
readonly k: MovingAverage;
|
|
623
|
+
readonly d: MovingAverage;
|
|
624
|
+
});
|
|
618
625
|
update(price: BigSource, replace: boolean): Big__default.Big | null;
|
|
619
626
|
}
|
|
620
627
|
declare class FasterStochasticRSI extends NumberIndicatorSeries {
|
|
621
628
|
readonly interval: number;
|
|
629
|
+
readonly smoothing: {
|
|
630
|
+
readonly k: FasterMovingAverage;
|
|
631
|
+
readonly d: FasterMovingAverage;
|
|
632
|
+
};
|
|
622
633
|
private readonly period;
|
|
623
634
|
private readonly rsi;
|
|
624
|
-
constructor(interval: number,
|
|
635
|
+
constructor(interval: number, SmoothingRSI?: FasterMovingAverageTypes, smoothing?: {
|
|
636
|
+
readonly k: FasterMovingAverage;
|
|
637
|
+
readonly d: FasterMovingAverage;
|
|
638
|
+
});
|
|
625
639
|
update(price: number, replace: boolean): number | null;
|
|
626
640
|
}
|
|
627
641
|
|
|
@@ -636,4 +650,36 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
636
650
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
637
651
|
}
|
|
638
652
|
|
|
639
|
-
|
|
653
|
+
type LinearRegressionConfig = {
|
|
654
|
+
period: number;
|
|
655
|
+
};
|
|
656
|
+
type LinearRegressionResult = {
|
|
657
|
+
prediction: Big__default;
|
|
658
|
+
slope: Big__default;
|
|
659
|
+
intercept: Big__default;
|
|
660
|
+
};
|
|
661
|
+
type FasterLinearRegressionResult = {
|
|
662
|
+
prediction: number;
|
|
663
|
+
slope: number;
|
|
664
|
+
intercept: number;
|
|
665
|
+
};
|
|
666
|
+
declare class LinearRegression extends TechnicalIndicator<LinearRegressionResult, BigSource> {
|
|
667
|
+
readonly prices: BigSource[];
|
|
668
|
+
private readonly period;
|
|
669
|
+
constructor(config: LinearRegressionConfig);
|
|
670
|
+
private calculateRegression;
|
|
671
|
+
update(price: BigSource, replace: boolean): LinearRegressionResult | null;
|
|
672
|
+
getResultOrThrow(): LinearRegressionResult;
|
|
673
|
+
get isStable(): boolean;
|
|
674
|
+
}
|
|
675
|
+
declare class FasterLinearRegression extends TechnicalIndicator<FasterLinearRegressionResult, number> {
|
|
676
|
+
readonly prices: number[];
|
|
677
|
+
private readonly period;
|
|
678
|
+
constructor(config: LinearRegressionConfig);
|
|
679
|
+
private calculateRegression;
|
|
680
|
+
update(price: number, replace: boolean): FasterLinearRegressionResult | null;
|
|
681
|
+
getResultOrThrow(): FasterLinearRegressionResult;
|
|
682
|
+
get isStable(): boolean;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
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
|
@@ -612,16 +612,30 @@ declare class FasterStochasticOscillator extends TechnicalIndicator<FasterStocha
|
|
|
612
612
|
|
|
613
613
|
declare class StochasticRSI extends BigIndicatorSeries {
|
|
614
614
|
readonly interval: number;
|
|
615
|
+
readonly smoothing: {
|
|
616
|
+
readonly k: MovingAverage;
|
|
617
|
+
readonly d: MovingAverage;
|
|
618
|
+
};
|
|
615
619
|
private readonly period;
|
|
616
620
|
private readonly rsi;
|
|
617
|
-
constructor(interval: number,
|
|
621
|
+
constructor(interval: number, SmoothingRSI?: MovingAverageTypes, smoothing?: {
|
|
622
|
+
readonly k: MovingAverage;
|
|
623
|
+
readonly d: MovingAverage;
|
|
624
|
+
});
|
|
618
625
|
update(price: BigSource, replace: boolean): Big__default.Big | null;
|
|
619
626
|
}
|
|
620
627
|
declare class FasterStochasticRSI extends NumberIndicatorSeries {
|
|
621
628
|
readonly interval: number;
|
|
629
|
+
readonly smoothing: {
|
|
630
|
+
readonly k: FasterMovingAverage;
|
|
631
|
+
readonly d: FasterMovingAverage;
|
|
632
|
+
};
|
|
622
633
|
private readonly period;
|
|
623
634
|
private readonly rsi;
|
|
624
|
-
constructor(interval: number,
|
|
635
|
+
constructor(interval: number, SmoothingRSI?: FasterMovingAverageTypes, smoothing?: {
|
|
636
|
+
readonly k: FasterMovingAverage;
|
|
637
|
+
readonly d: FasterMovingAverage;
|
|
638
|
+
});
|
|
625
639
|
update(price: number, replace: boolean): number | null;
|
|
626
640
|
}
|
|
627
641
|
|
|
@@ -636,4 +650,36 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
636
650
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
637
651
|
}
|
|
638
652
|
|
|
639
|
-
|
|
653
|
+
type LinearRegressionConfig = {
|
|
654
|
+
period: number;
|
|
655
|
+
};
|
|
656
|
+
type LinearRegressionResult = {
|
|
657
|
+
prediction: Big__default;
|
|
658
|
+
slope: Big__default;
|
|
659
|
+
intercept: Big__default;
|
|
660
|
+
};
|
|
661
|
+
type FasterLinearRegressionResult = {
|
|
662
|
+
prediction: number;
|
|
663
|
+
slope: number;
|
|
664
|
+
intercept: number;
|
|
665
|
+
};
|
|
666
|
+
declare class LinearRegression extends TechnicalIndicator<LinearRegressionResult, BigSource> {
|
|
667
|
+
readonly prices: BigSource[];
|
|
668
|
+
private readonly period;
|
|
669
|
+
constructor(config: LinearRegressionConfig);
|
|
670
|
+
private calculateRegression;
|
|
671
|
+
update(price: BigSource, replace: boolean): LinearRegressionResult | null;
|
|
672
|
+
getResultOrThrow(): LinearRegressionResult;
|
|
673
|
+
get isStable(): boolean;
|
|
674
|
+
}
|
|
675
|
+
declare class FasterLinearRegression extends TechnicalIndicator<FasterLinearRegressionResult, number> {
|
|
676
|
+
readonly prices: number[];
|
|
677
|
+
private readonly period;
|
|
678
|
+
constructor(config: LinearRegressionConfig);
|
|
679
|
+
private calculateRegression;
|
|
680
|
+
update(price: number, replace: boolean): FasterLinearRegressionResult | null;
|
|
681
|
+
getResultOrThrow(): FasterLinearRegressionResult;
|
|
682
|
+
get isStable(): boolean;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
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
|
@@ -1602,11 +1602,15 @@ var FasterStochasticOscillator = class extends TechnicalIndicator {
|
|
|
1602
1602
|
// src/STOCH/StochasticRSI.ts
|
|
1603
1603
|
import Big23 from "big.js";
|
|
1604
1604
|
var StochasticRSI = class extends BigIndicatorSeries {
|
|
1605
|
-
constructor(interval,
|
|
1605
|
+
constructor(interval, SmoothingRSI = WSMA, smoothing = {
|
|
1606
|
+
d: new SMA(3),
|
|
1607
|
+
k: new SMA(3)
|
|
1608
|
+
}) {
|
|
1606
1609
|
super();
|
|
1607
1610
|
this.interval = interval;
|
|
1611
|
+
this.smoothing = smoothing;
|
|
1608
1612
|
this.period = new Period(interval);
|
|
1609
|
-
this.rsi = new RSI(interval,
|
|
1613
|
+
this.rsi = new RSI(interval, SmoothingRSI);
|
|
1610
1614
|
}
|
|
1611
1615
|
period;
|
|
1612
1616
|
rsi;
|
|
@@ -1619,21 +1623,30 @@ var StochasticRSI = class extends BigIndicatorSeries {
|
|
|
1619
1623
|
const max = periodResult.highest;
|
|
1620
1624
|
const denominator = max.minus(min);
|
|
1621
1625
|
if (denominator.eq(0)) {
|
|
1622
|
-
return this.setResult(new Big23(100),
|
|
1626
|
+
return this.setResult(new Big23(100), replace);
|
|
1623
1627
|
}
|
|
1624
1628
|
const numerator = rsiResult.minus(min);
|
|
1625
|
-
|
|
1629
|
+
const stochRSI = numerator.div(denominator);
|
|
1630
|
+
const k = this.smoothing.k.update(stochRSI, replace);
|
|
1631
|
+
if (k) {
|
|
1632
|
+
this.smoothing.d.update(k, replace);
|
|
1633
|
+
}
|
|
1634
|
+
return this.setResult(stochRSI, replace);
|
|
1626
1635
|
}
|
|
1627
1636
|
}
|
|
1628
1637
|
return null;
|
|
1629
1638
|
}
|
|
1630
1639
|
};
|
|
1631
1640
|
var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
1632
|
-
constructor(interval,
|
|
1641
|
+
constructor(interval, SmoothingRSI = FasterWSMA, smoothing = {
|
|
1642
|
+
d: new FasterSMA(3),
|
|
1643
|
+
k: new FasterSMA(3)
|
|
1644
|
+
}) {
|
|
1633
1645
|
super();
|
|
1634
1646
|
this.interval = interval;
|
|
1647
|
+
this.smoothing = smoothing;
|
|
1635
1648
|
this.period = new FasterPeriod(interval);
|
|
1636
|
-
this.rsi = new FasterRSI(interval,
|
|
1649
|
+
this.rsi = new FasterRSI(interval, SmoothingRSI);
|
|
1637
1650
|
}
|
|
1638
1651
|
period;
|
|
1639
1652
|
rsi;
|
|
@@ -1649,15 +1662,130 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1649
1662
|
return this.setResult(100, replace);
|
|
1650
1663
|
}
|
|
1651
1664
|
const numerator = rsiResult - min;
|
|
1652
|
-
|
|
1665
|
+
const stochRSI = numerator / denominator;
|
|
1666
|
+
const k = this.smoothing.k.update(stochRSI, replace);
|
|
1667
|
+
if (k) {
|
|
1668
|
+
this.smoothing.d.update(k, replace);
|
|
1669
|
+
}
|
|
1670
|
+
return this.setResult(stochRSI, replace);
|
|
1653
1671
|
}
|
|
1654
1672
|
}
|
|
1655
1673
|
return null;
|
|
1656
1674
|
}
|
|
1657
1675
|
};
|
|
1658
1676
|
|
|
1659
|
-
// src/
|
|
1677
|
+
// src/LINREG/LinearRegression.ts
|
|
1660
1678
|
import Big24 from "big.js";
|
|
1679
|
+
var LinearRegression = class extends TechnicalIndicator {
|
|
1680
|
+
prices = [];
|
|
1681
|
+
period;
|
|
1682
|
+
constructor(config) {
|
|
1683
|
+
super();
|
|
1684
|
+
this.period = config.period;
|
|
1685
|
+
}
|
|
1686
|
+
calculateRegression(prices) {
|
|
1687
|
+
const n = new Big24(prices.length);
|
|
1688
|
+
const xValues = Array.from({ length: prices.length }, (_, i) => new Big24(i));
|
|
1689
|
+
const yValues = prices.map((p) => new Big24(p));
|
|
1690
|
+
const sumX = xValues.reduce((sum, x) => sum.add(x), new Big24(0));
|
|
1691
|
+
const sumY = yValues.reduce((sum, y) => sum.add(y), new Big24(0));
|
|
1692
|
+
const sumXY = xValues.reduce((sum, x, i) => sum.add(x.mul(yValues[i])), new Big24(0));
|
|
1693
|
+
const sumXX = xValues.reduce((sum, x) => sum.add(x.mul(x)), new Big24(0));
|
|
1694
|
+
const slope = sumXY.mul(n).sub(sumX.mul(sumY)).div(sumXX.mul(n).sub(sumX.mul(sumX)));
|
|
1695
|
+
const intercept = sumY.sub(slope.mul(sumX)).div(n);
|
|
1696
|
+
const prediction = slope.mul(xValues[xValues.length - 1]).add(intercept);
|
|
1697
|
+
return {
|
|
1698
|
+
intercept,
|
|
1699
|
+
prediction,
|
|
1700
|
+
slope
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
update(price, replace) {
|
|
1704
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1705
|
+
if (this.prices.length < this.period) {
|
|
1706
|
+
return null;
|
|
1707
|
+
}
|
|
1708
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1709
|
+
}
|
|
1710
|
+
getResultOrThrow() {
|
|
1711
|
+
if (this.prices.length < this.period) {
|
|
1712
|
+
throw new NotEnoughDataError();
|
|
1713
|
+
}
|
|
1714
|
+
return this.result;
|
|
1715
|
+
}
|
|
1716
|
+
get isStable() {
|
|
1717
|
+
try {
|
|
1718
|
+
this.getResultOrThrow();
|
|
1719
|
+
return true;
|
|
1720
|
+
} catch {
|
|
1721
|
+
return false;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
var FasterLinearRegression = class extends TechnicalIndicator {
|
|
1726
|
+
prices = [];
|
|
1727
|
+
period;
|
|
1728
|
+
constructor(config) {
|
|
1729
|
+
super();
|
|
1730
|
+
this.period = config.period;
|
|
1731
|
+
}
|
|
1732
|
+
calculateRegression(prices) {
|
|
1733
|
+
const n = prices.length;
|
|
1734
|
+
const isPerfectLinearTrend = prices.every((price, i) => {
|
|
1735
|
+
if (i === 0) {
|
|
1736
|
+
return true;
|
|
1737
|
+
}
|
|
1738
|
+
return Math.abs(price - prices[i - 1] - 1) < 1e-10;
|
|
1739
|
+
});
|
|
1740
|
+
if (isPerfectLinearTrend) {
|
|
1741
|
+
const slope2 = 1;
|
|
1742
|
+
const intercept2 = prices[0] - slope2;
|
|
1743
|
+
const nextX = n;
|
|
1744
|
+
const prediction2 = slope2 * nextX + intercept2;
|
|
1745
|
+
return { intercept: intercept2, prediction: prediction2, slope: slope2 };
|
|
1746
|
+
}
|
|
1747
|
+
const sumX = (n - 1) * n / 2;
|
|
1748
|
+
const sumY = prices.reduce((a, b) => a + b, 0);
|
|
1749
|
+
let sumXY = 0;
|
|
1750
|
+
let sumXX = 0;
|
|
1751
|
+
for (let i = 0; i < n; i++) {
|
|
1752
|
+
sumXY += i * prices[i];
|
|
1753
|
+
sumXX += i * i;
|
|
1754
|
+
}
|
|
1755
|
+
const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
|
|
1756
|
+
const intercept = (sumY - slope * sumX) / n;
|
|
1757
|
+
const prediction = slope * n + intercept;
|
|
1758
|
+
return {
|
|
1759
|
+
intercept,
|
|
1760
|
+
prediction,
|
|
1761
|
+
slope
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
update(price, replace) {
|
|
1765
|
+
pushUpdate(this.prices, replace, price, this.period);
|
|
1766
|
+
if (this.prices.length < this.period) {
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
return this.result = this.calculateRegression(this.prices);
|
|
1770
|
+
}
|
|
1771
|
+
getResultOrThrow() {
|
|
1772
|
+
if (!this.result) {
|
|
1773
|
+
throw new NotEnoughDataError();
|
|
1774
|
+
}
|
|
1775
|
+
return this.result;
|
|
1776
|
+
}
|
|
1777
|
+
get isStable() {
|
|
1778
|
+
try {
|
|
1779
|
+
this.getResultOrThrow();
|
|
1780
|
+
return true;
|
|
1781
|
+
} catch {
|
|
1782
|
+
return false;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1786
|
+
|
|
1787
|
+
// src/WMA/WMA.ts
|
|
1788
|
+
import Big25 from "big.js";
|
|
1661
1789
|
var WMA = class extends MovingAverage {
|
|
1662
1790
|
constructor(interval) {
|
|
1663
1791
|
super(interval);
|
|
@@ -1668,9 +1796,9 @@ var WMA = class extends MovingAverage {
|
|
|
1668
1796
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1669
1797
|
if (this.prices.length === this.interval) {
|
|
1670
1798
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1671
|
-
const weightedPrice = new
|
|
1799
|
+
const weightedPrice = new Big25(price2).mul(index + 1);
|
|
1672
1800
|
return acc.add(weightedPrice);
|
|
1673
|
-
}, new
|
|
1801
|
+
}, new Big25(0));
|
|
1674
1802
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1675
1803
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1676
1804
|
return this.setResult(weightedMa, replace);
|
|
@@ -1728,6 +1856,7 @@ export {
|
|
|
1728
1856
|
FasterDMA,
|
|
1729
1857
|
FasterDX,
|
|
1730
1858
|
FasterEMA,
|
|
1859
|
+
FasterLinearRegression,
|
|
1731
1860
|
FasterMACD,
|
|
1732
1861
|
FasterMAD,
|
|
1733
1862
|
FasterMOM,
|
|
@@ -1743,6 +1872,7 @@ export {
|
|
|
1743
1872
|
FasterTR,
|
|
1744
1873
|
FasterWMA,
|
|
1745
1874
|
FasterWSMA,
|
|
1875
|
+
LinearRegression,
|
|
1746
1876
|
MACD,
|
|
1747
1877
|
MAD,
|
|
1748
1878
|
MOM,
|
package/package.json
CHANGED
|
@@ -3,31 +3,31 @@
|
|
|
3
3
|
"url": "https://github.com/bennycode/trading-signals/issues"
|
|
4
4
|
},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@types/big.js": "^6.2.
|
|
7
|
-
"big.js": "^6.2.
|
|
6
|
+
"@types/big.js": "^6.2.2",
|
|
7
|
+
"big.js": "^6.2.2"
|
|
8
8
|
},
|
|
9
9
|
"description": "Technical indicators to run technical analysis with JavaScript / TypeScript.",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@arethetypeswrong/cli": "^0.17.
|
|
12
|
-
"@tstv/eslint-config": "^3.
|
|
13
|
-
"@types/benchmark": "^2.1.
|
|
14
|
-
"@types/node": "^18.
|
|
15
|
-
"@vitest/coverage-v8": "^
|
|
11
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
12
|
+
"@tstv/eslint-config": "^3.2.4",
|
|
13
|
+
"@types/benchmark": "^2.1.5",
|
|
14
|
+
"@types/node": "^18.19.86",
|
|
15
|
+
"@vitest/coverage-v8": "^3.1.2",
|
|
16
16
|
"benchmark": "^2.1.4",
|
|
17
|
-
"dependency-cruiser": "^16.
|
|
18
|
-
"eslint": "^8.57.
|
|
17
|
+
"dependency-cruiser": "^16.10.1",
|
|
18
|
+
"eslint": "^8.57.1",
|
|
19
19
|
"generate-changelog": "^1.8.0",
|
|
20
20
|
"husky": "^4.3.8",
|
|
21
|
-
"lint-staged": "^15.
|
|
22
|
-
"prettier": "^3.
|
|
23
|
-
"pretty-quick": "^4.
|
|
21
|
+
"lint-staged": "^15.5.1",
|
|
22
|
+
"prettier": "^3.5.3",
|
|
23
|
+
"pretty-quick": "^4.1.1",
|
|
24
24
|
"rimraf": "^6.0.1",
|
|
25
|
-
"ts-node": "^10.9.
|
|
26
|
-
"tsup": "^8.
|
|
27
|
-
"typedoc": "0.
|
|
28
|
-
"typedoc-plugin-markdown": "^4.
|
|
29
|
-
"typescript": "^5.
|
|
30
|
-
"vitest": "^
|
|
25
|
+
"ts-node": "^10.9.2",
|
|
26
|
+
"tsup": "^8.4.0",
|
|
27
|
+
"typedoc": "^0.28.3",
|
|
28
|
+
"typedoc-plugin-markdown": "^4.6.3",
|
|
29
|
+
"typescript": "^5.7.3",
|
|
30
|
+
"vitest": "^3.1.2"
|
|
31
31
|
},
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
@@ -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.
|
|
107
|
+
"version": "6.3.0"
|
|
108
108
|
}
|