garch 1.2.1 → 1.2.3

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 CHANGED
@@ -33,7 +33,8 @@ const result = predict(candles, '4h');
33
33
  // {
34
34
  // currentPrice: 97500,
35
35
  // sigma: 0.012, // 1.2% per-period volatility
36
- // move: 1177, // upward expected move (upper - current)
36
+ // move: 1177, // upward expected move (upper - current), in dollars
37
+ // movePercent: 1.21, // upward expected move, in percent (0–100)
37
38
  // upperPrice: 98677, // P·exp(+σ) — ceiling
38
39
  // lowerPrice: 96337, // P·exp(-σ) — floor
39
40
  // modelType: 'egarch',
@@ -87,7 +88,8 @@ Higher confidence = wider corridor. `sigma` stays the same (it's the model's vol
87
88
  interface PredictionResult {
88
89
  currentPrice: number; // Reference price
89
90
  sigma: number; // One-period volatility (decimal, e.g. 0.012 = 1.2%)
90
- move: number; // Upward price move = upperPrice - currentPrice
91
+ move: number; // Upward price move = upperPrice - currentPrice (dollars)
92
+ movePercent: number; // Upward price move in percent (0–100), e.g. 1.21 = 1.21%
91
93
  upperPrice: number; // P · exp(+z·σ)
92
94
  lowerPrice: number; // P · exp(-z·σ)
93
95
  modelType: 'garch' | 'egarch' | 'gjr-garch' | 'har-rv' | 'novas'; // Auto-selected model
@@ -108,7 +110,8 @@ const range = predictRange(candles, '4h', 5);
108
110
  // {
109
111
  // currentPrice: 97500,
110
112
  // sigma: 0.027, // cumulative ~2.7% over 5 candles
111
- // move: 2669, // upward expected move
113
+ // move: 2669, // upward expected move, in dollars
114
+ // movePercent: 2.74, // upward expected move, in percent (0–100)
112
115
  // upperPrice: 100169, // P·exp(+z·σ)
113
116
  // lowerPrice: 94901, // P·exp(-z·σ)
114
117
  // modelType: 'egarch',
package/build/index.cjs CHANGED
@@ -1780,8 +1780,9 @@ function checkReliable(fit) {
1780
1780
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
1781
1781
  * Common values: 0.90 → z=1.645, 0.95 → z=1.96, 0.99 → z=2.576.
1782
1782
  */
1783
- function predict(candles, interval, currentPrice = candles[candles.length - 1].close, confidence = 0.6827) {
1783
+ function predict(candles, interval, currentPrice, confidence = 0.6827) {
1784
1784
  assertMinCandles(candles, interval);
1785
+ currentPrice = currentPrice || candles[candles.length - 1].close;
1785
1786
  const z = probit(confidence);
1786
1787
  const fit = fitModel(candles, INTERVALS_PER_YEAR[interval], 1);
1787
1788
  const sigma = fit.forecast.volatility[0];
@@ -1792,6 +1793,7 @@ function predict(candles, interval, currentPrice = candles[candles.length - 1].c
1792
1793
  currentPrice,
1793
1794
  sigma,
1794
1795
  move: upperPrice - currentPrice,
1796
+ movePercent: (upperPrice / currentPrice - 1) * 100,
1795
1797
  upperPrice,
1796
1798
  lowerPrice,
1797
1799
  reliable: checkReliable(fit),
@@ -1804,10 +1806,11 @@ function predict(candles, interval, currentPrice = candles[candles.length - 1].c
1804
1806
  * Uses log-normal price bands: P·exp(±z·σ), where z = probit(confidence).
1805
1807
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
1806
1808
  */
1807
- function predictRange(candles, interval, steps, currentPrice = candles[candles.length - 1].close, confidence = 0.6827) {
1809
+ function predictRange(candles, interval, steps, currentPrice, confidence = 0.6827) {
1808
1810
  assertMinCandles(candles, interval);
1809
1811
  const z = probit(confidence);
1810
1812
  const fit = fitModel(candles, INTERVALS_PER_YEAR[interval], steps);
1813
+ currentPrice = currentPrice || candles[candles.length - 1].close;
1811
1814
  const cumulativeVariance = fit.forecast.variance.reduce((sum, v) => sum + v, 0);
1812
1815
  const sigma = Math.sqrt(cumulativeVariance);
1813
1816
  const upperPrice = currentPrice * Math.exp(z * sigma);
@@ -1817,6 +1820,7 @@ function predictRange(candles, interval, steps, currentPrice = candles[candles.l
1817
1820
  currentPrice,
1818
1821
  sigma,
1819
1822
  move: upperPrice - currentPrice,
1823
+ movePercent: (upperPrice / currentPrice - 1) * 100,
1820
1824
  upperPrice,
1821
1825
  lowerPrice,
1822
1826
  reliable: checkReliable(fit),
package/build/index.mjs CHANGED
@@ -1778,8 +1778,9 @@ function checkReliable(fit) {
1778
1778
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
1779
1779
  * Common values: 0.90 → z=1.645, 0.95 → z=1.96, 0.99 → z=2.576.
1780
1780
  */
1781
- function predict(candles, interval, currentPrice = candles[candles.length - 1].close, confidence = 0.6827) {
1781
+ function predict(candles, interval, currentPrice, confidence = 0.6827) {
1782
1782
  assertMinCandles(candles, interval);
1783
+ currentPrice = currentPrice || candles[candles.length - 1].close;
1783
1784
  const z = probit(confidence);
1784
1785
  const fit = fitModel(candles, INTERVALS_PER_YEAR[interval], 1);
1785
1786
  const sigma = fit.forecast.volatility[0];
@@ -1790,6 +1791,7 @@ function predict(candles, interval, currentPrice = candles[candles.length - 1].c
1790
1791
  currentPrice,
1791
1792
  sigma,
1792
1793
  move: upperPrice - currentPrice,
1794
+ movePercent: (upperPrice / currentPrice - 1) * 100,
1793
1795
  upperPrice,
1794
1796
  lowerPrice,
1795
1797
  reliable: checkReliable(fit),
@@ -1802,10 +1804,11 @@ function predict(candles, interval, currentPrice = candles[candles.length - 1].c
1802
1804
  * Uses log-normal price bands: P·exp(±z·σ), where z = probit(confidence).
1803
1805
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
1804
1806
  */
1805
- function predictRange(candles, interval, steps, currentPrice = candles[candles.length - 1].close, confidence = 0.6827) {
1807
+ function predictRange(candles, interval, steps, currentPrice, confidence = 0.6827) {
1806
1808
  assertMinCandles(candles, interval);
1807
1809
  const z = probit(confidence);
1808
1810
  const fit = fitModel(candles, INTERVALS_PER_YEAR[interval], steps);
1811
+ currentPrice = currentPrice || candles[candles.length - 1].close;
1809
1812
  const cumulativeVariance = fit.forecast.variance.reduce((sum, v) => sum + v, 0);
1810
1813
  const sigma = Math.sqrt(cumulativeVariance);
1811
1814
  const upperPrice = currentPrice * Math.exp(z * sigma);
@@ -1815,6 +1818,7 @@ function predictRange(candles, interval, steps, currentPrice = candles[candles.l
1815
1818
  currentPrice,
1816
1819
  sigma,
1817
1820
  move: upperPrice - currentPrice,
1821
+ movePercent: (upperPrice / currentPrice - 1) * 100,
1818
1822
  upperPrice,
1819
1823
  lowerPrice,
1820
1824
  reliable: checkReliable(fit),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "garch",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "GARCH and EGARCH volatility models for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./build/index.cjs",
package/types.d.ts CHANGED
@@ -501,6 +501,7 @@ interface PredictionResult {
501
501
  currentPrice: number;
502
502
  sigma: number;
503
503
  move: number;
504
+ movePercent: number;
504
505
  upperPrice: number;
505
506
  lowerPrice: number;
506
507
  modelType: 'garch' | 'egarch' | 'gjr-garch' | 'har-rv' | 'novas';
@@ -514,7 +515,7 @@ interface PredictionResult {
514
515
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
515
516
  * Common values: 0.90 → z=1.645, 0.95 → z=1.96, 0.99 → z=2.576.
516
517
  */
517
- declare function predict(candles: Candle[], interval: CandleInterval, currentPrice?: number, confidence?: number): PredictionResult;
518
+ declare function predict(candles: Candle[], interval: CandleInterval, currentPrice?: number | null, confidence?: number): PredictionResult;
518
519
  /**
519
520
  * Forecast expected price range over multiple candles.
520
521
  *
@@ -522,7 +523,7 @@ declare function predict(candles: Candle[], interval: CandleInterval, currentPri
522
523
  * Uses log-normal price bands: P·exp(±z·σ), where z = probit(confidence).
523
524
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
524
525
  */
525
- declare function predictRange(candles: Candle[], interval: CandleInterval, steps: number, currentPrice?: number, confidence?: number): PredictionResult;
526
+ declare function predictRange(candles: Candle[], interval: CandleInterval, steps: number, currentPrice?: number | null, confidence?: number): PredictionResult;
526
527
  /**
527
528
  * Walk-forward backtest of predict.
528
529
  *