Using the Ljung-Box Test to Diagnose Return and Model Residual Autocorrelation
Summary
The document explains the Ljung-Box portmanteau test, which evaluates whether a time series has autocorrelation across a chosen range of lags. It describes the Q statistic, its chi-square approximation and degrees of freedom, and an MQL5 toolkit that can apply the calculation to price returns, closed-trade results, or residuals loaded from a file. Users can select test horizons and set a degrees-of-freedom adjustment for model residuals.
The article frames the test as a diagnostic for possible unmodeled serial structure, rather than proof of a tradable edge. It cautions that the approximation can be unreliable on small samples, that residual tests may need model-specific degrees-of-freedom adjustments, and that ordinary Ljung-Box testing does not by itself detect volatility clustering. Testing many horizons or series also increases false-positive risk, so the tested horizons and interpretation should be planned in advance.
Key ideas
- The Ljung-Box statistic tests a group of autocorrelations jointly across lags.
- Its p-value uses a chi-square approximation, with degrees of freedom chosen for the series and model being tested.
- The toolkit applies the same diagnostic to price returns, closed trades, or imported model residuals.
- Small samples and lags close to the sample size can make results unreliable.
- Multiple lag tests and volatility dependence require careful interpretation beyond a single p-value.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.