| Title: | (Un)Conditional Forecast Dominance |
|---|---|
| Description: | A unified toolkit for out-of-sample forecast dominance testing. Covers unconditional and conditional equal and superior predictive ability, encompassing, and nested-model comparison. Implements the Diebold-Mariano test with the Harvey, Leybourne, and Newbold (1997) <doi:10.1016/S0169-2070(96)00719-4> small-sample correction; the Clark-West mean squared forecast error (MSFE) adjusted statistic (Clark and West, 2007) <doi:10.1016/j.jeconom.2006.05.023>; the ENC-NEW encompassing test of Clark and McCracken (2001) <doi:10.1016/S0304-4076(01)00071-9>; the Giacomini-White conditional equal predictive ability test (Giacomini and White, 2006) <doi:10.1111/j.1468-0262.2006.00718.x>; Hansen's superior predictive ability (SPA) test (Hansen, 2005) <doi:10.1198/073500105000000063>; the conditional superior predictive ability test of Li, Liao, and Quaedvlieg (2022) <doi:10.1093/restud/rdab039>; and the uniform and average multi-horizon SPA tests of Quaedvlieg (2021) <doi:10.1080/07350015.2019.1620074>. |
| Authors: | Gabriel Cabrera [aut, cre] (ORCID: <https://orcid.org/0000-0001-8803-2338>) |
| Maintainer: | Gabriel Cabrera <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-09-19 09:01:52 UTC |
| Source: | https://github.com/gabbocg/forecastdom |
Implements the average multi-horizon SPA test of Quaedvlieg (2021), which
tests whether a weighted average of horizon-wise expected loss differentials
favours the benchmark, allowing inferior performance at some horizons to be
compensated by superior performance at others. Bootstrap follows
Algorithm 1 (moving-block bootstrap, block length L).
aspa_mh_test(loss_diff, weights, L, B = 999L, level = 0.05)aspa_mh_test(loss_diff, weights, L, B = 999L, level = 0.05)
loss_diff |
A |
weights |
Numeric vector of length |
L |
Integer block length for the moving-block bootstrap. |
B |
Integer number of bootstrap replications. Default |
level |
Significance level. Default |
The aSPA statistic is
where and is the
Quadratic-Spectral HAC long-run variance (Andrews, 1991). Critical values
are obtained via a moving-block bootstrap that recentres the weighted
series under the null. The p-value is upper-tail
(mean(t < t_b)); rejection requires the weighted-average
differential to be large and positive (the benchmark loses on the
weighted average).
This is a port of the Matlab reference implementation accompanying
Quaedvlieg (2021); the helpers .mbb_indices, .mbb_variance,
and .qs_lrvar translate Get_MBB_ID.m, MBB_Variance.m,
and QS.m respectively.
A list with class "aspa_mh_test" containing
statistic, pvalue, reject, level,
L, B, T, H, weights, d_bar.
Quaedvlieg, R. (2021). Multi-Horizon Forecast Comparison. Journal of Business & Economic Statistics, 39(1), 40-53.
set.seed(2) ld <- matrix(rnorm(200 * 4, mean = 0.2), 200, 4) aspa_mh_test(ld, weights = rep(0.25, 4), L = 3, B = 199)set.seed(2) ld <- matrix(rnorm(200 * 4, mean = 0.2), 200, 4) aspa_mh_test(ld, weights = rep(0.25, 4), L = 3, B = 199)
Monthly US civilian unemployment rate and annualised monthly log
inflation rate, assembled from FRED series UNRATE and
CPIAUCSL. The series support the Phillips-curve forecasting
illustration in Clark and McCracken (2001, Section 5): does adding
lagged inflation to a univariate AR for unemployment improve
out-of-sample forecasts?
cm2001cm2001
A data frame with 937 rows and 3 columns:
First day of the month (Date).
Civilian unemployment rate (percent), FRED
UNRATE.
Annualised monthly log inflation, computed as
from
FRED CPIAUCSL.
FRED, Federal Reserve Bank of St. Louis, https://fred.stlouisfed.org/series/UNRATE and https://fred.stlouisfed.org/series/CPIAUCSL.
Clark, T. E. and McCracken, M. W. (2001). Tests of equal forecast accuracy and encompassing for nested models. Journal of Econometrics, 105(1), 85-110.
Constructs the confidence set for the most superior forecasting method
by inverting the CSPA test, as described in Section 2.3 of Li, Liao, and
Quaedvlieg (2022). The set contains all methods j for which the
CSPA null hypothesis (with j as benchmark) is not rejected.
csms( losses, X, level, trim = 0, prewhiten = -1L, preselect = TRUE, R = 10000L, method_names = NULL )csms( losses, X, level, trim = 0, prewhiten = -1L, preselect = TRUE, R = 10000L, method_names = NULL )
losses |
An |
X |
An |
level |
Significance level (e.g., 0.05). |
trim |
Trimming parameter (standard deviations). Default |
prewhiten |
Pre-whitening order. Default |
preselect |
Logical; adaptive inequality selection. Default
|
R |
Integer; Gaussian process replications. Default |
method_names |
Optional character vector of method names. If
|
For each method j in 0, ..., J, the CSPA test is applied
with j as the benchmark. The confidence set is:
A list with class "csms" containing:
in_set |
Logical vector; which methods are in the confidence set. |
set_members |
Names of methods in the confidence set. |
theta |
Theta values for each method as benchmark. |
pvalues |
P-values for each method as benchmark. |
method_names |
Names of all methods. |
level |
Significance level. |
n_methods |
Total number of methods. |
Li, J., Liao, Z., and Quaedvlieg, R. (2022). Conditional Superior Predictive Ability. Review of Economic Studies, 89(2), 843-875.
set.seed(42) n <- 300 X <- arima.sim(list(ar = 0.5), n = n, sd = sqrt(0.75)) losses <- matrix(rnorm(n * 4), n, 4) csms(losses, X, level = 0.05, trim = 2, R = 500L)set.seed(42) n <- 300 X <- arima.sim(list(ar = 0.5), n = n, sd = sqrt(0.75)) losses <- matrix(rnorm(n * 4), n, 4) csms(losses, X, level = 0.05, trim = 2, R = 500L)
Tests the null hypothesis that a benchmark forecasting method has conditional superior predictive ability over competing alternatives, uniformly across all conditioning states. Based on Li, Liao, and Quaedvlieg (2022).
cspa_test(Y, X, level, trim = 0, prewhiten = -1L, preselect = TRUE, R = 10000L)cspa_test(Y, X, level, trim = 0, prewhiten = -1L, preselect = TRUE, R = 10000L)
Y |
An |
X |
An |
level |
Significance level (e.g., 0.05). |
trim |
Trim observations where the conditioning variable exceeds this
many standard deviations from the mean. Use |
prewhiten |
Order of pre-whitening VAR for HAC estimation. Use
|
preselect |
Logical; perform adaptive inequality selection? Default
|
R |
Integer; number of bootstrap replications for critical value
computation. Default |
A list with class "cspa_test" containing:
theta |
Infimum of the upper confidence bound. Negative values lead to rejection of the null. |
pvalue |
P-value for the test. |
reject |
Logical; whether the null is rejected at the given level. |
level |
Significance level used. |
h_hat |
Estimated conditional mean functions ( |
sigma_jx |
Estimated standard deviations ( |
kp |
Critical value from adaptive inequality selection. |
Vhat |
Logical matrix indicating selected (j, x) pairs. |
X |
Conditioning variable (after trimming). |
Y |
Loss differentials (after trimming). |
K |
Number of series terms used. |
prewhiten_order |
Pre-whitening lag order actually used. |
Li, J., Liao, Z., and Quaedvlieg, R. (2022). Conditional Superior Predictive Ability. Review of Economic Studies, 89(2), 843-875.
sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) result <- cspa_test(sim$Y, sim$X, level = 0.05, trim = 2, R = 500L) print(result)sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) result <- cspa_test(sim$Y, sim$X, level = 0.05, trim = 2, R = 500L) print(result)
Visualizes the estimated conditional mean functions ,
their lower envelope, and the confidence bound from the CSPA test.
cspa_test_plot( object = NULL, Y = NULL, X = NULL, level = 0.05, trim = 0, prewhiten = -1L, preselect = TRUE, ylab = "Loss Difference", xlab = "Conditioning Variable" )cspa_test_plot( object = NULL, Y = NULL, X = NULL, level = 0.05, trim = 0, prewhiten = -1L, preselect = TRUE, ylab = "Loss Difference", xlab = "Conditioning Variable" )
object |
A |
Y |
An |
X |
An |
level |
Significance level (e.g., 0.05). Ignored if |
trim |
Trimming parameter. Default |
prewhiten |
Pre-whitening order. Default |
preselect |
Logical; adaptive inequality selection. Default
|
ylab |
Label for the y-axis. Default |
xlab |
Label for the x-axis. Default |
A ggplot object.
Tests whether an alternative (unrestricted) model has superior
out-of-sample predictive ability relative to a benchmark (restricted)
model, using the MSFE-adjusted statistic of Clark and West (2007).
Also computes the out-of-sample statistic.
cw_test(e1, e2, f1, f2)cw_test(e1, e2, f1, f2)
e1 |
Numeric vector of forecast errors from the benchmark (restricted/null) model. |
e2 |
Numeric vector of forecast errors from the alternative (unrestricted) model. |
f1 |
Numeric vector of forecasts from the benchmark model. |
f2 |
Numeric vector of forecasts from the alternative model. |
The MSFE-adjusted series is defined as:
The test regresses on a constant and uses the resulting
t-statistic, compared to a standard normal distribution (one-sided).
A list with class "cw_test" containing:
statistic |
The Clark-West t-statistic. |
pvalue |
One-sided p-value (H1: alternative is better). |
r2os |
Out-of-sample |
n |
Number of observations. |
Clark, T.E. and West, K.D. (2007). Approximately Normal Tests for Equal Predictive Accuracy in Nested Models. Journal of Econometrics, 138(1), 291-311.
set.seed(42) n <- 200 actual <- rnorm(n) f1 <- actual + rnorm(n, sd = 0.5) f2 <- actual + rnorm(n, sd = 0.4) e1 <- actual - f1 e2 <- actual - f2 cw_test(e1, e2, f1, f2)set.seed(42) n <- 200 actual <- rnorm(n) f1 <- actual + rnorm(n, sd = 0.5) f2 <- actual + rnorm(n, sd = 0.4) e1 <- actual - f1 e2 <- actual - f2 cw_test(e1, e2, f1, f2)
Tests the null hypothesis that two forecasting methods have equal predictive ability (UEPA), with an optional small-sample correction by Harvey, Leybourne, and Newbold (1997).
dm_test( e1, e2, h = 1L, loss = c("SE", "AE"), alternative = c("two.sided", "less", "greater"), correction = TRUE )dm_test( e1, e2, h = 1L, loss = c("SE", "AE"), alternative = c("two.sided", "less", "greater"), correction = TRUE )
e1 |
Numeric vector of forecast errors from model 1 (benchmark). |
e2 |
Numeric vector of forecast errors from model 2 (competitor). |
h |
Integer; forecast horizon. Default |
loss |
Character; loss function to use. |
alternative |
Character; alternative hypothesis. |
correction |
Logical; apply the Harvey, Leybourne, and Newbold (1997)
finite-sample correction? Default |
A list with class "dm_test" containing:
statistic |
The (possibly corrected) DM test statistic. |
pvalue |
P-value. |
alternative |
The alternative hypothesis used. |
correction |
Whether HLN correction was applied. |
h |
Forecast horizon. |
n |
Number of observations. |
loss |
Loss function used. |
Diebold, F.X. and Mariano, R.S. (1995). Comparing Predictive Accuracy. Journal of Business & Economic Statistics, 13(3), 253-263.
Harvey, D., Leybourne, S., and Newbold, P. (1997). Testing the Equality of Prediction Mean Squared Errors. International Journal of Forecasting, 13(2), 281-291.
set.seed(42) e1 <- rnorm(100) e2 <- rnorm(100, mean = 0.1) dm_test(e1, e2)set.seed(42) e1 <- rnorm(100) e2 <- rnorm(100, mean = 0.1) dm_test(e1, e2)
Generates data from the data generating process in Section 3.1 of Li,
Liao, and Quaedvlieg (2022). The conditioning variable follows
a Gaussian AR(1) with coefficient 0.5, and the loss differentials are
, where
follows an AR(1) with coefficient rho_u.
do_sim(J, n, a, c, rho_u)do_sim(J, n, a, c, rho_u)
J |
Integer; number of competing forecast methods. |
n |
Integer; sample size. |
a |
Numeric; controls the shape of the conditional mean function.
|
c |
Numeric; location parameter for the minimum of |
rho_u |
Numeric in |
A list with components:
Y |
An |
X |
A numeric vector of length |
sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) str(sim)sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) str(sim)
Tests whether the benchmark model encompasses the alternative model, using the ENC-NEW statistic of Clark and McCracken (2001). Under the null, the benchmark forecast encompasses the alternative (no additional information in the alternative).
enc_new(e1, e2)enc_new(e1, e2)
e1 |
Numeric vector of forecast errors from the benchmark model. |
e2 |
Numeric vector of forecast errors from the alternative model. |
The ENC-NEW statistic is:
where and
.
Critical values are non-standard and depend on the estimation setup. See Clark and McCracken (2001, Table 2) for asymptotic critical values.
A list with class "enc_new" containing:
statistic |
The ENC-NEW test statistic. |
n |
Number of observations. |
Clark, T.E. and McCracken, M.W. (2001). Tests of Equal Forecast Accuracy and Encompassing for Nested Models. Journal of Econometrics, 105(1), 85-110.
set.seed(42) e1 <- rnorm(100) e2 <- rnorm(100, sd = 0.9) enc_new(e1, e2)set.seed(42) e1 <- rnorm(100) e2 <- rnorm(100, sd = 0.9) enc_new(e1, e2)
Tests the null hypothesis of conditional equal predictive ability using the Giacomini and White (2006) approach. The test checks whether loss differentials are conditionally mean-zero given an information set, using a finite set of instruments.
gw_test(e1, e2, instruments = NULL, loss = c("SE", "AE"))gw_test(e1, e2, instruments = NULL, loss = c("SE", "AE"))
e1 |
Numeric vector of forecast errors from model 1 (benchmark). |
e2 |
Numeric vector of forecast errors from model 2 (competitor). |
instruments |
An |
loss |
Character; loss function. |
The test is based on the unconditional moment conditions implied by the CEPA null hypothesis:
where is the loss differential and is a vector of
instruments measurable with respect to the conditioning information set.
The test statistic follows a chi-squared distribution with
degrees of freedom, where is the number of instruments.
A list with class "gw_test" containing:
statistic |
The Wald test statistic. |
pvalue |
P-value from the chi-squared distribution. |
df |
Degrees of freedom (number of instruments). |
n |
Number of observations used. |
loss |
Loss function used. |
Giacomini, R. and White, H. (2006). Tests of Conditional Predictive Ability. Econometrica, 74(6), 1545-1578.
set.seed(42) e1 <- rnorm(200) e2 <- rnorm(200, sd = 0.9) gw_test(e1, e2)set.seed(42) e1 <- rnorm(200) e2 <- rnorm(200, sd = 0.9) gw_test(e1, e2)
Quarterly mean Survey of Professional Forecasters (SPF) forecasts of
annualised CPI inflation at horizons
quarters ahead, aligned with realised CPI inflation from FRED. The
panel covers 1981Q3 onward, the start of the SPF's CPI survey.
gw2006gw2006
A data frame with 180 rows and 10 columns:
First day of the third month of the realisation
quarter (Date).
Realisation quarter.
Realised annualised QoQ CPI inflation (percent),
computed from quarterly averages of CPIAUCSL.
One-quarter lag of infl — the naive
random-walk forecast benchmark.
SPF mean forecasts
of infl, made quarters in advance.
SPF mean CPI inflation forecasts from the Federal Reserve Bank of Philadelphia, https://www.philadelphiafed.org/surveys-and-data/real-time-data-research/survey-of-professional-forecasters. Realised CPI from FRED series CPIAUCSL, https://fred.stlouisfed.org/series/CPIAUCSL.
Giacomini, R. and White, H. (2006). Tests of conditional predictive ability. Econometrica, 74(6), 1545-1578.
Daily IBM data from the replication archive of Hansen and Lunde
(2005). Contains 254 trading days (1999-06-01 to 2000-05-31),
8 realized-variance proxies of varying quality, and 330
one-step-ahead conditional variance forecasts produced by GARCH-family
models. The benchmark GARCH(1,1) with constant mean and Gaussian
errors is identified by the index garch11_idx.
hl2005hl2005
A list with the following components:
Trading-day Date vector (length 254).
Numeric vector (length 254); the 5-minute linear-interpolation realized-variance proxy. The paper's headline series.
matrix of alternative RV
proxies: sq_ccr (squared close-to-close returns),
spline_50_3min, spline_250_2min, fourier_M85,
linear_5min, prevtick_5min, linear_1min,
prevtick_1min.
matrix of one-step-ahead
conditional variance forecasts. Columns index a base GARCH
specification (55 specs: LGARCH, IGARCH, TS-GARCH, A-GARCH,
NA-GARCH, V-GARCH, THR-GARCH, GJR-GARCH, LOG-GARCH, EGARCH,
NGARCH, A-PARCH, GQ-ARCH, H-GARCH, AUG-GARCH) crossed with
mean-equation and error-distribution combinations (zero/const/
GARCH-in-mean Gaussian/t-distributed).
Integer (= 57); the column of forecasts
corresponding to GARCH(1,1) with constant mean and Gaussian
errors, used as the benchmark in the paper.
Journal of Applied Econometrics data archive for Hansen and Lunde (2005), volume 20, issue 7.
Hansen, P. R. and Lunde, A. (2005). A forecast comparison of volatility models: does anything beat a GARCH(1,1)? Journal of Applied Econometrics, 20(7), 873-889.
Computes the IVX-Wald statistic of Kostakis, Magdalinos, and Stamatogiannis (2015) for testing predictability in a regression of returns on persistent predictors. The IVX approach is robust to the degree of persistence of the regressors (stationary, local-to-unity, or unit root).
ivx_wald(y, X, K = 1L, M_n = 0L, beta = 0.95)ivx_wald(y, X, K = 1L, M_n = 0L, beta = 0.95)
y |
Numeric vector of length |
X |
A |
K |
Integer; forecast horizon. Default |
M_n |
Integer; bandwidth parameter for the long-run covariance
estimator. Default |
beta |
Numeric in |
The IVX-Wald test constructs an endogenous instrument
by filtering the predictor increments through a
mildly integrated process with autoregressive root
. The resulting Wald statistic is
asymptotically chi-squared with r degrees of freedom,
regardless of the persistence of the predictors.
A list with class "ivx_wald" containing:
statistic |
The IVX-Wald test statistic. |
pvalue |
P-value from the chi-squared distribution. |
coefficients |
IVX coefficient estimates. |
K |
Forecast horizon. |
n |
Number of observations. |
r |
Number of predictors. |
Kostakis, A., Magdalinos, T., and Stamatogiannis, M.P. (2015). Robust Econometric Inference for Stock Return Predictability. Review of Financial Studies, 28(5), 1506-1553.
set.seed(42) n <- 200 x <- cumsum(rnorm(n)) y <- 0.02 * x + rnorm(n) ivx_wald(y, as.matrix(x))set.seed(42) n <- 200 x <- cumsum(rnorm(n)) y <- 0.02 * x + rnorm(n) ivx_wald(y, as.matrix(x))
Daily 5-minute realized variance of the S&P 500 with one-step-ahead out-of-sample forecasts from six competing models, plus lagged VIX as a conditioning variable. The forecasts and realized variances are from the replication package of Li, Liao and Quaedvlieg (2022) on Zenodo; the underlying RV series is from Bollerslev, Patton and Quaedvlieg (2016).
llq2022llq2022
A data frame with 3,071 rows and 9 variables. Sample period is 2001-05-11 to 2013-08-30 (daily, trading days).
Trading-day Date.
Realized variance of the S&P 500 (5-minute returns), in percent-squared units.
AR(1) forecast of rv.
AR(22) forecast of rv.
AR(22) forecast with adaptive lasso (Matlab).
HAR forecast of Corsi (2009).
HARQ forecast of Bollerslev, Patton and Quaedvlieg (2016).
Fractionally integrated AR forecast.
VIX close from the previous trading day, used as conditioning variable.
Replication package of Li, Liao and Quaedvlieg (2022), https://zenodo.org/record/4884813. Realized variance series adapted from Bollerslev, Patton and Quaedvlieg (2016), retrieved from Quaedvlieg's website. VIX from CBOE.
Bollerslev, T., Patton, A. J. and Quaedvlieg, R. (2016). Exploiting the errors: a simple approach for improved volatility forecasting. Journal of Econometrics, 192(1), 1-18.
Corsi, F. (2009). A simple approximate long-memory model of realized volatility. Journal of Financial Econometrics, 7(2), 174-196.
Li, J., Liao, Z. and Quaedvlieg, R. (2022). Conditional Superior Predictive Ability. Review of Economic Studies, 89(2), 843-875.
data(llq2022) head(llq2022) # Squared-error losses per model: losses <- (llq2022[, c("AR1","AR22","AR22_Lasso","HAR","HARQ","ARFIMA")] - llq2022$rv)^2 colMeans(losses)data(llq2022) head(llq2022) # Squared-error losses per model: losses <- (llq2022[, c("AR1","AR22","AR22_Lasso","HAR","HARQ","ARFIMA")] - llq2022$rv)^2 colMeans(losses)
Daily 5-minute realized variance of Johnson & Johnson (NYSE: JNJ) with one-step-ahead out-of-sample forecasts from six competing models, plus one-day-lagged VIX as a conditioning variable. JNJ is the stock featured in Figures 2 and 3 of Li, Liao and Quaedvlieg (2022).
llq2022_jnjllq2022_jnj
A data frame with the same columns as llq2022:
Trading-day Date.
Realized variance (5-minute returns), percent-squared.
One-step-ahead
forecasts of rv.
VIX close from the previous trading day.
Replication package of Li, Liao and Quaedvlieg (2022), https://zenodo.org/record/4884813. Realized variance series from Bollerslev, Patton and Quaedvlieg (2016). VIX from CBOE.
Bollerslev, T., Patton, A. J. and Quaedvlieg, R. (2016). Exploiting the errors: a simple approach for improved volatility forecasting. Journal of Econometrics, 192(1), 1-18.
Li, J., Liao, Z. and Quaedvlieg, R. (2022). Conditional Superior Predictive Ability. Review of Economic Studies, 89(2), 843-875.
Pre-computed rejection counts replicating Table_UV_CSPA.xlsx from
the Li, Liao and Quaedvlieg (2022) replication package. For each of
28 stocks, pairwise conditional superior predictive ability (CSPA)
tests are run for every benchmark-competitor pair across six
realized-variance forecasting models; cell counts the
number of stocks for which the null “benchmark
conditionally dominates alternative ” is rejected at the 5%
level. Conditioning variable is one-day-lagged VIX; loss is QLIKE.
llq2022_uv_cspallq2022_uv_cspa
A list with the following components:
integer matrix of rejection counts
produced by forecastdom::cspa_test with R = 10000
bootstrap reps and AIC pre-whitening, matching the call
signature in Empirics_Volatility.ox.
integer matrix from
Table_UV_CSPA.xlsx in the LLQ replication package.
matrix of mean QLIKE loss per
stock and model.
Character vector of the 28 tickers used.
Character vector of the six model names.
Significance level used (0.05).
Number of bootstrap replications used.
Computed by data-raw/llq2022_uv_cspa.R from the
replication package of Li, Liao and Quaedvlieg (2022),
https://zenodo.org/record/4884813.
Li, J., Liao, Z. and Quaedvlieg, R. (2022). Conditional Superior Predictive Ability. Review of Economic Studies, 89(2), 843-875.
Tests the null hypothesis of equal mean squared forecast error between the (restricted) benchmark and the (unrestricted) alternative nested model, using the MSE-F statistic of McCracken (2007). Under the null, the alternative does not reduce MSFE relative to the benchmark.
mse_f_test(e1, e2, h = 1L)mse_f_test(e1, e2, h = 1L)
e1 |
Numeric vector of forecast errors from the benchmark (restricted) model. |
e2 |
Numeric vector of forecast errors from the alternative (unrestricted) model. |
h |
Integer; forecast horizon. Default |
The MSE-F statistic is:
where is the number of out-of-sample observations and
is the forecast horizon.
Critical values are non-standard and depend on the number of extra
regressors in the alternative model () and on
(out-of-sample size relative to estimation
window). See McCracken (2007, Table 1) for asymptotic critical
values.
A list with class "mse_f_test" containing:
statistic |
The MSE-F test statistic. |
msfe1 |
Mean squared forecast error of the benchmark. |
msfe2 |
Mean squared forecast error of the alternative. |
n |
Number of out-of-sample observations. |
h |
Forecast horizon. |
McCracken, M.W. (2007). Asymptotics for out of sample tests of Granger causality. Journal of Econometrics, 140(2), 719-752.
Clark, T.E. and McCracken, M.W. (2001). Tests of Equal Forecast Accuracy and Encompassing for Nested Models. Journal of Econometrics, 105(1), 85-110.
set.seed(42) e1 <- rnorm(100) e2 <- rnorm(100, sd = 0.9) mse_f_test(e1, e2)set.seed(42) e1 <- rnorm(100) e2 <- rnorm(100, sd = 0.9) mse_f_test(e1, e2)
Monthly U.S. log equity premium (in percent) and the 14 binary technical-indicator predictors of Neely, Rapach, Tu, and Zhou (2014), "Forecasting the Equity Risk Premium: The Role of Technical Indicators." The macroeconomic predictors of the same paper are not included; for those, see rz2013.
nrtz2014nrtz2014
A data frame with 733 rows and 16 variables. Sample period is 1950-12 to 2011-12 (monthly).
First-of-month Date.
Log equity premium, in percent:
.
Moving-average
signals MA(s,l) for , .
Momentum signals MOM(m) for .
On-balance-volume signals VOL(s,l) for ,
.
Indicators are constructed from monthly S&P 500 closing prices and trading volume (Goyal-Welch updated dataset) following the rules in the paper:
MA(s,l) – 1 if the -month moving average of
the price exceeds the -month moving average, else 0.
MOM(m) – 1 if today's price is at or above the price
months ago, else 0.
VOL(s,l) – 1 if the -month moving average of
on-balance volume exceeds the -month moving average, else 0.
Replication archive of Neely et al. (2014): https://github.com/gabbocg/nrtz2014. The underlying price and volume data are from Amit Goyal's website (https://sites.google.com/view/agoyal145).
Neely, C. J., Rapach, D. E., Tu, J., and Zhou, G. (2014). Forecasting the equity risk premium: The role of technical indicators. Management Science, 60(7), 1772-1791.
data(nrtz2014) head(nrtz2014) # Fraction of months each technical indicator equals 1 colMeans(nrtz2014[, -(1:2)])data(nrtz2014) head(nrtz2014) # Fraction of months each technical indicator equals 1 colMeans(nrtz2014[, -(1:2)])
Displays a formatted summary of the CSPA test output, including the test statistic (theta), p-value, decision, and key estimation details.
## S3 method for class 'cspa_test' print(x, digits = 4, ...)## S3 method for class 'cspa_test' print(x, digits = 4, ...)
x |
An object of class |
digits |
Integer; number of decimal places for numeric output.
Default |
... |
Additional arguments (currently ignored). |
Invisibly returns x.
sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) result <- cspa_test(sim$Y, sim$X, level = 0.05, trim = 2, R = 500L) print(result)sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) result <- cspa_test(sim$Y, sim$X, level = 0.05, trim = 2, R = 500L) print(result)
Computes the statistic of Elliott and Muller (2006) for
testing the null hypothesis that regression coefficients are constant
over time against the alternative of general time variation.
qll_hat(y, X, Z = NULL, L = 0L)qll_hat(y, X, Z = NULL, L = 0L)
y |
Numeric vector of length |
X |
A |
Z |
A |
L |
Integer; lag truncation for the Newey-West estimator of the
variance. Default |
The test is based on optimal invariant statistics for the null of
constant coefficients against local alternatives. The
statistic has non-standard critical values that depend on k;
see Table 1 in Elliott and Muller (2006).
Selected critical values (5\
k = 1: -5.91
k = 2: -10.64
k = 3: -15.78
k = 4: -20.62
k = 5: -25.87
Reject the null when is below the critical value.
A list with class "qll_hat" containing:
statistic |
The |
k |
Number of potentially time-varying coefficients. |
n |
Number of observations. |
Elliott, G. and Muller, U.K. (2006). Efficient Tests for General Persistent Time Variation in Regression Coefficients. Review of Economic Studies, 73(4), 907-940.
set.seed(42) n <- 200 x <- matrix(rnorm(n * 2), n, 2) y <- x %*% c(0.5, -0.3) + rnorm(n) qll_hat(y, x)set.seed(42) n <- 200 x <- matrix(rnorm(n * 2), n, 2) y <- x %*% c(0.5, -0.3) + rnorm(n) qll_hat(y, x)
Two example matrices of loss differentials at horizons
from the replication archive of Quaedvlieg (2021). $uspa is a
configuration where average SPA holds but uniform SPA does not;
$aspa is a configuration where both hold.
quaedvlieg2021quaedvlieg2021
A list with two elements, each a T x 20 numeric matrix:
Loss differentials with aSPA but not uSPA.
Loss differentials with both aSPA and uSPA.
Author's replication archive distributed alongside Quaedvlieg (2021), JBES 39(1):40-53.
Monthly nominal exchange rates against the U.S. dollar for five industrialised economies, used in the empirical exercise of Rossi (2006). Originally distributed as a Datastream extract in the replication archive at https://github.com/gabbocg/rossi2006.
rossi2006rossi2006
A data frame with 1,550 rows and 3 variables:
First-of-month Date, from 1973-03-01 to
1998-12-01 (310 monthly observations per country).
Factor with levels "Canada",
"France", "Germany", "Italy",
"Japan".
Numeric. Nominal bilateral exchange rate level vs. the
U.S. dollar, as supplied in the source file. The empirical
exercise in Rossi (2006) works with log(fx) and its
monthly differences.
Replication archive of Rossi (2006): https://github.com/gabbocg/rossi2006.
Rossi, B. (2006). Are exchange rates really random walks? Some evidence robust to parameter instability. Macroeconomic Dynamics, 10(1), 20-38.
Meese, R. A. and Rogoff, K. (1983). Empirical exchange rate models of the seventies: Do they fit out of sample? Journal of International Economics, 14(1-2), 3-24.
data(rossi2006) head(rossi2006) with(subset(rossi2006, country == "Japan"), plot(date, log(fx), type = "l", main = "Japan log FX"))data(rossi2006) head(rossi2006) with(subset(rossi2006, country == "Japan"), plot(date, log(fx), type = "l", main = "Japan log FX"))
Monthly U.S. log excess return on the S&P 500 and the short interest index (SII) used in Rapach, Ringgenberg, and Zhou (2016), "Short interest and aggregate stock returns" (Journal of Financial Economics, 121, 46-65). Sample period 1973-01 to 2014-12.
rrz2016rrz2016
A data frame with 504 rows and 3 variables:
First-of-month Date.
Log excess return on the S&P 500:
.
Short interest index, standardised linearly-detrended log EWSI.
SII is constructed as standardised residuals from a linear regression
of on a time trend, where
is the equal-weighted mean across all firms of the number of shares
held short normalised by shares outstanding.
Replication archive of Rapach, Ringgenberg, and Zhou (2016): https://github.com/gabbocg/rrz2016.
Rapach, D. E., Ringgenberg, M. C. and Zhou, G. (2016). Short interest and aggregate stock returns. Journal of Financial Economics, 121(1), 46-65.
data(rrz2016) head(rrz2016) plot(rrz2016$date, rrz2016$SII, type = "l", xlab = NULL, ylab = "SII")data(rrz2016) head(rrz2016) plot(rrz2016$date, rrz2016$SII, type = "l", xlab = NULL, ylab = "SII")
Monthly U.S. log equity premium and the 14 Goyal-Welch macroeconomic predictors used in Rapach and Zhou (2013), "Forecasting Stock Returns," Handbook of Economic Forecasting, Vol. 2A, Chapter 6. Sourced from the replication archive at https://github.com/gabbocg/rz2013.
rz2013rz2013
A data frame with 1,009 rows and 16 variables. Sample period is 1926-12 to 2010-12 (monthly).
First-of-month Date.
Log equity premium: ,
where is the CRSP value-weighted S&P 500 return.
Log dividend-price ratio.
Log dividend yield.
Log earnings-price ratio.
Log dividend-payout ratio.
Stock variance: monthly sum of squared daily S&P 500 returns.
DJIA book-to-market ratio.
Net equity expansion.
3-month Treasury bill yield (decimal).
Long-term government bond yield (decimal).
Long-term government bond return (decimal).
Term spread: LTY - TBL.
Default yield spread: BAA minus AAA corporate yields.
Default return spread: long-term corporate minus government bond return.
Inflation rate, lagged one month (decimal).
Replication archive of Rapach and Zhou (2013): https://github.com/gabbocg/rz2013. The underlying data are from Amit Goyal's website (https://sites.google.com/view/agoyal145).
Rapach, D. E. and Zhou, G. (2013). Forecasting stock returns. In G. Elliott and A. Timmermann (Eds.), Handbook of Economic Forecasting, Vol. 2A, pp. 328-383. Elsevier.
Goyal, A. and Welch, I. (2008). A comprehensive look at the empirical performance of equity premium prediction. Review of Financial Studies, 21(4), 1455-1508.
data(rz2013) head(rz2013) summary(rz2013$eq_prem)data(rz2013) head(rz2013) summary(rz2013$eq_prem)
Tests the null hypothesis that a benchmark forecasting method has unconditional superior predictive ability over all competing alternatives, using Hansen's (2005) stationary bootstrap approach.
spa_test(Y, level, B = 5000L, q = 0.25)spa_test(Y, level, B = 5000L, q = 0.25)
Y |
An |
level |
Significance level (e.g., 0.05). |
B |
Integer; number of bootstrap replications. Default |
q |
Numeric in |
The SPA test statistic is:
where is the mean loss differential for competitor j
and is its estimated standard deviation.
The null hypothesis is rejected when the benchmark is not superior to all competitors, i.e., some competitor significantly outperforms it.
Hansen's (2005) consistent test uses a pre-selection step to remove clearly inferior competitors from the critical value computation.
A list with class "spa_test" containing:
statistic |
The SPA test statistic (consistent). |
pvalue |
Bootstrap p-value. |
reject |
Logical; whether the null is rejected. |
level |
Significance level used. |
d_bar |
Sample mean of loss differentials for each competitor. |
n |
Number of observations. |
J |
Number of competitors. |
B |
Number of bootstrap replications. |
Hansen, P.R. (2005). A Test for Superior Predictive Ability. Journal of Business & Economic Statistics, 23(4), 365-380.
White, H. (2000). A Reality Check for Data Snooping. Econometrica, 68(5), 1097-1126.
sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) spa_test(sim$Y, level = 0.05, B = 500)sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) spa_test(sim$Y, level = 0.05, B = 500)
Provides a detailed summary of the CSPA test, including per-competitor diagnostics of the estimated conditional mean functions.
## S3 method for class 'cspa_test' summary(object, digits = 4, ...)## S3 method for class 'cspa_test' summary(object, digits = 4, ...)
object |
An object of class |
digits |
Integer; number of decimal places. Default |
... |
Additional arguments (currently ignored). |
Invisibly returns object.
sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) result <- cspa_test(sim$Y, sim$X, level = 0.05, trim = 2, R = 500L) summary(result)sim <- do_sim(J = 3, n = 250, a = 1, c = 0, rho_u = 0.4) result <- cspa_test(sim$Y, sim$X, level = 0.05, trim = 2, R = 500L) summary(result)
Tests the null hypothesis that a benchmark forecasting method has
uniform (i.e. simultaneous, at every horizon) superior predictive
ability over a competitor in a multi-horizon setting, using Quaedvlieg's
(2021) moving-block-bootstrap implementation of the uniform SPA test
(uSPA).
uspa_mh_test(loss_diff, L, B = 999L, level = 0.05)uspa_mh_test(loss_diff, L, B = 999L, level = 0.05)
loss_diff |
A |
L |
Integer; moving-block-bootstrap block length. |
B |
Integer; number of bootstrap replications. Default |
level |
Significance level (e.g. |
The uniform multi-horizon SPA test statistic is
where is the sample mean of the loss differential
L_bench - L_comp at horizon h, and is its
Quadratic-Spectral HAC long-run variance estimate (Andrews, 1991).
Critical values are obtained from a moving-block bootstrap that recentres
the loss differentials so the null is imposed (Quaedvlieg, 2021), with the
"natural variance" estimator recomputed within each bootstrap replication.
The resulting p-value is upper-tail: large positive values of the statistic
(i.e. the benchmark has higher loss uniformly across horizons)
lead to rejection. Equivalently, rejection requires at
every horizon; the test has limited power against alternatives where the
benchmark is worse at only some horizons.
This is a port of the Matlab reference implementation accompanying
Quaedvlieg (2021); the helpers .mbb_indices, .mbb_variance,
and .qs_lrvar translate Get_MBB_ID.m, MBB_Variance.m,
and QS.m respectively.
A list with class "uspa_mh_test" containing:
statistic |
The uSPA test statistic
|
pvalue |
Moving-block bootstrap p-value
|
reject |
Logical; whether the null is rejected at |
level |
Significance level used. |
L |
Block length used. |
B |
Number of bootstrap replications. |
T |
Number of time periods. |
H |
Number of forecast horizons. |
d_bar |
Sample mean of loss differentials at each horizon (length |
Quaedvlieg, R. (2021). Multi-Horizon Forecast Comparison. Journal of Business & Economic Statistics, 39(1), 40-53.
set.seed(1) ld <- matrix(rnorm(200 * 4, mean = 0.3), 200, 4) uspa_mh_test(ld, L = 3, B = 199, level = 0.10)set.seed(1) ld <- matrix(rnorm(200 * 4, mean = 0.3), 200, 4) uspa_mh_test(ld, L = 3, B = 199, level = 0.10)
Annual equity premium and predictor series built from Welch and
Goyal's original PredictorData.xls (annual sheet) — the
data vintage shipped with the published 2008 paper. The equity
premium is constructed as the log total return on the S&P 500
minus the log risk-free rate (per WG Section 1), and the log
dividend-price ratio is
.
wg2008wg2008
A data frame with 134 rows and 13 columns covering 1872-2005:
Calendar year.
S&P 500 price level.
Twelve-month moving sum of dividends.
Twelve-month moving sum of earnings.
Risk-free rate (decimal).
Treasury-bill yield.
CPI inflation rate.
Net equity expansion.
Total return on the S&P 500,
.
Log equity premium,
.
Lagged log dividend-price ratio,
— the predictor used
in WG Table 1.
Lagged log earnings-price ratio.
Lagged log dividend-payout ratio.
Welch and Goyal (2008) original annual data file
PredictorData.xls, distributed with the paper. A
regularly updated version is maintained on Amit Goyal's
website, https://sites.google.com/view/agoyal145.
Welch, I. and Goyal, A. (2008). A comprehensive look at the empirical performance of equity premium prediction. Review of Financial Studies, 21(4), 1455-1508.