Twofold problem with Maxima: derivative of cdf_normal and expressing result as an expression of a var...
Subject: Twofold problem with Maxima: derivative of cdf_normal and expressing result as an expression of a var...
From: Julien Martin
Date: Thu, 29 Oct 2009 19:07:40 +0100
Leo,
Thanks!
I'll try what you suggested and keep you posted.
Julien.
2009/10/29 Leo Butler <l.butler at ed.ac.uk>
>
>
> On Thu, 29 Oct 2009, Julien Martin wrote:
>
> < Hello again,
> < No luck with "depends".
> < Since I have defined d1 and d2 above, when I input:
> < depends(d1, t, d2, t)
> < it tells me "the arguments to depends must be a symbolic name".
> <
> < Here is all that I input in the same order:
> <
> < load(distrib)
> < d1:(log(S/K)+(r+sigma^2/2)*(T-t))/(sigma*sqrt(T-t))
> < d2:d1-(sigma*sqrt(T-t))
> < C(S,t):=S*cdf_normal(d1,0,1)-K*exp(-r*(T-t))*cdf_normal(d2,0,1)
> < depends(d1, t, d2, t)
> <
> < J.
>
> You are defining d1 and d2, and then trying to tell Maxima that they
> depend on t. Try:
>
> depends([d1,d2],t);
> C(S,t):=S*cdf_normal(d1,0,1)-K*exp(-r*(T-t))*cdf_normal(d2,0,1);
> etc.
>
> -----------------
> You may also want to try something even more conceptual. You can do this
> with Maxima's rules:
>
> (%i2) matchdeclare(aa,true,bb,true,cc,true);
>
> (%o2) done
> (%i3) tellsimpafter('diff(cdfn(aa,bb,cc),aa,1),pdfn(aa,bb,cc));
>
> (%o3) [derivativerule3,?simpderiv]
> (%i4) diff(cdfn(t,a,b),t);
>
> (%o4) pdfn(t,a,b)
> (%i5) depends(d1,t);
>
> (%o5) [d1(t)]
> (%i6) diff(cdfn(d1,a,b),d1)*diff(d1,t);
>
> (%o6) pdfn(d1,a,b)*'diff(d1,t,1)
>
>
> In %i3, I tell Maxima that the derivative of this undefined function 'cdfn'
> with respect to the first variable is another undefined function 'pdfn'.
>
> In %i4, I check it, and in %i6, I implement the rule.
>
> Then, I plug in some values and let Maxima work:
>
> (%i7) subst([pdfn=normal,d1=(T-t)^2/2/sigma^2,a=0,b=1],%o6);
>
> (%o7) normal((T-t)^2/(2*sigma^2),0,1)*'diff((T-t)^2/(2*sigma^2),t,1)
> (%i8) ev(%,nouns);
>
> (%o8) -(T-t)*normal((T-t)^2/(2*sigma^2),0,1)/sigma^2
>
> I get an answer that looks like what I want. This is a more natural way
> to do your checks because you don't really need the formulae for the
> normal pdf or cdf, just a few of their properties.
>
> Leo
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>