interface Candle { open: number; high: number; low: number; close: number; volume: number; timestamp?: number; } interface GarchParams { omega: number; alpha: number; beta: number; persistence: number; unconditionalVariance: number; annualizedVol: number; df: number; } interface EgarchParams { omega: number; alpha: number; gamma: number; beta: number; persistence: number; unconditionalVariance: number; annualizedVol: number; leverageEffect: number; df: number; } interface GjrGarchParams { omega: number; alpha: number; gamma: number; beta: number; persistence: number; unconditionalVariance: number; annualizedVol: number; leverageEffect: number; df: number; } interface CalibrationResult { params: T; diagnostics: { logLikelihood: number; aic: number; bic: number; iterations: number; converged: boolean; }; } interface VolatilityForecast { variance: number[]; volatility: number[]; annualized: number[]; } interface LeverageStats { negativeVol: number; positiveVol: number; ratio: number; recommendation: 'garch' | 'egarch'; } interface HarRvParams { beta0: number; betaShort: number; betaMedium: number; betaLong: number; persistence: number; unconditionalVariance: number; annualizedVol: number; r2: number; df: number; /** true when the regression runs on ln RV (betas live in log space). */ logSpec?: boolean; /** Residual variance of the log-RV regression (lognormal bias correction). */ residualLogVar?: number; } interface RealizedGarchParams { omega: number; beta: number; gamma: number; /** Measurement-equation intercept: ln RV_t = ξ + ln σ²_t + τ₁z + τ₂(z²−1) + u. */ xi: number; tau1: number; tau2: number; /** Std of the measurement noise u — how much the model trusts RV. */ sigmaU: number; persistence: number; unconditionalVariance: number; annualizedVol: number; df: number; } interface NoVaSParams { weights: number[]; forecastWeights: number[]; lags: number; persistence: number; unconditionalVariance: number; annualizedVol: number; dSquared: number; r2: number; df: number; } interface OptimizerResult { x: number[]; fx: number; /** Iterations of the winning Nelder-Mead run (not summed across multi-start restarts). */ iterations: number; converged: boolean; } interface GarchOptions { periodsPerYear?: number; maxIter?: number; tol?: number; } /** * GARCH(1,1) model * * σ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁ * * where: * - ω (omega) > 0: constant term * - α (alpha) ≥ 0: ARCH parameter (reaction to shocks) * - β (beta) ≥ 0: GARCH parameter (persistence) * - α + β < 1: stationarity condition */ declare class Garch { private returns; private rv; private periodsPerYear; private initialVariance; constructor(data: Candle[] | number[], options?: GarchOptions); /** * Calibrate GARCH(1,1) parameters using Maximum Likelihood Estimation */ fit(options?: { maxIter?: number; tol?: number; forgetting?: number; warmStart?: GarchParams; }): CalibrationResult; /** * Calculate conditional variance series given parameters */ getVarianceSeries(params: GarchParams): number[]; /** * Forecast variance forward */ forecast(params: GarchParams, steps?: number): VolatilityForecast; /** * Get the return series */ getReturns(): number[]; /** * Get initial variance estimate */ getInitialVariance(): number; } /** * Convenience function to calibrate GARCH(1,1) from candles */ declare function calibrateGarch(data: Candle[] | number[], options?: GarchOptions): CalibrationResult; interface EgarchOptions { periodsPerYear?: number; maxIter?: number; tol?: number; } /** * EGARCH(1,1) model (Nelson, 1991) * * ln(σ²ₜ) = ω + α·(|zₜ₋₁| - E[|z|]) + γ·zₜ₋₁ + β·ln(σ²ₜ₋₁) * * where: * - zₜ = εₜ/σₜ (standardized residual) * - ω (omega): constant term * - α (alpha): magnitude effect * - γ (gamma): leverage effect (typically negative) * - β (beta): persistence * - E[|z|] = expectedAbsStudentT(df) for Student-t(df) */ declare class Egarch { private returns; private rv; private periodsPerYear; private initialVariance; constructor(data: Candle[] | number[], options?: EgarchOptions); /** * Calibrate EGARCH(1,1) parameters using Maximum Likelihood Estimation */ fit(options?: { maxIter?: number; tol?: number; forgetting?: number; warmStart?: EgarchParams; }): CalibrationResult; /** * Calculate conditional variance series given parameters */ getVarianceSeries(params: EgarchParams): number[]; /** * Mean drift of the magnitude term under the fitted dynamics. * * With RV magnitude, E[√(RV/σ²)] ≠ E[|z|]: the in-sample recursion * carries a mean offset α·m̄ per step that ω absorbed during fitting. * A multi-step forecast that drops the α term entirely would therefore * converge to a level systematically below the fitted dynamics. * Returns m̄ = mean(magnitude − E|z|) over the sample (0 for prices-only * input, where magnitude = |z| and the offset is sampling noise). */ magnitudeDrift(params: EgarchParams): number; /** * Forecast variance forward * * Note: EGARCH forecasts are more complex because they depend on * the path of shocks. This provides an approximation assuming * expected values of future shocks. */ forecast(params: EgarchParams, steps?: number): VolatilityForecast; /** * Get the return series */ getReturns(): number[]; /** * Get initial variance estimate */ getInitialVariance(): number; } /** * Convenience function to calibrate EGARCH(1,1) from candles */ declare function calibrateEgarch(data: Candle[] | number[], options?: EgarchOptions): CalibrationResult; interface HarRvOptions { periodsPerYear?: number; shortLag?: number; mediumLag?: number; longLag?: number; /** * Regress ln RV instead of RV levels (log-HAR, Corsi). Positivity comes * for free (no 1e-20 clamps on negative predictions), residuals are far * closer to homoskedastic, and single RV prints stop dominating the OLS. * Predictions are bias-corrected: E[RV] = exp(ŷ + σ²_ε/2). */ logSpec?: boolean; } /** * HAR-RV model (Corsi, 2009) * * RV_{t+1} = β₀ + β₁·RV_short + β₂·RV_medium + β₃·RV_long + ε * * where: * - RV_short = mean(rv[t-s+1..t]) (default s=1) * - RV_medium = mean(rv[t-m+1..t]) (default m=5) * - RV_long = mean(rv[t-l+1..t]) (default l=22) * - rv[t] = Parkinson(candle_t) for OHLC data, r[t]² for prices-only * * Parkinson (1980): RV = (1/(4·ln2))·(ln(H/L))², ~5x more efficient than r². * * Uses OLS for estimation — closed-form, always converges. */ declare class HarRv { private returns; private rv; private periodsPerYear; private shortLag; private mediumLag; private longLag; private logSpec; private lnRv; constructor(data: Candle[] | number[], options?: HarRvOptions); /** * Calibrate HAR-RV via OLS. */ fit(): CalibrationResult; /** * Internal: compute variance series from beta vector. * For the log spec the prediction is E[RV] = exp(ŷ + σ²_ε/2). */ private getVarianceSeriesInternal; /** * Calculate conditional variance series given parameters. */ getVarianceSeries(params: HarRvParams): number[]; /** * Forecast variance forward. * * Uses iterative substitution: each forecast step feeds back * into the rolling RV components for subsequent steps (point forecasts * of ln RV for the log spec, bias-corrected on output). */ forecast(params: HarRvParams, steps?: number): VolatilityForecast; /** * Get the return series. */ getReturns(): number[]; /** * Get realized variance series (squared returns). */ getRv(): number[]; } /** * Convenience function to calibrate HAR-RV from candles or prices. */ declare function calibrateHarRv(data: Candle[] | number[], options?: HarRvOptions): CalibrationResult; interface GjrGarchOptions { periodsPerYear?: number; maxIter?: number; tol?: number; } /** * GJR-GARCH(1,1) model (Glosten, Jagannathan & Runkle, 1993) * * σ²ₜ = ω + α·ε²ₜ₋₁ + γ·ε²ₜ₋₁·I(rₜ₋₁<0) + β·σ²ₜ₋₁ * * where: * - ω (omega) > 0: constant term * - α (alpha) ≥ 0: symmetric shock response * - γ (gamma) ≥ −α: asymmetric leverage coefficient (negative = inverted leverage) * - β (beta) ≥ 0: persistence * - I(r<0) = 1 when return is negative, 0 otherwise * - Stationarity: α + γ/2 + β < 1 * * With Candle[] input, ε² is replaced by Parkinson per-candle RV. * Leverage direction still comes from close-to-close return sign. */ declare class GjrGarch { private returns; private rv; private periodsPerYear; private initialVariance; constructor(data: Candle[] | number[], options?: GjrGarchOptions); /** * Calibrate GJR-GARCH(1,1) parameters using Maximum Likelihood Estimation */ fit(options?: { maxIter?: number; tol?: number; forgetting?: number; warmStart?: GjrGarchParams; }): CalibrationResult; /** * Calculate conditional variance series given parameters */ getVarianceSeries(params: GjrGarchParams): number[]; /** * Forecast variance forward */ forecast(params: GjrGarchParams, steps?: number): VolatilityForecast; /** * Get the return series */ getReturns(): number[]; /** * Get initial variance estimate */ getInitialVariance(): number; } /** * Convenience function to calibrate GJR-GARCH(1,1) from candles */ declare function calibrateGjrGarch(data: Candle[] | number[], options?: GjrGarchOptions): CalibrationResult; interface RealizedGarchOptions { periodsPerYear?: number; maxIter?: number; tol?: number; } /** * Realized GARCH(1,1) (Hansen, Huang & Shek, 2012), log-linear, φ = 1. * * r_t = σ_t·z_t, z_t ~ standardized t(df) * ln σ²_t = ω + β·ln σ²_{t−1} + γ·ln RV_{t−1} * ln RV_t = ξ + ln σ²_t + τ₁·z_t + τ₂·(z²_t − 1) + u_t, u_t ~ N(0, σ²_u) * * Unlike the RV-in-place-of-ε² hybrids, the measurement equation estimates * the bias (ξ) and noise (σ_u) of the realized measure inside the joint * likelihood: RV information is weighted by how trustworthy it actually is, * and leverage enters through τ₁. Stationarity: β + γ < 1 (with φ = 1). */ declare class RealizedGarch { private returns; private lnRv; private periodsPerYear; private initialVariance; constructor(data: Candle[] | number[], options?: RealizedGarchOptions); /** * Calibrate by joint MLE over returns and the realized measure. */ fit(options?: { maxIter?: number; tol?: number; forgetting?: number; warmStart?: RealizedGarchParams; }): CalibrationResult; /** * Conditional variance series (data scale). σ²_t is driven by RV_{t−1} * through the log recursion — no look-ahead. */ getVarianceSeries(params: RealizedGarchParams): number[]; /** * Forecast variance forward. One step uses the actual last RV; further * steps substitute E[ln RV_t] = ξ + ln σ²_t, giving the reduced recursion * ln σ²_{t+h} = (ω + γξ) + (β + γ)·ln σ²_{t+h−1}. */ forecast(params: RealizedGarchParams, steps?: number): VolatilityForecast; /** * Get the return series. */ getReturns(): number[]; /** * Get initial variance estimate. */ getInitialVariance(): number; } /** * Convenience function to calibrate Realized GARCH from candles or prices. */ declare function calibrateRealizedGarch(data: Candle[] | number[], options?: RealizedGarchOptions): CalibrationResult; interface NoVaSOptions { periodsPerYear?: number; lags?: number; maxIter?: number; tol?: number; } /** * NoVaS (Normalizing and Variance-Stabilizing) model (Politis, 2003) * * Two-stage calibration: * * Stage 1 — D² minimization (model-free normality): * σ²_t = a_0 + a_1·X²_{t-1} + a_2·X²_{t-2} + ... + a_p·X²_{t-p} * W_t = X_t / σ_t * Minimize D² = S² + (K - 3)² where S, K are skewness and kurtosis of {W_t}. * * Stage 2 — OLS rescaling (forecast-optimal): * RV_{t+1} = β₀ + β₁·σ²_t(D²) * The D²-discovered σ²_t acts as a data-driven smoother over RV lags. * OLS rescales it to minimize forecast error (RSS on RV). * Only 2 parameters → robust on small samples with noisy per-candle RV. * * D² discovers lag structure (model-free). OLS rescales for prediction accuracy. * Both weight sets are stored in params — no identity loss. */ declare class NoVaS { private returns; private rv; private periodsPerYear; private lags; constructor(data: Candle[] | number[], options?: NoVaSOptions); /** * Calibrate NoVaS weights via two-stage procedure: * Stage 1: D² minimization (normality of W_t) * Stage 2: OLS rescaling of D²-variance (forecast-optimal) */ fit(options?: { maxIter?: number; tol?: number; warmWeights?: number[]; }): CalibrationResult; /** * Internal: compute variance series from D² weight vector. */ private getVarianceSeriesInternal; /** * Calculate conditional variance series using D² weights (normalization identity). */ getVarianceSeries(params: NoVaSParams): number[]; /** * Calculate forecast variance series using OLS-rescaled D² variance. * forecast_σ²_t = β₀ + β₁·σ²_t(D²) * Used for QLIKE model comparison — measures forecast quality. */ getForecastVarianceSeries(params: NoVaSParams): number[]; /** * Forecast variance forward using OLS-rescaled D² weights. * * Step 1: compute D²-based σ²_{t+h} using D² weights * Step 2: rescale via β₀ + β₁·σ²_{t+h} */ forecast(params: NoVaSParams, steps?: number): VolatilityForecast; /** * Get the return series. */ getReturns(): number[]; } /** * Convenience function to calibrate NoVaS from candles or prices. */ declare function calibrateNoVaS(data: Candle[] | number[], options?: NoVaSOptions): CalibrationResult; /** * Validate OHLC integrity. Garbage candles (NaN, non-positive prices, * high < low) otherwise propagate silently as NaN through every estimator. */ declare function validateCandles(candles: Candle[]): void; /** * Linear-interpolation quantile of a pre-sorted (ascending) sample. */ declare function empiricalQuantile(sortedAsc: number[], p: number): number; /** * Calculate log returns from candles */ declare function calculateReturns(candles: Candle[]): number[]; /** * Calculate log returns from price array */ declare function calculateReturnsFromPrices(prices: number[]): number[]; /** * Calculate sample variance (mean-zero assumption) */ declare function sampleVariance(returns: number[]): number; /** * Calculate sample variance with mean adjustment */ declare function sampleVarianceWithMean(returns: number[]): number; /** * Check for leverage effect (asymmetry in volatility) */ declare function checkLeverageEffect(returns: number[]): LeverageStats; /** * Garman-Klass (1980) variance estimator using OHLC data. * * σ²_GK = (1/n) Σ [ 0.5·(ln(H/L))² − (2ln2−1)·(ln(C/O))² ] * * ~5x more efficient than close-to-close variance. */ declare function garmanKlassVariance(candles: Candle[]): number; /** * Yang-Zhang (2000) variance estimator using OHLC data. * * Combines overnight (open vs prev close), open-to-close, * and Rogers-Satchell components. More efficient than Garman-Klass * and handles overnight gaps (relevant for stocks). * * σ²_YZ = σ²_overnight + k·σ²_close + (1−k)·σ²_RS */ declare function yangZhangVariance(candles: Candle[]): number; /** * Per-candle Parkinson (1980) realized variance proxy. * * RV_i = (1/(4·ln2)) · ln(H/L)² * * ~5× more efficient than squared returns. Falls back to r² when H === L. * rv[i] aligned with returns[i], using candles[i+1]'s OHLC. */ declare function perCandleParkinson(candles: Candle[], returns: number[]): number[]; /** * Expected value of |Z| where Z ~ N(0,1) * E[|Z|] = sqrt(2/π) */ declare const EXPECTED_ABS_NORMAL: number; /** * Ljung-Box test for autocorrelation. * * Q = n(n+2) Σ(k=1..m) ρ²_k / (n−k) * * Under H₀ (no autocorrelation), Q ~ χ²(m). * Use on squared standardized residuals to test GARCH adequacy. */ declare function ljungBox(data: number[], maxLag: number): { statistic: number; pValue: number; }; /** * Log-Gamma function via Lanczos approximation (g=7, n=9). * Accurate to ~15 digits for x > 0. */ declare function logGamma(x: number): number; /** * Per-observation Student-t negative log-likelihood contribution. * * For standardized t(df) with variance σ²_t: * -LL_i = 0.5·ln(σ²_t) + ((df+1)/2)·ln(1 + r²_t / ((df-2)·σ²_t)) * - lnΓ((df+1)/2) + lnΓ(df/2) + 0.5·ln(π·(df-2)) * * Returns the per-observation neg-LL (without the constant terms). * Caller accumulates and adds the constant once. */ declare function studentTNegLL(returns: number[], varianceSeries: number[], df: number): number; /** * E[|Z|] where Z follows a standardized Student-t(df) distribution (variance = 1). * * E[|Z|] = √((df-2)/π) · Γ((df-1)/2) / Γ(df/2) * * Converges to √(2/π) as df → ∞ (Gaussian limit). */ declare function expectedAbsStudentT(df: number): number; /** * Regularized incomplete beta function I_x(a, b). */ declare function incompleteBeta(x: number, a: number, b: number): number; /** * CDF of the (raw, unstandardized) Student-t distribution with df degrees * of freedom: P(T ≤ t). */ declare function studentTCdf(t: number, df: number): number; /** * Two-sided quantile of the STANDARDIZED Student-t distribution * (unit variance). The t-analog of probit(): returns z such that * P(|Z| ≤ z) = confidence when Z ~ t(df) scaled to variance 1. * * This is what price corridors must use when the model was fitted with * Student-t innovations: with fat tails (small df) the Gaussian probit * makes 68% bands too wide and 99% bands dangerously narrow. * * Falls back to probit() for df > 1000 (where the difference from the * Gaussian quantile is < 0.3% even at 99%) or df ≤ 2 (variance undefined). */ declare function studentTProbit(confidence: number, df: number): number; /** * 1D grid search for optimal df that minimizes Student-t neg-LL. * Used by HAR-RV and NoVaS where df is profiled after main optimization. */ declare function profileStudentTDf(returns: number[], varianceSeries: number[]): number; /** * QLIKE loss (Patton 2011) — standard loss function for volatility forecasts. * * QLIKE = (1/n) · Σ (RV_t / σ²_t − log(RV_t / σ²_t) − 1) * * Lower = better forecast. Neutral to calibration method — judges only * how well the variance series predicts realized variance, regardless * of how the model was calibrated (MLE, OLS, D², etc.). */ declare function qlike(varianceSeries: number[], rv: number[]): number; /** * Inverse standard normal CDF (probit function). * Converts a two-sided confidence level (e.g. 0.95) to the corresponding * z-score (e.g. 1.96). * * Uses Acklam's rational approximation (max relative error < 1.15e-9). */ declare function probit(confidence: number): number; type CandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '6h' | '8h'; type WarningCode = 'LOW_SAMPLE' | 'NOT_CONVERGED' | 'HIGH_PERSISTENCE' | 'DEGENERATE_VARIANCE' | 'RESIDUAL_AUTOCORRELATION' | 'DATA_GAPS' | 'INTERVAL_MISMATCH'; interface PredictionWarning { code: WarningCode; /** Plain-language explanation with a suggested action. */ message: string; /** true when this warning alone makes the forecast unreliable. */ critical: boolean; } interface PredictionResult { /** Reference price used to compute the corridor (last close or the value passed as `currentPrice`). */ currentPrice: number; /** One-period (or cumulative) volatility estimate, as a decimal log-return standard deviation (e.g. `0.012` = 1.2%). */ sigma: number; /** Upward expected move in price units: `upperPrice - currentPrice`. */ move: number; /** Upward expected move in percent (0–100 scale, e.g. `1.21` means 1.21%). Equal to `(exp(z·σ) - 1) * 100`. */ movePercent: number; /** Upper price band: `currentPrice · exp(+z·σ)`. */ upperPrice: number; /** Lower price band: `currentPrice · exp(-z·σ)`. Always positive. */ lowerPrice: number; /** Top-weight member of the volatility model combination (selected by out-of-sample QLIKE). */ modelType: 'garch' | 'egarch' | 'gjr-garch' | 'realized-garch' | 'har-rv' | 'novas'; /** Student-t degrees of freedom profiled on scale-corrected residuals. */ df: number; /** * Average corridor multiplier, (zScoreUp + zScoreDown) / 2 — kept for * backward compatibility. The bands themselves are asymmetric; use * zScoreUp/zScoreDown to reconstruct them exactly. */ zScore: number; /** Upper-tail multiplier: `upperPrice = currentPrice · exp(+zScoreUp · sigma)`. */ zScoreUp: number; /** Lower-tail multiplier: `lowerPrice = currentPrice · exp(−zScoreDown · sigma)`. */ zScoreDown: number; /** `true` when no critical warning fired (model converged, persistence < 0.999, Ljung-Box p ≥ 0.05, non-degenerate variance). */ reliable: boolean; /** * Everything the pipeline noticed, in plain language: why `reliable` is * false (critical warnings) plus non-critical data quality notes. */ warnings: PredictionWarning[]; /** Combination weights per model family (out-of-sample QLIKE softmax), summing to 1. */ modelWeights: Partial>; /** `true` when a significant diurnal volatility profile was detected and removed before fitting. */ seasonalityDetected: boolean; } interface PredictOptions { /** Reference price for the corridor; defaults to the last close. */ currentPrice?: number | null; /** Two-sided probability in (0,1). Default ≈0.6827 (±1σ). */ confidence?: number; } interface DataIssue { code: 'TOO_FEW_CANDLES' | 'INVALID_OHLC' | 'UNSORTED' | 'DUPLICATE_TIMESTAMPS' | 'LOW_SAMPLE' | 'DATA_GAPS' | 'INTERVAL_MISMATCH' | 'FLAT_CANDLES'; message: string; severity: 'error' | 'warning'; } interface DataReport { /** false when any error-severity issue is present (predict would throw). */ ok: boolean; issues: DataIssue[]; recommendedCandles: number; } /** * Pre-flight data check with plain-language, actionable messages: run it on * a new data source before wiring it into predict. Errors are conditions * predict would throw on; warnings degrade quality but do not block. */ declare function checkData(candles: Candle[], interval: CandleInterval): DataReport; interface Seasonality { /** Variance factor per intraday bucket, sample-weighted mean 1. */ factors: number[]; /** Bucket of return index t (i.e. candle t+1); also valid for future t. */ bucketOfReturn: (t: number) => number; } /** * Diurnal variance profile from per-candle Parkinson RV. * * Intraday markets have a strong time-of-day volatility pattern (sessions, * funding, weekends). A GARCH-family fit smears it into average persistence, * so corridors are systematically too narrow in active hours and too wide in * quiet ones. Factors are estimated per intraday bucket (≤24 per day, bars * grouped for sub-hour intervals), circularly smoothed, shrunk toward 1 by * bucket support, and gated by a χ² significance test against the RV * sampling noise (inflated for volatility clustering) — pure-GARCH data * without seasonality returns null and the pipeline is unchanged. * * Timestamps (ms or s), when present on every candle, anchor buckets to * real time of day and survive gaps; otherwise buckets are positional and * assume contiguous bars. */ declare function computeSeasonality(candles: Candle[], interval: CandleInterval): Seasonality | null; /** * Rescale each candle's log-moves by 1/√f(bucket) so the deseasonalized * series has a flat diurnal profile. Gaps (open vs prev close) are scaled * with the same factor; OHLC ordering is preserved (monotone log map). */ declare function deseasonalizeCandles(candles: Candle[], season: Seasonality): Candle[]; /** * Cached calibration state threaded between rolling refits: previous * optima become warm starts with a reduced multi-start budget, and the * HAR spec search collapses to the previously selected configuration. */ interface WarmState { garch?: GarchParams; garchForget?: GarchParams; egarch?: EgarchParams; gjr?: GjrGarchParams; rgarch?: RealizedGarchParams; harLags?: [number, number, number]; harLog?: boolean; novasWeights?: number[]; } /** * Stateful predictor for rolling use (bots, backtests): each subsequent * predict/predictRange warm-starts every optimizer from the previous * window's optimum with a reduced multi-start budget — same math, a * fraction of the cost. State is per-instrument: do not share one * predictor across symbols. */ declare function createPredictor(interval: CandleInterval): { predict: (candles: Candle[], currentPriceOrOptions?: number | null | PredictOptions, confidence?: number) => PredictionResult; predictRange: (candles: Candle[], steps: number, currentPriceOrOptions?: number | null | PredictOptions, confidence?: number) => PredictionResult; }; /** * Forecast expected price range for t+1 (next candle). * * Combines all volatility models weighted by out-of-sample QLIKE, * deseasonalizes the diurnal variance profile when one is present, * rescales the variance to the return scale (Var(r/σ) = 1), and builds * bands P·exp(±z·σ) where z is calibrated on the data itself: the * empirical |z| quantile of the standardized residuals blended with the * fitted Student-t quantile as the tail runs out of observations (see * corridorZ). Empirical coverage tracks the requested confidence without * assuming a distributional shape. * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ). * Common values: 0.90, 0.95, 0.99. */ declare function predict(candles: Candle[], interval: CandleInterval, currentPriceOrOptions?: number | null | PredictOptions, confidence?: number): PredictionResult; /** * Forecast expected price range over multiple candles. * * Cumulative σ = √(σ₁² + σ₂² + ... + σₙ²) — total expected move over N * periods, with each step's variance carrying its own seasonal factor. * Uses log-normal price bands P·exp(±z·σ) where z is calibrated at the * requested horizon: the empirical quantile of |h-step standardized sums| * from the sample itself, blended with the model-implied quantile simulated * through the fitted recursions (volatility feedback and fat-tail decay * included). * @param confidence — two-sided probability in (0,1). Default ≈0.6827 (±1σ). * @param steps — horizon in candles, 1 ≤ steps ≤ candles.length. */ declare function predictRange(candles: Candle[], interval: CandleInterval, steps: number, currentPriceOrOptions?: number | null | PredictOptions, confidence?: number): PredictionResult; interface BacktestStats { /** Number of test candles whose close landed inside the predicted corridor. */ hits: number; /** Number of walk-forward predictions made. */ total: number; /** Empirical coverage in percent (0–100). Compare against `confidence · 100`. */ hitRate: number; /** Statistical judgment of the coverage against the nominal confidence (Kupiec POF test). */ verdict: 'well-calibrated' | 'too-narrow' | 'too-wide' | 'inconclusive'; /** Kupiec test p-value: probability of a coverage gap this large under correct calibration. */ pValue: number; /** Plain-language interpretation of the verdict with the numbers filled in. */ message: string; } /** * Kupiec (1995) proportion-of-failures test: is the observed hit rate * statistically consistent with the nominal confidence, given how many * walk-forward points there are? A raw hitRate of 63% vs nominal 68% means * nothing without n — this answers "failure or noise" directly. */ declare function kupiecTest(hits: number, total: number, confidence: number): Pick; /** * Walk-forward calibration statistics for predict. * * Refits the model on a rolling window (75% of candles, min MIN_CANDLES) * and checks whether the next close lands inside the predicted corridor. * A well-calibrated tool has hitRate ≈ confidence·100. * * Every refit costs a full multi-model calibration, so by default the test * points are subsampled to at most ~100 refits (stride grows with the test * span). Pass `stride: 1` to evaluate every candle when runtime is not a * concern, or any positive stride to control the trade-off yourself. * Throws if not enough candles for the given interval. * @param confidence — two-sided probability in (0,1) for the prediction band. * Default ≈0.6827 (±1σ). */ declare function backtestStats(candles: Candle[], interval: CandleInterval, confidence?: number, options?: { stride?: number; }): BacktestStats; /** * Walk-forward backtest of predict. * * Window is computed automatically: 75% of candles for fitting, 25% for testing. * Throws if not enough candles for the given interval. * Returns true if the model's hit rate meets the required threshold. * @param confidence — two-sided probability in (0,1) for the prediction band. * Default ≈0.6827 (±1σ). * @param requiredPercent — minimum hit rate (0–100) to pass. Default 68. */ declare function backtest(candles: Candle[], interval: CandleInterval, confidence?: number, requiredPercent?: number): boolean; /** * Typed error hierarchy so bot code can branch on error class instead of * parsing message strings. * * try { predict(candles, '1h') } * catch (e) { * if (e instanceof NotEnoughDataError) await fetchMoreCandles(); * else if (e instanceof BadDataError) alertDataPipeline(e.message); * else throw e; * } */ declare class GarchError extends Error { constructor(message: string); } /** The sample is too short for the requested interval/model. Fetch more candles. */ declare class NotEnoughDataError extends GarchError { } /** The candles themselves are broken: invalid OHLC, unsorted or duplicated timestamps. Fix the data pipeline. */ declare class BadDataError extends GarchError { } /** A call argument is out of range or of the wrong shape (interval, confidence, steps, currentPrice). Fix the call site. */ declare class InvalidArgumentError extends GarchError { } declare function nelderMead(fn: (x: number[]) => number, x0: number[], options?: { maxIter?: number; tol?: number; alpha?: number; gamma?: number; rho?: number; sigma?: number; }): OptimizerResult; declare function nelderMeadMultiStart(fn: (x: number[]) => number, x0: number[], options?: { maxIter?: number; tol?: number; restarts?: number; /** * Additional explicit starting points, each run through a full NM pass. * The perturbation restarts below scale x0 multiplicatively, so they * preserve its shape — basins whose shape differs from x0 (e.g. far-lag * weight structures) are unreachable from x0 alone and must be seeded * explicitly. */ extraStarts?: number[][]; }): OptimizerResult; export { BadDataError, EXPECTED_ABS_NORMAL, Egarch, Garch, GarchError, GjrGarch, HarRv, InvalidArgumentError, NoVaS, NotEnoughDataError, RealizedGarch, backtest, backtestStats, calculateReturns, calculateReturnsFromPrices, calibrateEgarch, calibrateGarch, calibrateGjrGarch, calibrateHarRv, calibrateNoVaS, calibrateRealizedGarch, checkData, checkLeverageEffect, computeSeasonality, createPredictor, deseasonalizeCandles, empiricalQuantile, expectedAbsStudentT, garmanKlassVariance, incompleteBeta, kupiecTest, ljungBox, logGamma, nelderMead, nelderMeadMultiStart, perCandleParkinson, predict, predictRange, probit, profileStudentTDf, qlike, sampleVariance, sampleVarianceWithMean, studentTCdf, studentTNegLL, studentTProbit, validateCandles, yangZhangVariance }; export type { BacktestStats, CalibrationResult, Candle, CandleInterval, DataIssue, DataReport, EgarchOptions, EgarchParams, GarchOptions, GarchParams, GjrGarchOptions, GjrGarchParams, HarRvOptions, HarRvParams, LeverageStats, NoVaSOptions, NoVaSParams, OptimizerResult, PredictOptions, PredictionResult, PredictionWarning, RealizedGarchOptions, RealizedGarchParams, Seasonality, VolatilityForecast, WarmState, WarningCode };