# CIR model - nth moment generation $E^*[r_T^n]$

I am analyzing the nth moment generation process for $r_t$ with dynamics defined by CIR model

$r_t$ has following dynamics $$dr_t=a(b-r_t)dt+\sigma \sqrt{r_t} dW_t^* \quad \quad (1)$$ for some constants $ab>\frac{\sigma^2}{2} \quad$

Letting T be a fixed date and $f_{\lambda}$ a function defined for some constant $\lambda >0$ is given $$f_{\lambda}(t,r)=E^*[e^{-\lambda {r_{T}}}|r_t=r] \quad \quad (2)$$

I want to generate first four moments. The solution manual suggest using the following function

$$E^*[r_T^n]=(-1)^n \ E^* \big{[} \ \frac{d^n}{d \lambda^n}e^{-\lambda r_t}\big{|}_{\lambda=0} \ \big{]}$$ $$=(-1)^n \ \frac{d^n}{d \lambda^n}e^{-\lambda r_t}\big{|}_{\lambda=0} \ \quad \quad (3)$$

I understand the general idea of using MGF to derive moments of a function. In a standard way it is calculated as $$M_t = E[e^{tX}]=\int e^{tx} \ f(x) dx \quad \quad (4)$$ and then $$M_t^{(n)}(0) \quad \quad (5)$$ would give the n-th moment.

I am confused here with couple of things. First the fact that $f_{\lambda}$ looks already like moment generating function, so in this case what is multiplied by what.
Second I don't understand how the suggested function (3) was created. The $-\lambda$ used in (3) confuses me. There is no minus in the standard moment generation function.
Finally the steps of the of the calculations using this function are unclear to me. Are derivative of $r_t$ taken directly or just of the function $e^{-\lambda}r_t$ where the r_r is substituted.

There are the first two moments of the $r_t$ I should get $$E^*[r_T^1]=b(1-e^{-at})+e^{-at}r_0$$ $$E^*[r_T^2]=e^{-2aT}[(b(1-e^{-at})+e^{-at}r_0)^2]+\frac{e^{-2aT}}{2a}[(e^{aT}-1)(b(e^{aT}-1)+2r_0)\sigma^2]$$

Your problem probably comes from the notations used.

Let the Moment Generating Function (MGF) of a random variable $X$ be defined as $$M_X(u) := E[e^{uX}]$$ From this definition, it entails that $$E(X^n) = M_X^{(n)}(u=0) = \frac{d^{n} M_X}{ d u^{n}}(u=0)$$

Knowing this, the function $$f_{\lambda}(t,r)=E[e^{-\lambda {r_{T}}}|r_t=r]$$ can be interpreted as the MGF $M_{X}(\lambda)$ of the random variable $X = (-r_T \vert\ r_t = r)$ (note the minus, and the conditioning).

Applying the definitions, we thus have that \begin{align} E[(-r_T)^n \vert r_t=r] &= \frac{d^{n} M_X}{ d \lambda^{n}}(\lambda=0) \\ &= \left. \frac{d^{n} f_{\lambda}(t,r)}{ d \lambda^{n}} \right\vert_{\lambda=0} \end{align}

Now, noticing that $$(-r_T)^n = (-1)^n\ r_T^n$$ and that multiplying or dividing a quantity by $(-1)^n$ (deterministic) is strictly equivalent $\forall n\in\mathbb{N}$ gives your manual solution $$E[r_T^n \vert r_t=r] = (-1)^n \left. \frac{d^{n} f_{\lambda}(t,r)}{ d \lambda^{n}} \right\vert_{\lambda=0}$$

Now how do you use that? Simply take the $n$-th derivative of the function $f$ with respect to $\lambda$, evaluate it for $\lambda=0$ and change sign if $n$ is odd to obtain the raw moment of order $n$.

Note that the MGF gives you raw moments, not centred moments. For centred moments you need some additional algebra. For instance, for the second centred moment ($n=2$), we could write: $$E[(X-E(X))^2] = E(X^2) - E(X)^2 = \mu_2 - \mu_1^2$$ where $\mu_i$, $i=1,2$ are the raw moments of order $i$ obtained using the MGF as explained above.