| Title: | Exact Finite-Sample Value-at-Risk Back-Testing |
|---|---|
| Description: | Provides fast dynamic-programming algorithms in 'C++'/'Rcpp' (with pure 'R' fallbacks) for the exact finite-sample distributions and p-values of Christoffersen (1998) independence (IND) and conditional-coverage (CC) VaR backtests. For completeness, it also provides the exact unconditional-coverage (UC) test following Kupiec (1995) via a closed-form binomial enumeration. See Christoffersen (1998) <doi:10.2307/2527341> and Kupiec (1995) <doi:10.3905/jod.1995.407942>. |
| Authors: | Yujian Chen [aut, cre] |
| Maintainer: | Yujian Chen <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.3 |
| Built: | 2026-05-22 07:33:17 UTC |
| Source: | https://github.com/yujianchen219/exactvartest |
Provides fast dynamic‑programming algorithms (C++/Rcpp) – with pure‑R fall‑backs – for the exact finite‑sample distributions and p‑values of Christoffersen’s (1998) VaR back‑tests: Independence (IND) and Conditional Coverage (CC) tests, and the Unconditional Coverage (UC) test via closed‑form binomial enumeration.
Maintainer: Yujian Chen [email protected]
Useful links:
Report bugs at https://github.com/YujianCHEN219/ExactVaRTest/issues
Exact UC/IND/CC back‑tests in one call
backtest_all(x, alpha = 0.05, sig = 0.05, prune_threshold = 1e-15)backtest_all(x, alpha = 0.05, sig = 0.05, prune_threshold = 1e-15)
x |
0/1 exception series. |
alpha |
Exception probability. |
sig |
Significance level (default |
prune_threshold |
Passed to the dynamic programming engine. |
An object of class "ExactVaRBacktestAll" (a named list) with components:
uc, ind, cc (each a list with stat, pval, reject),
and scalars sig (significance level), alpha (model exception probability),
n (sample size).
set.seed(1) x <- rbinom(300, 1, 0.02) backtest_all(x, alpha = 0.02)set.seed(1) x <- rbinom(300, 1, 0.02) backtest_all(x, alpha = 0.02)
Exact finite‑sample back‑test for a VaR exception series
backtest_lr( x, alpha = 0.05, type = c("uc", "ind", "cc"), sig = 0.05, prune_threshold = 1e-15 )backtest_lr( x, alpha = 0.05, type = c("uc", "ind", "cc"), sig = 0.05, prune_threshold = 1e-15 )
x |
0/1 exception series. |
alpha |
Exception probability. |
type |
|
sig |
Significance level (default |
prune_threshold |
Passed to the dynamic‑programming engine. |
An object of class "ExactVaRBacktest" (a named list) with components:
stat (numeric LR statistic),
pval (numeric exact -value in ),
reject (logical; TRUE if p < sig),
type (character; one of "uc", "ind", "cc"),
alpha (numeric model exception probability),
sig (numeric significance level),
n (integer sample size).
set.seed(123) x <- rbinom(250, 1, 0.01) backtest_lr(x, alpha = 0.01, type = "uc")set.seed(123) x <- rbinom(250, 1, 0.01) backtest_lr(x, alpha = 0.01, type = "uc")
Returns the finite‑sample distribution of Christoffersen’s conditional‑coverage
statistic . The returned list also includes the matching
unconditional‑coverage distribution , produced by the same
dynamic‑programming run.
lr_cc_dist(n, alpha = 0.05, prune_threshold = 1e-15)lr_cc_dist(n, alpha = 0.05, prune_threshold = 1e-15)
n |
Integer sample size ( |
alpha |
Exception probability |
prune_threshold |
Probability below which states are pruned by the dynamic‑programming recursion. |
A named list with elements LR_cc, prob_cc, LR_uc,
prob_uc. The pairs (LR_cc, prob_cc) and (LR_uc, prob_uc)
have equal lengths; each probability vector is in and sums to 1.
lr_cc_dist(8, 0.05)lr_cc_dist(8, 0.05)
Christoffersen LR_cc statistic
lr_cc_stat(x, alpha = 0.05)lr_cc_stat(x, alpha = 0.05)
x |
0/1 exception series. |
alpha |
Exception probability. |
Numeric LR_cc statistic.
Returns the finite‑sample distribution of Christoffersen’s independence
statistic .
lr_ind_dist(n, alpha = 0.05, prune_threshold = 1e-15)lr_ind_dist(n, alpha = 0.05, prune_threshold = 1e-15)
n |
Integer sample size ( |
alpha |
Exception probability |
prune_threshold |
Probability below which states are pruned by the dynamic‑programming recursion. |
A named list with elements LR and prob of equal length,
where LR is the support of the LR statistic and prob are the
corresponding probabilities in that sum to 1.
lr_ind_dist(8, 0.05)lr_ind_dist(8, 0.05)
Christoffersen LR_ind statistic
lr_ind_stat(x, alpha = 0.05)lr_ind_stat(x, alpha = 0.05)
x |
0/1 exception series. |
alpha |
Exception probability. |
Numeric LR_ind statistic.
Exact LR_uc distribution (closed‑form binomial)
lr_uc_dist(n, alpha = 0.05)lr_uc_dist(n, alpha = 0.05)
n |
Integer sample size ( |
alpha |
Exception probability |
A named list with elements LR and prob of equal length,
where LR is the support of the LR statistic and prob are the
corresponding probabilities in that sum to 1.
lr_uc_dist(8, 0.01)lr_uc_dist(8, 0.01)
Christoffersen LR_uc statistic
lr_uc_stat(x, alpha = 0.05)lr_uc_stat(x, alpha = 0.05)
x |
0/1 exception series. |
alpha |
Exception probability. |
Numeric LR_uc statistic.
Print method for ExactVaRBacktest
## S3 method for class 'ExactVaRBacktest' print(x, digits = max(3L, getOption("digits") - 3L), ...)## S3 method for class 'ExactVaRBacktest' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
An object of class 'ExactVaRBacktest'. |
digits |
Number of digits to print. |
... |
Further arguments passed to or from other methods (ignored). |
Prints the test name, sample size , model alpha, significance level,
LR statistic, exact p-value, and the decision at the specified level.
The input object x, returned invisibly (class ExactVaRBacktest).
Print method for ExactVaRBacktestAll
## S3 method for class 'ExactVaRBacktestAll' print(x, digits = max(3L, getOption("digits") - 3L), ...)## S3 method for class 'ExactVaRBacktestAll' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
An object of class 'ExactVaRBacktestAll'. |
digits |
Number of digits to print. |
... |
Further arguments passed to or from other methods (ignored). |
Prints a header with sample size , model alpha and significance level,
followed by per-test blocks for UC, IND, and CC: LR statistic, exact p-value,
and the decision at the specified level.
The input object x, returned invisibly (class ExactVaRBacktestAll).
Exact p-value for LR_cc
pval_lr_cc(lr_obs, n, alpha = 0.05, prune_threshold = 1e-15)pval_lr_cc(lr_obs, n, alpha = 0.05, prune_threshold = 1e-15)
lr_obs |
Observed LR_cc statistic. |
n |
Sample size. |
alpha |
Exception probability. |
prune_threshold |
State-pruning threshold for DP engine. |
Numeric exact -value in ; may be NA_real_ if the
finite-sample distribution is unavailable.
Exact p-value for LR_ind
pval_lr_ind(lr_obs, n, alpha = 0.05, prune_threshold = 1e-15)pval_lr_ind(lr_obs, n, alpha = 0.05, prune_threshold = 1e-15)
lr_obs |
Observed LR_ind statistic. |
n |
Sample size. |
alpha |
Exception probability. |
prune_threshold |
State-pruning threshold for DP engine. |
Numeric exact -value in ; may be NA_real_ if the
finite-sample distribution is unavailable.
Exact p-value for LR_uc
pval_lr_uc(lr_obs, n, alpha = 0.05)pval_lr_uc(lr_obs, n, alpha = 0.05)
lr_obs |
Observed LR_uc statistic. |
n |
Sample size. |
alpha |
Exception probability. |
Numeric exact -value in ; may be NA_real_ if the
finite-sample distribution is unavailable.