Solution (source code)

= Solution

Set $\overline F(M)=1-F_X(M)$. The <compound Poisson distribution> <variance> identity and the per-claim <excess of loss reinsurance> payouts give
$$
g(M)=\lambda\left[\int_0^M x^2f_X(x)\,dx+M^2\overline F(M)
+\int_M^\infty(x-M)^2f_X(x)\,dx\right].
$$
Apply <differentiation under the integral sign>. The endpoint terms $M^2f_X(M)$ in the first two terms cancel, while the last integrand is zero at its lower endpoint. Equivalently, differentiate the two payout squares inside their <expected values>; the finite <second moment> supplies a dominating integrable function. This gives the <total variance stationary condition for excess of loss>
$$
g'(M)=2\lambda\left[M\overline F(M)-\int_M^\infty(x-M)f_X(x)\,dx\right].
$$
Hence the specified equality makes \b[$g'(M)=0$]. When $\overline F(M)>0$, its interpretation is $M=m_X(M)$, where the <mean residual life> is $m_X(M)=\mathbb E[X-M\mid X>M]$.

For the <exponential distribution> of mean $\mu$, $\overline F(M)=e^{-M/\mu}$ and
$$
\mathbb E[(X-M)_+]=\mu e^{-M/\mu}.
$$
Thus $g'(M)=2\lambda e^{-M/\mu}(M-\mu)$ is negative below $\mu$ and positive above it. The <variance-minimizing exponential retention> is the unique global minimizer
$$
\boxed{M^*=\mu.}
$$
For an explicit value, put $m=M/\mu$. The <capped claim moments> and the excess-claim <second moment> give
$$
g(M)=2\lambda\mu^2(1-me^{-m}),\qquad
\boxed{g(\mu)=2\lambda\mu^2(1-e^{-1}).}
$$
The sign argument establishes global minimality, rather than just stationarity.