Berkowitz Test

Calculate Berkowitz’s likelihood ratio test of the one-period-ahead density forecasts of a return model: whether the forecast distributions match the returns in mean, variance and independence.

A Value at Risk backtest only looks at one quantile; a density forecast says how likely every return is. The test transforms each realized return with the distribution function of its forecast (the probability integral transform, PIT), which is uniform and independent over time when the forecasts are right, takes the normal quantile of the PITs and tests whether those are independent standard normal: a mean away from 0 means the forecasts are biased, a standard deviation above 1 that they understate the risk and an autocorrelation that they miss its dynamics. With a tail probability, only the tail below that quantile is tested, the part a Value at Risk at that level depends on.

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}\] \[z_{t} = \Phi^{-1} (\text{PIT}_{t})\;\;\text{and}\;\; z_{t} - \mu = \rho (z_{t-1} - \mu) + \epsilon_{t},\;\; \text{with}\; \epsilon_{t} \sim N(0,\; \sigma^{2})\] \[\text{Berkowitz Statistic} = - 2 (\ln L(0,\; 1,\; 0) - \ln L(\hat{\mu},\; \hat{\sigma},\; \hat{\rho})),\;\; \text{compared with a } \chi^{2} \text{ distribution with 3 degrees of freedom}\] \[\text{With alpha:}\;\; \text{every}\; z_{t} \;\text{above}\; q = \Phi^{-1} (\alpha) \;\text{is censored at}\; q,\;\; \text{the AR}(1) \;\text{term is left out and the statistic} \;\mathord{-} 2 (\ln L(0,\; 1) - \ln L(\hat{\mu},\; \hat{\sigma})) \;\text{is compared with}\; a \chi^{2} \;\text{distribution with 2 degrees of freedom}\]

Where L is the exact Gaussian AR(1) likelihood (see forecast_evaluation_model.get_berkowitz_test) and F the distribution function of the standardized innovations with their fitted Shape and Skew. The Gaussian model uses a normal distribution with the mean and standard deviation (ddof=1) of the window returns before t and the EWMA model a normal distribution with mean zero and the RiskMetrics variance with decay lambda_.

Also known as: density forecast test, PIT test, Berkowitz LR test.

Example · QQQ, TLT, GLD · 2019 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_berkowitz_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_berkowitz_test()

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

Did the one-day-ahead return distributions of a GARCH model match what happened to the Invesco QQQ Trust, the iShares 20+ Year Treasury Bond ETF (TLT) and SPDR Gold Shares (GLD) from 2019 to 2025, according to the Berkowitz test?

Which returns:

Using Your Own Data

get_berkowitz_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_berkowitz_test()

Parameters

get_berkowitz_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"
alphafloat | NoneThe tail probability of the tail test. Defaults to None, which tests the whole density.0.01
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 Berkowitz, J. (2001). “Testing Density Forecasts, With Applications to Risk Management.” Journal of Business & Economic Statistics, 19(4), 465-474.
  • 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 Referenced against statsmodels’ ARIMA
  • Library Shares similar logic as rugarch (R)’s BerkowitzTest
Share