arch.univariate.traffic_light

arch.univariate.traffic_light(returns: ndarray[tuple[int], dtype[float64]] | Series | list[float], var: ndarray[tuple[int], dtype[float64]] | Series | list[float], p: float = 0.01, window: int = 250) → TrafficLightResult[source]

Basel traffic light zone of the exceptions of VaR.

Parameters:
returns: ndarray[tuple[int], dtype[float64]] | Series | list[float]

Realized returns, a 1-d array of finite numbers with at least window observations.

var: ndarray[tuple[int], dtype[float64]] | Series | list[float]

VaR forecasts as positive losses, a 1-d array of finite numbers. See var_exceptions for the sign convention and for how the inputs are aligned.

p: float = 0.01

The probability of an exception that the VaR is designed for, which is the size of the tail, in the interval (0, 0.5]. It is 0.05 for a 95% VaR and 0.01 for a 99% VaR. The default is 0.01, the 99% VaR of the Basel framework.

window: int = 250

The number of the most recent observations that are counted. It must be positive and no larger than the number of observations. The default is 250, about one year of daily data.

Returns:

The zone, the number of exceptions in the window, the cumulative binomial probability of that number of exceptions or fewer, the probability of that number or more (the type 1 error), the number of observations in the window and p.

Return type:

TrafficLightResult

Raises:
  • TypeError – If returns or var cannot be converted to numbers, p is not a real number or window is not an integer.

  • ValueError – If returns or var is not valid, as in var_exceptions, p is not in (0, 0.5], window is not positive, or there are fewer than window observations.

See also

kupiec_pof

Test of the proportion of exceptions.

Notes

The framework of the Basel Committee on Banking Supervision (1996) [1] counts the exceptions in the last 250 days. If the probability of an exception is p, the number of exceptions has a binomial distribution, and the cumulative probability \(P(X\leq x)\) of the observed number \(x\) sets the zone. The zone is green if the probability is below 95%, yellow if it is at least 95% and below 99.99%, and red if it is at least 99.99%, since the framework says that the yellow and the red zone begin where the probability equals or exceeds 95% and 99.99%. For 250 observations and p=0.01, green is 0 to 4 exceptions, yellow is 5 to 9 and red is 10 or more, which are the boundaries of Table 2 of the framework. The framework deduces the boundaries for other sample sizes from the binomial distribution in the same way, as this function does.

type1_error is \(P(X\geq x)\), the probability that an accurate model has \(x\) or more exceptions. The two probabilities add up to more than 1 by the probability of exactly \(x\) exceptions.

A series with no exception is always green. Its cumulative probability is the probability of the smallest number of exceptions, which is above 95% when window * p is small, but no exception is never a sign of understated risk.

A series with fewer than window observations raises an error rather than being tested with the observations that there are, because the zones of the framework are defined for a sample of the specified size. Set window to the number of observations to test a shorter series.

References