Ljung–Box Test Calculator
Enter an ordered, equal-frequency residual series, maximum lag, and fitted AR and MA orders to calculate the NIST Ljung–Box Q statistic and its asymptotic chi-square p-value. Every lag contribution stays visible, while model adequacy, residual independence, predictability and trading decisions remain explicitly outside the result.
Enter ordered model residuals
Use residuals from one fitted model and one consistent frequency, oldest to newest. Enter the AR and MA orders represented by that model.
Accumulates autocorrelations from lag 1 through m.
AR order represented by the fitted model that produced the residuals.
MA order represented by the same fitted model.
Oldest to newest. Enter numbers without percent signs; separate with spaces, commas, semicolons or new lines. Maximum 500.
Entered Ljung–Box arithmetic
Entered Return Statistical Diagnostics 1.0.0.
On smaller screens, scroll horizontally to inspect the complete audit table.
| Lag | Pairs | Autocorrelation | Squared autocorrelation | r² ÷ (n − k) | Q contribution |
|---|
How the Ljung–Box reference is calculated
Q = n(n + 2) × Σk=1m[r[k]² ÷ (n − k)]
Reference df = m − p − q
Version 1.0.0 mean-centers the complete entered residual series and uses the NIST autocorrelation denominator over all n residuals. Each lag k contributes its squared sample autocorrelation divided by n minus k.
The entered maximum lag m is reduced by entered fitted AR order p and MA order q for the asymptotic chi-square degrees of freedom. The calculator requires m minus p minus q to remain at least one.
The result is most naturally applied to residuals from a fitted time-series model. Raw returns can be entered arithmetically, but fitted-order adjustments and interpretation must still match the analysis actually performed.
Worked example from the audited fixture
The audited fixture contains 30 ordered residuals, maximum lag 5, fitted AR order 1 and fitted MA order 0.
- The lag 1 through 5 autocorrelations are −0.16096587, −0.43015686, −0.07597121, 0.23346264 and −0.00075898.
- Q = 9.41948577 with 5 − 1 − 0 = 4 reference degrees of freedom; the independently recomputed asymptotic p-value is 0.05142819. The page reports those values without a reject/retain or model-adequacy label.
Reproduce it: select “Load audited example” above. The governed engine retains full precision and rounds only the visible interface.
How to interpret the result
- Q accumulates squared sample autocorrelations, so positive and negative lag coefficients both increase the joint statistic.
- The audit table shows whether one lag or several lags contribute most to Q.
- The p-value is the asymptotic chi-square survival reference for the entered Q and degrees of freedom.
- Changing maximum lag changes both the accumulated terms and the reference degrees of freedom.
- A reference value alone cannot verify residual independence, diagnose model structure or establish an exploitable trading pattern.
Assumptions and limits
- Enter 5 to 500 ordered, equally spaced residuals; the maximum lag is capped at 100 and must leave at least two residual pairs.
- All residuals must use one model, one frequency, one preprocessing rule and one oldest-to-newest order.
- AR and MA orders are user-entered and are not inferred or validated against a fitted model.
- The chi-square p-value is asymptotic and can be unreliable in small samples or under violated assumptions.
- The test does not identify which model term, data issue, volatility process or structural break could explain autocorrelation.
- No pass/fail decision, adequacy grade, independence proof, forecast, signal or recommendation is generated.
Which return diagnostic answers which question?
Distribution shape, one-lag autocorrelation, joint residual autocorrelation and multi-period variance are related but not interchangeable. The comparison below preserves each tool’s evidence requirement and prevents one statistic from being presented as a universal strategy test.
| Diagnostic | Evidence entered | Question answered | Main boundary |
|---|---|---|---|
| Return Distribution Analyzer | Entered return series | Location, spread, percentiles, skewness and raw kurtosis | Descriptive moments only. |
| Jarque–Bera | Entered n, skewness and raw kurtosis | Joint normal-reference moment statistic | Small-sample p-value withheld; no normality verdict. |
| Return Autocorrelation | Entered return series plus one lag | One sample autocorrelation coefficient | No joint multi-lag reference. |
| Ljung–Box | Ordered residuals, maximum lag and fitted orders | Joint asymptotic portmanteau reference | No residual-independence or adequacy verdict. |
| Observed Variance Ratio | Entered returns plus horizon q | Overlapping multi-period variance divided by scaled one-period variance | No corrected z test, p-value or random-walk verdict. |
Frequently asked questions
- It jointly accumulates squared sample autocorrelations from lag one through the entered maximum lag using the published n times n plus two weighting.
- Enter ordered, equally spaced residuals from one fitted model and one preprocessing convention, oldest to newest.
- NIST gives the asymptotic reference degrees of freedom as maximum lag minus fitted AR order minus fitted MA order.
- Version 1.0.0 uses the complete-series mean, lagged cross-product numerator and complete-series squared-deviation denominator published by NIST.
- It is the asymptotic chi-square survival reference for the entered Q and degrees of freedom, not the probability that the fitted model is correct.
- The calculator does not choose it. The lag should be declared for the analysis and supported by the sample frequency, sample length and model context.
- The arithmetic can consume them, but fitted-order adjustment and diagnostic interpretation must match the analysis actually performed.
- No. It issues no pass/fail label, independence proof, model-adequacy grade, predictability claim, forecast, signal or recommendation.
Sources and methodology
- NIST — Ljung–Box Test — Published Q formula, residual use and fitted-ARMA degrees-of-freedom adjustment.
- NIST — Autocorrelation — Published sample autocorrelation formula and equal-spacing requirement.
- Ljung and Box — On a Measure of Lack of Fit in Time Series Models — Original Biometrika paper defining the portmanteau statistic.
Version 1.0.0 was locked only after the governing formulas and boundaries were checked in the cited primary or standards sources. Independent fixtures recompute the displayed statistics and reference probabilities separately from the browser adapter.
Compare serial-dependence evidence
Verify the return and residual evidence
Reconcile the exact statement period, sampling frequency, timezone, realized results, spread, commission, financing, conversion and fitted-model preprocessing before deriving inputs. These browser calculations cannot certify that an entered sample is complete, stationary or representative.
Risk and affiliate disclosure: Leveraged forex and CFD trading can result in substantial losses. These are affiliate links, so ForexMT4Indicators.com may receive compensation if you register or trade through them, at no additional cost to you. Availability and terms vary by jurisdiction and broker entity.

