Solution (source code)

= Solution

Multiplying the likelihood by the <gamma distribution> prior density gives
$$
\begin{aligned}
\pi(\theta\mid x_1,\ldots,x_n)
&\propto
\theta^n e^{-\theta S_n}
\theta^{\alpha-1}e^{-\beta\theta}\\
&=\theta^{\alpha+n-1}
e^{-(\beta+S_n)\theta}.
\end{aligned}
$$
Thus <Gamma-exponential conjugacy> gives
$$
\boxed{
\theta\mid X_1,\ldots,X_n
\sim\operatorname{Gamma}(\alpha+n,\beta+S_n),}
$$
where the second parameter is the rate. Under <squared-error loss>, the <Bayes estimator under squared error loss> is the <posterior mean>, hence
$$
\boxed{
\widehat\theta_\pi
=\frac{\alpha+n}{\beta+S_n}.}
$$