Hong-Li Test

Calculate the nonparametric density forecast test of Hong and Li: whether the one-period-ahead forecast densities of a return model have the right shape and capture the dependence of the returns.

Correct density forecasts turn the realized returns into probability integral transforms (PITs) that are independent and uniform on (0, 1), so every pair of a PIT and the PIT j periods before it is spread evenly over the unit square. The test estimates the joint density of those pairs with a kernel and measures how far it is from flat, for every lag: a forecast density of the wrong shape (too thin tails, a missed skew) and dependence the model misses (volatility clustering it does not follow) both move it away. Where get_berkowitz_test checks the mean, variance and first autocorrelation of the normal quantiles of the PITs, this test looks at the whole joint density.

The formula is as follows (with the default GARCH model and daily returns, for which the window is 504):

\[\text{PIT}_{t} = F\left(\frac{\text{Return}_{t} - \text{Mu}}{\text{Volatility}_{t}}\right),\;\; \text{from a GARCH(1, 1) with normal innovations fitted on the 504 returns before } t \text{, refitted every 21 returns (see get\_berkowitz\_test)}\] \[g_{j}(x_{1},\; x_{2}) = \frac{\Sigma_{t} K_{h}(x_{1},\; \text{PIT}_{t}) K_{h}(x_{2},\; \text{PIT}_{t-j})}{n - j},\;\; \text{with}\;\; K_{h} \;\text{the boundary-modified quartic kernel and}\; h = S n^{- \frac{1}{6}},\;\; S \text{ the standard deviation of the PITs}\] \[M(j) = \text{∫∫} \;(g_{j}(x_{1},\; x_{2}) - 1)^{2} \,\mathrm{d}x_{1} \,\mathrm{d}x_{2} \;\text{over the unit square}\] \[Q(j) = \frac{h ((n - j) M(j) - A_{h})}{\sqrt{V}} \;\text{}_{0} \;\text{for}\; j = 1,\; \ldots,\; \text{lags}\] \[W = \frac{\Sigma_{j} Q(j)}{\text{√} \;\text{lags}},\;\; \text{the portmanteau statistic}\]

Where \(A_{h}\) and \(V_{0}\) are the centring and scaling constants of Hong and Li (2005), see forecast_evaluation_model.get_hong_li_test. Only large values reject. The statistics are standard normal under the null only as the sample grows, and slowly, so the p-values come from their distribution simulated under the null (independent uniform PITs) for the same number of PITs and lags, see forecast_evaluation_model.get_hong_li_p_value. The Gaussian and EWMA models give the density forecasts of get_berkowitz_test.

Also known as: Hong-Li test, nonparametric density forecast test, PIT independence and uniformity test, HL portmanteau test.

Example · QQQ, TLT, GLD · 2019 to 2025

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

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["QQQ", "TLT", "GLD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2019-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_hong_li_test()

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

Did the one-day-ahead return densities of a GARCH model have the right shape and dependence for the Invesco QQQ Trust, the iShares 20+ Year Treasury Bond ETF (TLT) and SPDR Gold Shares (GLD) from 2019 to 2025, according to the Hong-Li test?

Which returns:

Using Your Own Data

get_hong_li_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_hong_li_test()

Parameters

get_hong_li_test accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”."weekly"
modelstrThe density forecast. Options are: “garch” (GARCH-family model), “gaussian” (rolling normal), “ewma” (RiskMetrics EWMA). Defaults to “garch”."garch"
lagsintThe number of lags of the portmanteau statistic. Defaults to 4.2
windowint | NoneThe number of returns of every window or GARCH fit, at least 100 for the GARCH model (a GARCH fit needs at least 100 returns) and 2 otherwise. Defaults to None, which uses two years of observations with a minimum of 100 for “garch” (504 daily returns) and a year with a minimum of 20 for “gaussian”.20
lambda_floatThe decay factor of model=”ewma”. Defaults to 0.94.0.97
refit_everyintThe number of returns between two GARCH fits. Defaults to 21.21
garch_methodstrThe GARCH variance model. 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"
garch_distributionstrThe GARCH innovation distribution. 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”."normal"
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 Hong, Y. and Li, H. (2005). “Nonparametric Specification Testing for Continuous-Time Models with Applications to Term Structure of Interest Rates.” The Review of Financial Studies, 18(1), 37-84.
  • Paper Diebold, F.X., Gunther, T.A. and Tay, A.S. (1998). “Evaluating Density Forecasts with Applications to Financial Risk Management.” International Economic Review, 39(4), 863-883.
  • Library Shares similar logic as rugarch (R)’s HLTest
Share