garch 1.2.1 → 1.2.2

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/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];
@@ -1804,10 +1805,11 @@ function predict(candles, interval, currentPrice = candles[candles.length - 1].c
1804
1805
  * Uses log-normal price bands: P·exp(±z·σ), where z = probit(confidence).
1805
1806
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
1806
1807
  */
1807
- function predictRange(candles, interval, steps, currentPrice = candles[candles.length - 1].close, confidence = 0.6827) {
1808
+ function predictRange(candles, interval, steps, currentPrice, confidence = 0.6827) {
1808
1809
  assertMinCandles(candles, interval);
1809
1810
  const z = probit(confidence);
1810
1811
  const fit = fitModel(candles, INTERVALS_PER_YEAR[interval], steps);
1812
+ currentPrice = currentPrice || candles[candles.length - 1].close;
1811
1813
  const cumulativeVariance = fit.forecast.variance.reduce((sum, v) => sum + v, 0);
1812
1814
  const sigma = Math.sqrt(cumulativeVariance);
1813
1815
  const upperPrice = currentPrice * Math.exp(z * sigma);
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];
@@ -1802,10 +1803,11 @@ function predict(candles, interval, currentPrice = candles[candles.length - 1].c
1802
1803
  * Uses log-normal price bands: P·exp(±z·σ), where z = probit(confidence).
1803
1804
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
1804
1805
  */
1805
- function predictRange(candles, interval, steps, currentPrice = candles[candles.length - 1].close, confidence = 0.6827) {
1806
+ function predictRange(candles, interval, steps, currentPrice, confidence = 0.6827) {
1806
1807
  assertMinCandles(candles, interval);
1807
1808
  const z = probit(confidence);
1808
1809
  const fit = fitModel(candles, INTERVALS_PER_YEAR[interval], steps);
1810
+ currentPrice = currentPrice || candles[candles.length - 1].close;
1809
1811
  const cumulativeVariance = fit.forecast.variance.reduce((sum, v) => sum + v, 0);
1810
1812
  const sigma = Math.sqrt(cumulativeVariance);
1811
1813
  const upperPrice = currentPrice * Math.exp(z * sigma);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "garch",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
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
@@ -514,7 +514,7 @@ interface PredictionResult {
514
514
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
515
515
  * Common values: 0.90 → z=1.645, 0.95 → z=1.96, 0.99 → z=2.576.
516
516
  */
517
- declare function predict(candles: Candle[], interval: CandleInterval, currentPrice?: number, confidence?: number): PredictionResult;
517
+ declare function predict(candles: Candle[], interval: CandleInterval, currentPrice?: number | null, confidence?: number): PredictionResult;
518
518
  /**
519
519
  * Forecast expected price range over multiple candles.
520
520
  *
@@ -522,7 +522,7 @@ declare function predict(candles: Candle[], interval: CandleInterval, currentPri
522
522
  * Uses log-normal price bands: P·exp(±z·σ), where z = probit(confidence).
523
523
  * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ).
524
524
  */
525
- declare function predictRange(candles: Candle[], interval: CandleInterval, steps: number, currentPrice?: number, confidence?: number): PredictionResult;
525
+ declare function predictRange(candles: Candle[], interval: CandleInterval, steps: number, currentPrice?: number | null, confidence?: number): PredictionResult;
526
526
  /**
527
527
  * Walk-forward backtest of predict.
528
528
  *