Pearson Goodness-of-Fit Test

Calculate the adjusted Pearson goodness of fit test of Palm (1996) and Vlaar and Palm (1993): whether the standardized residuals of every asset’s GARCH-family model follow the innovation distribution the model assumes.

Each standardized residual is turned into the probability of a value at most as large under the fitted distribution, which is uniform between 0 and 1 when the distribution fits. The probabilities are counted in equally wide bins and the counts compared with the equal number every bin should hold. Daily returns have fatter tails than a GARCH model with normal innovations allows, so the test usually rejects the normal distribution; a Student-t or skewed Student-t fits better when its p-value is larger.

The formula is as follows:

  • \(z_{t}\) the standardized residuals of the GARCH-family method (GARCH(1, 1) by default) with the distribution and mean model fitted to the returns of period, see toolkit.risk.get_garch
\[u_{t} = F(z_{t}),\;\; \text{with } F \text{ the distribution function of the fitted standardized innovation distribution (with its fitted Shape and Skew)}\] \[n_{i} = \text{the number of}\; u_{t} \;\text{in} \;\left[\frac{i - 1}{g},\; \frac{i}{\text{g)}} \;\text{for}\; i = 1 \ldots g\right],\;\; \text{with}\;\; g = \text{bins} \;(20 \;\text{by default})\] \[\text{Pearson Statistic} = \frac{\sum_{i=1}^{g}\left(n_{i} - \frac{n}{g}\right)^{2}}{\frac{n}{g}},\;\; \text{chi-squared with}\; g - 1 \;\text{degrees of freedom}\]

Also known as: adjusted Pearson goodness of fit test, chi-squared goodness of fit test, probability integral transform test, GARCH distribution test, GARCH residual diagnostics.

Example · ^GSPC, GLD · 2016 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_pearson_goodness_of_fit_test:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["^GSPC", "GLD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2016-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_pearson_goodness_of_fit_test(distribution="t")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

Did a GARCH model with Student-t errors fit the distribution of the daily returns of the S&P 500 and SPDR Gold Shares (GLD) from 2016 to 2025, according to Pearson's goodness-of-fit test?

Which returns:

Using Your Own Data

get_pearson_goodness_of_fit_test runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_pearson_goodness_of_fit_test()

Parameters

get_pearson_goodness_of_fit_test accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
binsintThe number of equally wide bins of the probabilities. Defaults to 20.20
methodstrThe GARCH-family model fitted to the returns, as in toolkit.risk.get_garch. Options are: “garch” (GARCH(1, 1)), “gjr” (GJR-GARCH(1, 1, 1)), “egarch” (EGARCH(1, 1)), “igarch” (IGARCH(1, 1)), “aparch” (APARCH(1, 1)), “tgarch” (TGARCH), “ngarch” (NGARCH), “avgarch” (AVGARCH), “nagarch” (NAGARCH), “component” (component GARCH), “figarch” (FIGARCH(1, d, 1)). Defaults to “garch”."garch"
distributionstrThe innovation distribution of the model and of the test. Options are: “normal” (normal), “t” (Student-t), “skewt” (skewed Student-t of Hansen), “skewt_fernandez_steel” (skewed Student-t of Fernández and Steel), “ged” (generalized error distribution), “johnson_su” (Johnson SU). Defaults to “normal”."studentt"
meanstrThe mean model. Options are: “zero” (the returns themselves are the shocks), “constant” (constant mean), “arma” (ARMA(1, 1)), “in_mean” (GARCH-in-mean). Defaults to “zero”."zero"
include_benchmarkboolWhether to include “Benchmark” among the assets tested. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Palm, F.C. (1996). “GARCH Models of Volatility.” In Handbook of Statistics, Vol. 14, Elsevier, 209-240.
  • Paper Vlaar, P.J.G. and Palm, F.C. (1993). “The Message in Weekly Exchange Rates in the European Monetary System: Mean Reversion, Conditional Heteroscedasticity, and Jumps.” Journal of Business & Economic Statistics, 11(3), 351-360.
  • Library Referenced against rugarch (R)’s gof
Share