Customized version of PERCENTILE_CONT
Antonio Savoldi, September 02, 2015 - 9:19 am UTC
>> An explanation of why the existing percentile_cont doesn't provide the results you want
The existing version of PERCENTILE_CONT cannot be used for calculating VaR (Value at Risk), as required by PRISMA margining methodology. As specified in the documentation of the methodology, provided by EUREX (European Derivative Market), the Var figures are quantiles of profit and loss distributions.
The profit and loss distribution can be mathematically expressed as a vector, in which each element represents the profit and loss calculated froma given set of scenario pricesand current prices. Each component of the profit and loss vector being sorted in ascending order represents a specific quantile of the empirical distribution. The quantile qi represented by the i-th component of the sorted profit and loss vector can be calculated according to qi = 100%(i - 0.5) / L where L denotes the length ofthe profit and loss vector.
In case the (100% − cl) quantile is exactly represented by a single component of the subsample profit and loss vector, this component will be the VaR figure.
In case the (100% − cl) quantile lies between two quantiles of the profit and loss distribution, it will be interpolated linearly using the next highest(q+) and next lowest quantile(q-) of the profit and loss distributionand the associated components of the profit and loss vector,denotesas PL(q+) qnd PL(q-) accordingto the formula:
VaR(cl) = {[(q+ - (100% - cl)) / (q+ - q-)] * PL(q-) + [((100% - cl) - q-) / (q+ - q-)] * PL(q+)} * (-1)
In case (100 − cl) is smaller than the quantile associated with the first component, the VaR will be given as thefirst component. In case it is bigger than the quantile associated with the last component, the VaR will be given asthe last component.
A positive VaR figure indicates a loss. The VaR figures utilized for the calculation of the initial margin will always be bounded below by zero. Every negative VaR, representing again, will be set to zero.
Example
i PL Components Quantile qi
1 -4000 100% * (1 - 0.5) = 10%
2 -3800 30%
3 -3700 50%
4 -3500 70%
5 -3200 90%
For instance VaR(10%) = -4000 whereas Var(80%) = 3900 (by appling the above formula). Oracle, with the built-in PERCENTILE_CONT, provides 3840.
September 18, 2015 - 3:23 am UTC
Thanks for the clarification
Aggregate Functions
David, September 02, 2015 - 1:04 pm UTC
quantile rebasement
Antonio Savoldi, September 02, 2015 - 2:05 pm UTC
There's no reason to re-do the wheel, at least in this case. I sorted out that I can rebase the quantile and convert it to row-numbwer, by obtaining, as a result, the confidence level that I need for Oracle PERCENTILE_COUNT function.
For instance:
RN = 1 + P(N - 1)
but
RN = (N x qd) / 100 + 0.5
therefore
P = (N x qd / 100 - 0.5) / (N - 1)
if qd = 3, N = 188, P will be equal to 0,0274866, which is exactly the confidence level that placed in the function gives the same results of the other function (based on quantile).
Thanks again,
Regards.
Tony
September 02, 2015 - 4:57 pm UTC
Great to hear! I (Chris) am not familiar with these calculations so was struggling to figure out what exactly to do here.