# Computing the entropic risk measure symbolically in MMA

Using the link Definition, it is possible to compute the entropic risk measure as follows: $$EVaR=\text{inf}_{z>0}\{z^{-1}\ln\left(\frac{M_X(z)}{\alpha}\right)\},$$ wherein $$X$$ is a random variable having a given distribution, $$\alpha$$ is the confidence level, and $$M_X(z)$$ is the moment generating function (MGF).

Hopefully since we have a command for MDF, I write the following lines for the normal distribution:

ClearAll["Global*"]
X = NormalDistribution[\[Mu], \[Sigma]];
Mgf = MomentGeneratingFunction[X, z]
Mgf1 = Mgf/\[Alpha] // FullSimplify;
Mgf2 = PowerExpand[Log[Mgf1],
Assumptions -> {z >= 0, \[Mu] >= 0, \[Sigma] >= 0,
0 < \[Alpha] < 1}];
EVaR = Refine[1/z Mgf2,
Assumptions -> {z >= 0, \[Mu] >= 0, \[Sigma] >= 0,
0 < \[Alpha] < 1}] // FullSimplify


Unfortunately this does not lead to the correct value $$\sigma \sqrt{-2 \log (\alpha )}+\mu$$.

Can anyone give some hints here how we can get the results or get rid of the $$z$$ variable in my code output?

Thanks.

Try this:

assumptions = DistributionParameterAssumptions[X] && 0 < α < 1 && z > 0;
Assuming[assumptions,
FullSimplify @ Minimize[{EVaR, assumptions}, z]
]
(* {μ + σ Sqrt[Log[1/α^2]], {z -> Sqrt[Log[1/α^2]]/σ}} *)


edit

Since Minimize is not going to work for every distribution, you can use this function to get the EVaR for numeric distributions and numeric values of α:

EntropicValueAtRisk[dist_?DistributionParameterQ, α_?NumericQ] /;
NumericQ[RandomVariate[dist]] := Module[{
mgf = MomentGeneratingFunction[dist, \[FormalZ]],
assumptions
},
assumptions = Simplify[DistributionParameterAssumptions[dist] && \[FormalZ] > 0 && mgf > 0];
NMinimize[
{
FullSimplify[1/\[FormalZ] Log[mgf/α], Assumptions -> assumptions],
assumptions
},
\[FormalZ]
]
];

EntropicValueAtRisk[UniformDistribution[], 0.5]
(* {0.815172, {\[FormalZ] -> 5.26208}} *)

• Thanks. This line helps to get the results but why the whole code still does not give a same output for the UniformDistribution[{a,b}] as in the link of the question? – Fazlollah Feb 19 at 17:39
• It just looks like Minimize can't find the minimum for that expression, unfortunately. If you give specific values for a, b and α, you can use NMinimize to find the minimum. – Sjoerd Smit Feb 20 at 9:28
• Your edited response sounds much more useful. Is it possible to Compile your function so as to gain some speed while we call it in a loop? – Fazlollah Feb 20 at 14:13
• NMinimize already compiles expressions internally wherever it can, so there's little point in trying to write your own compilation of this code since NMinimize is going to be the slowest step. The only optimization that makes sense here, is to use symbolic results from Minimize where possible (and then substitute parameter values) and only use NMinimize where necessary. – Sjoerd Smit Feb 20 at 14:29
• Another optimization you could attempt, is to pre-compute a number of values of α for a given distribution and then use Interpolation to interpolate those values so you can get other α values more quickly (approximately). FunctionInterpolation` might also work here (though it can be a bit flaky sometimes). – Sjoerd Smit Feb 20 at 14:37