Model Confidence Set

Calculate the Model Confidence Set (MCS) of Hansen, Lunde and Nason: the volatility forecasting models that cannot be told apart from the best one.

The Diebold-Mariano test compares two forecasts; the MCS compares any number of them. Every model forecasts the next period’s variance of each asset from the returns before it, and its loss against the squared return is recorded. Starting from all models, the MCS tests whether they are equally good and, if not, eliminates the worst and tests again, until the remaining models cannot be told apart. The models left over form a set that contains the best model with a probability of at least 1 - alpha; the MCS p-value of a model says at which size it would leave the set.

The formula is as follows (with the default max statistic, QLIKE loss and daily returns):

\[\text{Loss}_{i,t} = \frac{\text{Return}_{t}^{2}}{\text{Forecast}_{i,t}} + \ln(\text{Forecast}_{i,t}),\;\; \text{or}\;\; (\text{Return}_{t}^{2} - \text{Forecast}_{i,t})^{2} \;\text{with the squared loss}\] \[d_{i} = \operatorname{mean}(\text{Loss}_{i}) - \frac{1}{m} \Sigma_{j} \;\text{mean}(\text{Loss}_{j})\;\;\text{and}\;\; t_{i} = \frac{d_{i}}{\sqrt{\operatorname{Var}(d_{i})}}\] \[T = \max_{i} t_{i},\;\; \text{with}\;\; \text{P-Value} = \frac{1}{B} \Sigma_{b} 1 \{T^{*}_{b} \geq T\} \;\text{over}\; B \;\text{stationary bootstrap resamples}\]
  • while the p-value is below alpha, the model with the largest \(t_{i}\) is eliminated and the test repeated
\[\text{MCS P-Value of a model} = \text{the largest p-value of the steps up to its elimination} \;(1 \;\text{for the last model})\]

Where m is the number of models still in the set, \(\operatorname{Var} (d_{i})\) the bootstrap variance of \(d_{i}\) and T*_b the statistic of the b-th resample centered at the full sample (see forecast_evaluation_model.get_model_confidence_set, also for the range statistic, the largest \(\vert t_{ij} \vert\) of all pairs). The forecasts of the models are:

  • EWMA: the RiskMetrics variance \(\lambda \cdot \sigma_{t - 1}^{2} + (1 - \lambda) \cdot r_{t - 1}^{2}\) with \(\lambda\) = lambda_
  • Rolling: the sample variance (ddof=1) of the window returns before t
  • GARCH, GJR-GARCH and the other models of Risk.get_garch: the one-step variance of the GARCH-family model with a constant mean and normal innovations (quasi-maximum likelihood), refitted every refit_every returns on the garch_window returns before t

Every model is compared on the dates all of them have a forecast. The squared-error loss and QLIKE rank volatility forecasts correctly with the squared return as a noisy proxy of the true variance (Patton 2011); QLIKE (written without the terms that do not depend on the forecast) is less sensitive to the largest returns.

Also known as: MCS, model confidence set, Hansen-Lunde-Nason test, forecast model selection.

Example · QQQ, TLT · 2019 to 2025

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

from financetoolkit import Toolkit

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

toolkit.econometrics.get_model_confidence_set()

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

Which of the EWMA, rolling, GARCH and GJR-GARCH volatility models belong to the 90% model confidence set of the Invesco QQQ and iShares 20+ Year Treasury Bond (TLT) ETFs from 2019 to 2025?

Which returns:

Using Your Own Data

get_model_confidence_set 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_model_confidence_set()

Parameters

get_model_confidence_set accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”."weekly"
modelslist[str] | NoneThe forecasting models to compare, at least two. Options are: “ewma” (RiskMetrics EWMA), “rolling” (rolling sample variance), “garch”, “gjr”, “egarch”, “igarch”, “aparch”, “tgarch”, “ngarch”, “avgarch”, “nagarch”, “component”, “figarch” (the GARCH-family models of Risk.get_garch). Defaults to None, which compares “ewma”, “rolling”, “garch” and “gjr”.None, which compares "ewma", "rolling", "garch" and "gjr"
lossstrThe loss of a forecast. Options are: “qlike” (QLIKE), “squared” (squared error). Defaults to “qlike”. The squared losses of daily variances are of the order of 1e-7, so they need a larger rounding to show."absolute"
statisticstrThe test statistic. Options are: “max” (the largest \(t_{i}\)), “range” (the largest \(\vert t_{ij} \vert\)). Defaults to “max”."max"
alphafloatThe size of the test. Defaults to 0.1, the 90% model confidence set.0.01
n_bootstrapintThe number of bootstrap resamples. Defaults to 1000.1000
block_sizeint | NoneThe average block length of the stationary bootstrap. Defaults to None, which uses the cube root of the number of periods, rounded.None, which uses the cube root of the number of periods, rounded
windowintThe window of the “rolling” model, at least 2. Defaults to 22 (about a month).20
lambda_floatThe decay factor of the “ewma” model. Defaults to 0.94.0.97
garch_windowint | NoneThe number of returns of every GARCH fit, at least 100, as a GARCH fit on fewer returns is not reliable. Defaults to None, which uses two years of observations with a minimum of 100 (504 daily returns).None, which uses two years of observations with a minimum of 100 (504 daily returns)
refit_everyintThe number of returns between two GARCH fits. Defaults to 21.21
seedintThe seed of the bootstrap. Defaults to 0.42
include_benchmarkboolWhether to include “Benchmark” among the assets. 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 Hansen, P.R., Lunde, A. and Nason, J.M. (2011). “The Model Confidence Set.” Econometrica, 79(2), 453-497.
  • Paper Patton, A.J. (2011). “Volatility Forecast Comparison Using Imperfect Volatility Proxies.” Journal of Econometrics, 160(1), 246-256.
  • Library Referenced against arch’s MCS
  • Library Referenced against rugarch (R)’s mcsTest
Share