Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
Exp has capital E (like all Mathematica functions). –  b.gatessucks Jan 18 '13 at 9:04
    
Thank you very much b.gatessucks! –  James S. Jan 18 '13 at 9:12
add comment

1 Answer 1

With cleaned-up version of of your code

 (* Declaring constants: Constants->{kappa,theta,sigma,gamma,b,dt,Uy,J,phi,lambda} *)
 (* how about a and v ?*) 
 aa[uv_] := (-(\[Kappa]*\[Theta])/(\[Sigma]^2))*((\[Gamma] + b)*dt + 
  2*Log[1 - ((\[Gamma] + b + (\[Sigma]^(2))*uv)/(2*\[Gamma]))*(1 -
         Exp[-\[Gamma]*dt])]) + (Exp[y*j] - 1 - y*\[Phi]*j)*\[Lambda]*dt;
 bb[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[aa[uv]]*(1 - bb[uv]/\[Omega])^(-v)

using

EVPsi'[uv] /. uv -> 0

gives

enter image description here

Related material from the Documentation Center:

MomentGeneratingFunction

enter image description here

Moment

enter image description here

share|improve this answer
    
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? –  James S. Jan 18 '13 at 9:29
    
@JamesS., my pleasure. Welcome to Mathematica.SE. –  kguler Jan 18 '13 at 9:34
1  
@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. –  kguler Jan 18 '13 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$.) –  whuber Jan 18 '13 at 16:04
    
@kguler whuber Thank you very much guys for your precious suggestions! –  James S. Jan 20 '13 at 19:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.