fintech-algorithms

Ljung-Box

Install and import

bash
npm install fintech-algorithms
ts
import { ljungBox } from "fintech-algorithms/statistical-time-series/diagnostics/ljung-box";

Signature

ljungBox(values, lags, modelDf, alpha)

Worked example

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input

values
[0.49366418, 1.1869847, -1.93610944, 1.06953965, 0.16494849, -0.7467157]

Showing 6 of 96 elements.

lags
12
modelDf
0
alpha
0.05

Call

ljungBox(values, lags, modelDf, alpha)

Returns

object with 13 fields: method, variant, nobs, lags, model_df, degrees_of_freedom, terms, statistic, …

{
  "method": "ljung_box",
  "variant": "demeaned-residual-portmanteau",
  "nobs": 96,
  "lags": 12,
  "model_df": 0,
  "degrees_of_freedom": 12,
  "terms": [
    {
      "lag": 1,
      "acf": -0.0475050120854155,
      "term": 0.00002375501234984708
    },
    {
      "lag": 2,
      "acf": -0.01074438668394694,
      "term": 0.0000012281047363210248
    },
    {
      "lag": 3,
      "acf": 0.10423989737175164,
      "term": 0.00011683823875347651
    }
  ],
  "statistic": 11.395763774723312,
  "p_value": 0.49534027421087556,
  "alpha": 0.05,
  "reject_null": false,
  "state": "fail-to-reject-residual-whiteness",
  "reason": "p-value-not-below-alpha"
}

Other exports

This module also exports acf, pacf, adf, kpss, zivotAndrews, runDiagnostic. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams

Ljung-Box — diagnostic anatomy

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References

  • statsmodels.tsa.stattools.acf
  • On a measure of lack of fit in time series models
  • statsmodels.stats.diagnostic.acorr_ljungbox
  • Evidence decisions