# Computing derivatives of a moment generating function

Dear Mathematica users,

I'm trying to compute higher order derivatives of a moment generating function and then evalutate them in 0 (in order to get some moment conditions for a GMM estimation). Although I try to declare constants at the beginning of my script, which follows:

% Declaring constants
Constants -> {kappa, theta, sigma, gamma, b, dt, Uy, J, phi, lambda}

%
A[Uv_] = (-(kappa *theta)/(sigma^2))*((gamma + b)*dt +
2*Log[1 - ((gamma + b + (sigma^(2))*Uv)/(2*gamma))*(1 -
exp[-gamma*dt])]) + (exp[Uy*J] - 1 - Uy*phi*J)*lambda*dt;

%
B[Uv_] = -(a*(1 - exp[-gamma*dt]) -
Uv*(2*gamma - (gamma - b)*(1 - exp[-gamma*dt])))/(2*
gamma - (gamma + b)*(1 - exp[-gamma*dt]) -
Uv*(sigma^(2))*(1 - exp[-gamma*dt]));

% My moment generating function
EVPsi[Uv_] = exp[A[Uv]]*(1 - B[Uv]/omega)^(-v)


My problem is due to the fact that when I compute the first order derivative by using

EVPsi'[Uv] /. Uv -> 0


I get the following expression

% First derivative of the mgf evalueated in Uv=0
-v (1 + (a (1 - exp[-dt gamma]))/(
omega (2 gamma - (b + gamma) (1 - exp[-dt gamma]))))^(-1 -
v) (-((2 gamma - (-b + gamma) (1 - exp[-dt gamma]))/(
omega (2 gamma - (b + gamma) (1 - exp[-dt gamma])))) + (
a sigma^2 (1 - exp[-dt gamma])^2)/(
omega (2 gamma - (b + gamma) (1 - exp[-dt gamma]))^2)) exp[
dt lambda (-1 - J phi Uy + exp[J Uy]) - (
kappa theta (dt (b + gamma) +
2 Log[1 - ((b + gamma) (1 - exp[-dt gamma]))/(2 gamma)]))/
sigma^2] + (
kappa theta (1 + (a (1 - exp[-dt gamma]))/(
omega (2 gamma - (b + gamma) (1 - exp[-dt gamma]))))^-v (1 -
exp[-dt gamma]) Derivative[1][exp][
dt lambda (-1 - J phi Uy + exp[J Uy]) - (
kappa theta (dt (b + gamma) +
2 Log[1 - ((b + gamma) (1 - exp[-dt gamma]))/(2 gamma)]))/
sigma^2])/(
gamma (1 - ((b + gamma) (1 - exp[-dt gamma]))/(2 gamma)))


What I'm missing here is why I get in the last lines an expression such as

Derivative[1][exp][product of constants!!]


instead of a 0.

I would be thankful if you could shed some light on this. Thank you.

• Exp has capital E (like all Mathematica functions). Jan 18, 2013 at 9:04
• Thank you very much b.gatessucks! Jan 18, 2013 at 9:12
• % does not delimit a comment. Sep 22, 2016 at 23:16

With cleaned-up version of of your code

 (* Declaring constants: Constants->{κ,θ,σ,γ,b,dt,Uy,J,ϕ,λ} *)
(* how about a and v ?*)
aa[uv_] := (-(κ*θ)/(σ^2))*((γ + b)*dt +
2*Log[1 - ((γ + b + (σ^(2))*uv)/(2*γ))*(1 -
Exp[-γ*dt])]) + (Exp[y*j] - 1 - y*ϕ*j)*λ*dt;
bb[uv_] := -(a*(1 - Exp[-γ*dt]) -
uv*(2*γ - (γ - b)*(1 -
Exp[-γ*dt])))/(2*γ - (γ + b)*(1 -
Exp[-γ*dt]) -  uv*(σ^(2))*(1 - Exp[-γ*dt]));
(* My moment generating function *)
EVPsi[uv_] := Exp[aa[uv]]*(1 - bb[uv]/ω)^(-v)


using

EVPsi'[uv] /. uv -> 0


gives

Related material from the Documentation Center:

MomentGeneratingFunction

Moment

• Kguler, thank you for your reply! I managed to fix it. Actually, v and Uv are different. v is a constant, while Uv is my variable. Can Mathematica confuse between them? Should I change the v? Jan 18, 2013 at 9:29
• @JamesS., my pleasure. Welcome to Mathematica.SE.
– kglr
Jan 18, 2013 at 9:34
• @JamesS., updated removing the part that replaces v with uv. It is a good idea to get in the habit of using variables and functions that start with lowercase letters to avoid possible conflicts with built-in Mathematica functions.
– kglr
Jan 18, 2013 at 9:55
• (+1) k! SeriesCoefficient[EVPsi[t], {t, 0, k}] will compute the kth moment. (With this particular function EVPsi, and keeping the constants as unevaluated symbols, be prepared to wait a while when k exceeds $4$,though. The case $k=4$ took 76 seconds and timing approximately doubles for each increment in $k$.) Jan 18, 2013 at 16:04
• @kguler whuber Thank you very much guys for your precious suggestions! Jan 20, 2013 at 19:31