trading-signals 6.1.0 → 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 +2 -0
- package/dist/index.cjs +119 -5
- package/dist/index.d.cts +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +115 -3
- package/package.json +2 -2
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 {
|
|
@@ -1759,8 +1761,118 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1759
1761
|
}
|
|
1760
1762
|
};
|
|
1761
1763
|
|
|
1762
|
-
// src/
|
|
1764
|
+
// src/LINREG/LinearRegression.ts
|
|
1763
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
|
+
|
|
1874
|
+
// src/WMA/WMA.ts
|
|
1875
|
+
var import_big25 = __toESM(require("big.js"), 1);
|
|
1764
1876
|
var WMA = class extends MovingAverage {
|
|
1765
1877
|
constructor(interval) {
|
|
1766
1878
|
super(interval);
|
|
@@ -1771,9 +1883,9 @@ var WMA = class extends MovingAverage {
|
|
|
1771
1883
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1772
1884
|
if (this.prices.length === this.interval) {
|
|
1773
1885
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1774
|
-
const weightedPrice = new
|
|
1886
|
+
const weightedPrice = new import_big25.default(price2).mul(index + 1);
|
|
1775
1887
|
return acc.add(weightedPrice);
|
|
1776
|
-
}, new
|
|
1888
|
+
}, new import_big25.default(0));
|
|
1777
1889
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1778
1890
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1779
1891
|
return this.setResult(weightedMa, replace);
|
|
@@ -1832,6 +1944,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1832
1944
|
FasterDMA,
|
|
1833
1945
|
FasterDX,
|
|
1834
1946
|
FasterEMA,
|
|
1947
|
+
FasterLinearRegression,
|
|
1835
1948
|
FasterMACD,
|
|
1836
1949
|
FasterMAD,
|
|
1837
1950
|
FasterMOM,
|
|
@@ -1847,6 +1960,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1847
1960
|
FasterTR,
|
|
1848
1961
|
FasterWMA,
|
|
1849
1962
|
FasterWSMA,
|
|
1963
|
+
LinearRegression,
|
|
1850
1964
|
MACD,
|
|
1851
1965
|
MAD,
|
|
1852
1966
|
MOM,
|
package/dist/index.d.cts
CHANGED
|
@@ -636,4 +636,36 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
636
636
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
-
|
|
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
|
@@ -636,4 +636,36 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
636
636
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
-
|
|
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
|
@@ -1656,8 +1656,118 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1656
1656
|
}
|
|
1657
1657
|
};
|
|
1658
1658
|
|
|
1659
|
-
// src/
|
|
1659
|
+
// src/LINREG/LinearRegression.ts
|
|
1660
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
|
+
|
|
1769
|
+
// src/WMA/WMA.ts
|
|
1770
|
+
import Big25 from "big.js";
|
|
1661
1771
|
var WMA = class extends MovingAverage {
|
|
1662
1772
|
constructor(interval) {
|
|
1663
1773
|
super(interval);
|
|
@@ -1668,9 +1778,9 @@ var WMA = class extends MovingAverage {
|
|
|
1668
1778
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1669
1779
|
if (this.prices.length === this.interval) {
|
|
1670
1780
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1671
|
-
const weightedPrice = new
|
|
1781
|
+
const weightedPrice = new Big25(price2).mul(index + 1);
|
|
1672
1782
|
return acc.add(weightedPrice);
|
|
1673
|
-
}, new
|
|
1783
|
+
}, new Big25(0));
|
|
1674
1784
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1675
1785
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1676
1786
|
return this.setResult(weightedMa, replace);
|
|
@@ -1728,6 +1838,7 @@ export {
|
|
|
1728
1838
|
FasterDMA,
|
|
1729
1839
|
FasterDX,
|
|
1730
1840
|
FasterEMA,
|
|
1841
|
+
FasterLinearRegression,
|
|
1731
1842
|
FasterMACD,
|
|
1732
1843
|
FasterMAD,
|
|
1733
1844
|
FasterMOM,
|
|
@@ -1743,6 +1854,7 @@ export {
|
|
|
1743
1854
|
FasterTR,
|
|
1744
1855
|
FasterWMA,
|
|
1745
1856
|
FasterWSMA,
|
|
1857
|
+
LinearRegression,
|
|
1746
1858
|
MACD,
|
|
1747
1859
|
MAD,
|
|
1748
1860
|
MOM,
|
package/package.json
CHANGED
|
@@ -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.2.0"
|
|
108
108
|
}
|