> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# VaR interpolation

> The percentile is a well-defined concept in the continuous case, but there are multiple ways to compute it from a discrete sample.

The percentile is a well-defined concept in the continuous case, but there are multiple ways to compute it from a discrete sample.

Consider the following example. This is a plot of the 10 smallest values in a sample of 250 values drawn from the standard normal distribution. The plot shows the theoretical 2.5% quantile of the standard normal distribution (“theo”) as well as various types of 97.5 percentile estimation (floor, ceil, weighted, etc).Â

<Frame>
  <img src="https://mintcdn.com/activeviam/gaoX7QceXzVFVfYn/solutions/market-risk/6.0/images/var-interpolation.png?fit=max&auto=format&n=gaoX7QceXzVFVfYn&q=85&s=ea4d45f2b5b25228af5fa7ecf6f931f4" alt="VaR Interpolation from discrete samples" width="872" height="296" data-path="solutions/market-risk/6.0/images/var-interpolation.png" />
</Frame>

Atoti Market Risk supports multiple types of VaR estimation, as described in this chapter.

## Calculation steps

The algorithm can be described as follows:

* Compute quantile as (1-confidence level)
* Compute adjacent ranks based on the value of the level `[Quantiles].[Quantiles].[QuantileName]`, quantile and discrete sample size
* Sort PL and obtain PL values for the adjacent ranks
  and approximate VaR from the PL values using the interpolation formula controlled by the value of the level `[Rounding].[RoundingMethods].[MethodName]`

## Computing adjacent ranks

The value of the level `[Quantiles].[Quantiles].[QuantileName]` is used to determine the rank calculation:

<table><thead><tr><th>Member value</th><th>Description</th><th>Formula for rank</th><th>Example</th><th>Notes</th></tr></thead><tbody><tr><td>Centered</td><td>Corresponds to the “First variant, C=1/2” of the interpolation variants described on this <a href="https://en.wikipedia.org/wiki/Percentile#The_linear_interpolation_between_closest_ranks_method">wiki</a></td><td>$x = quantile * vectorSize + 0.5$</td><td>(1-97.5%) x 250 + 0.5 = 6.75</td><td /></tr><tr><td>Equal Weight</td><td>Corresponds to the “Third variant, C=0” of the interpolation variants described on this <a href="https://en.wikipedia.org/wiki/Percentile#The_linear_interpolation_between_closest_ranks_method">wiki</a></td><td>$x = quantile * (vectorSize+1)$</td><td>(1-97.5%)x (250+1) = 6.275</td><td>default option</td></tr><tr><td>Exclusive</td><td /><td>$x = quantile * (vectorSize+1)-1$</td><td>(1-97.5%)x (250+1)-1 = 5.275</td><td /></tr><tr><td>Simple</td><td /><td>$x = quantile * vectorSize$</td><td>(1-97.5%)x 250 = 6.25</td><td /></tr></tbody></table>

Based on the computed rank $x$, we can obtain various adjacent ranks:

* $x_{lower}$ = $round_{down}(x)$
* $x_{higher}$ = $round_{up}(x)$
* $x_{nearest}$ = $round(x)$
* $x_{nearestEven}$ = $round_{toEven}(x)$
* $weight$ = $fractionalPart(x)$

and the corresponding P\&L values (in the sorted P\&L vector):

* $PL_{lower}$ as the value of the sorted P\&L vector at rank $x_{lower}$
* $PL_{higher}$ as the value of the sorted P\&L vector at rank $x_{higher}$
* $PL_{nearest}$ as the value of the sorted P\&L vector at rank $x_{nearest}$
* $PL_{nearestEven}$ as the value of the sorted P\&L vector at rank $x_{nearestEven}$

## VaR approximation

The value of the level `[Rounding].[RoundingMethods].[MethodName]` is be used to control the interpolation.

<table><thead><tr><th>Property value</th><th>Description</th><th>Formula for VaR</th><th>Example</th><th>Notes</th></tr></thead><tbody><tr><td>Floor</td><td>Simulated PL for the lower of the adjacent ranks</td><td>VaR = $PL_{lower}$</td><td>For $x$ = 6.25, the PL value at rank 6 is taken as the VaR.</td><td /></tr><tr><td>Ceil</td><td>Simulated PL for the higher of the adjacent ranks</td><td>VaR = $PL_{higher}$</td><td>For $x$ = 6.25, the PL value at rank 7 is taken as the VaR.</td><td>default option</td></tr><tr><td>Weighted</td><td>Simulated PL linearly interpolated between the adjacent ranks</td><td>VaR = $weight * PL_{lower} + (1-weight) * PL_{higher}$</td><td>For $x$ = 6.25, the linear interpolation beween PL value at rank 6 and PL value at rank 7 at the point $x$ = 6.25 is taken as the VaR.</td><td /></tr><tr><td>Round</td><td>Simulated PL for the nearest rank</td><td>VaR = $PL_{nearest}$</td><td>For $x$ = 6.25, the PL value at rank 6 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 6.75, the PL value at rank 7 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 7.5, the PL value at rank 8 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 8.5, the PL value at rank 9 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 9.5, the PL value at rank 10 is taken as the VaR.</td><td /></tr><tr><td>Round Even</td><td>Simulated PL for the nearest rank with rounding half to even</td><td>VaR = $PL_{nearestEven}$</td><td>For $x$ = 6.25, the PL value at rank 6 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 6.75, the PL value at rank 7 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 7.5, the PL value at rank 8 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 8.5, the PL value at rank 9 is taken as the VaR.</td><td /></tr><tr><td /><td /><td /><td>For $x$ = 9.5, the PL value at rank 10 is taken as the VaR.</td><td /></tr></tbody></table>
