# Tail Value at Risk (TVaR)

> What Tail Value at Risk (TVaR) means and how to calculate it: the average loss of the worst k trials, how it differs from CTE and expected shortfall, with code.

Source: https://reinsurance.dev/toolkit/metrics/tail-value-at-risk/

[Value at Risk (VaR)](https://reinsurance.dev/toolkit/metrics/value-at-risk/) tells you where the tail starts. **[Tail Value at Risk (TVaR)](https://reinsurance.dev/glossary/#tvar-tail-value-at-risk)** tells you how bad it gets once you are in it. At confidence level $\alpha$, TVaR is the average loss across the worst $(1-\alpha)$ of trials: the expected severity of the tail.

TVaR is also known as **[Conditional Tail Expectation (CTE)](https://reinsurance.dev/glossary/#cte-conditional-tail-expectation)** and **[Expected Shortfall (ES)](https://reinsurance.dev/glossary/#es-expected-shortfall)**. For continuous loss distributions, the three names describe the same quantity. On a discrete distribution, and every empirical trial set is discrete, the three differ at ties and at the tail boundary. CTE conditions on the loss value ("all trials with loss at or above VaR"), which at a tie includes more than $k$ trials and can fail the [sub-additivity](https://reinsurance.dev/toolkit/metrics/var-vs-tvar/#sub-additivity) property. ES, as the literature defines it, averages exactly the worst $(1-\alpha)$ of probability, which splits the boundary trial fractionally whenever $N(1-\alpha)$ is not a whole number. The rank-based tail average does neither: it averages whole trials, the worst $k$ of them, and remains sub-additive.[^artzner] This site computes the rank-based average (the worst $k$ trials, defined below), whichever of the three names appears.

Unless a figure says otherwise, the numbers on this page follow the [assumptions of the Metrics overview](https://reinsurance.dev/toolkit/metrics/): the aggregate exceedance probability (AEP) basis, results at 100%, and the [20-trial demo tier](https://reinsurance.dev/toolkit/trials/#demo-scale).

## Definition and implementation

### Formal definition

$$
\text{TVaR}_\alpha = \frac{1}{k} \sum_{r=1}^{k} L_{(r)}
$$

where $k = \lfloor (1 - \alpha) \cdot N \rfloor$ is the number of tail trials and $L_{(r)}$ is the $r$-th largest loss (rank $r$ in the descending [exceedance probability (EP) curve](https://reinsurance.dev/toolkit/distributions/)). In words: take the worst $k$ trials and average their losses. The connection to $\alpha$ is through $k$: a higher confidence level means fewer but more extreme tail trials. TVaR inherits both VaR conventions: it averages observed losses, and at $k = 0$ it is undefined rather than the maximum.

### Business interpretation

TVaR is the expected loss conditional on being in the tail. It answers the chief underwriting officer's (CUO's) question: "If we have a bad year, one of the worst $(1-\alpha)$, how bad is it on average?"

### What this means in code

Python (`python/caldera_re/tvar.py`, runnable on the web page):

```python
from caldera_re.aep import aep
from caldera_re.data import cedents
from caldera_re.report import fields
from caldera_re.utils import ep_index

def tvar(curve, alpha):
    """Compute TVaR at confidence level alpha from an EP curve.

    The EP curve is sorted descending by loss (rank 1 = largest).
    TVaR at alpha is the mean of the worst k trials,
    where k = ep_index(N, alpha).

    Same conventions as VaR: an average of observed losses, and at
    k = 0 the quote does not exist (NaN), rather than the maximum.
    """
    N = len(curve)
    k = ep_index(N, alpha)
    if k < 1:
        return float('nan')
    return curve.iloc[:k]['loss'].mean()

if __name__ == '__main__':
    from caldera_re.var import var

    curve = aep(cedents.suncoast)

    for alpha in [0.80, 0.90, 0.95]:
        v = var(curve, alpha)
        tv = tvar(curve, alpha)
        k = ep_index(len(curve), alpha)
        tail = curve.iloc[:k]
        print(f"At alpha = {alpha:.0%} ({k} tail trials):")
        print(f"  Tail losses: "
              + ", ".join(f"{x:.1f}M" for x in tail['loss']))
        fields([('VaR', v, 'the threshold'),
                ('TVaR', tv, f"mean of worst {k}")], indent=2, sep=' = ')
        print()
```

:::note[In Practice]
The tail metrics read one sorted vector. Reducing a year event loss table ([YELT](https://reinsurance.dev/glossary/#yelt-year-event-loss-table)) to trial totals is one grouping ($O(R)$ over the rows with a hash grouping; pandas sorts its keys by default). Sorting the $N$ trial totals costs $O(N \log N)$, and everything after it is $O(N)$ or less (VaR is one lookup, TVaR one mean over $k$ entries, the whole EP curve one pass). That is why the site's helpers take a curve and never rebuild one: sort once, reuse the curve. When only the tail is wanted, `np.partition` selects the worst $k$ trials in $O(N)$ without a full sort. The cost that matters in production is not one distribution but many: at [10,000 to 1,000,000+ trials](https://reinsurance.dev/toolkit/trials/#demo-scale) and a few thousand layers, the sorted curve per layer is the cacheable intermediate, and the memory is one float per trial per layer. [At production scale](https://reinsurance.dev/applications/production-scale/) gives the numbers.
:::

:::tip[Key Insight]
**TVaR is preferred over VaR for capital decisions.** VaR answers "what is the threshold?" TVaR answers "how bad is it when things go wrong?" For a reinsurer managing tail risk, the second question is more relevant. Two portfolios with the same VaR can have very different TVaRs: the one with the heavier tail is more dangerous and needs more capital.
:::

*[Interactive figure: Caldera metrics chart. See the web page: https://reinsurance.dev/toolkit/metrics/tail-value-at-risk/]*

The preference also has a formal basis: [VaR of a combined distribution can exceed the sum of the standalone VaRs, and TVaR cannot](https://reinsurance.dev/toolkit/metrics/var-vs-tvar/#sub-additivity).

[^artzner]: Philippe Artzner, Freddy Delbaen, Jean-Marc Eber, and David Heath, ["Coherent Measures of Risk"](https://onlinelibrary.wiley.com/doi/full/10.1111/1467-9965.00068), *Mathematical Finance* 9(3), 1999. Introduces the coherence axioms and shows that tail conditional expectation is not sub-additive in general. Carlo Acerbi and Dirk Tasche, ["On the Coherence of Expected Shortfall"](https://arxiv.org/abs/cond-mat/0104295), *Journal of Banking & Finance* 26(7), 2002. Pins down exactly where the definitions diverge on discrete distributions and proves the averaging form coherent.
