Beginner really needs help with Maxima's basic concepts
Subject: Beginner really needs help with Maxima's basic concepts
From: Leo Butler
Date: Sat, 14 Nov 2009 08:35:46 +0000 (GMT)
On Sat, 14 Nov 2009, Julien Martin wrote:
< Hello Leo,
<
< Thanks a lot for your detailed reply and accept my apologies for my late follow-up.
<
< Your code is very useful indeed and I understand most of it save for the syntax of the solve function as in here:
< peq : solve(p='p,exp(r*T));
<
< I figured out from the documentation that 'p prevents the evaluation of p. Now what does it mean to have an equation defined as:
< "the evaluated value of p"="the non evaluated value of p"??
<
< I expected something like:
< "the evaluated value of p"=0
<
< This is what I cannot work out from the documentation...
I could have written
peq : solve((exp(r*T)-d)/(u-d)='p , exp(r*T));
which solves for exp(r*T) in terms of 'p. To solve your problem,
it was necessary to do something like that. You can see what is
happening:
(%i1) p:(exp(r*T)-d)/(u-d);
(%o1) (%e^(r*T)-d)/(u-d)
(%i2) p='p;
(%o2) (%e^(r*T)-d)/(u-d) = p
Leo
<
< Julien.
<
< 2009/11/11 Leo Butler <l.butler at ed.ac.uk>
<
<
< On Tue, 10 Nov 2009, Julien Martin wrote:
<
< < Hello,
< <
< < I am working on the binomial model and my example is based on that but really my question relates to Maxima's basic concepts.
< <
< < Here is my example:
< <
< < I have %Delta and p defined as follows:
< <
< < %Delta:(fu-fd)/(S0*u-S0*d); (1)
< <
< < p:(exp(r*T)-d)/(u-d); (2)
< <
< < I need to have the following expression (3) simplified by replacing the %Delta with the expression given above in (1) and expressed in terms of p as
< defined above
< < in (2)...
< <
< < f:S0*%Delta*(1-u*exp(-r*T))+fu*exp(-r*T); (3)
< <
< < ...so that I would ideally get this:
< <
< < f:exp(-r*T)*(p*fu + (1-p) * fd); (4)
< <
< < Is this possible? Can someone please help?
< <
< < Julien.
< <
< <
<
< Julien,
< I think the key to the problem is to model your own
< manipulations. To subst p into f, you need to solve for %e^(r*T)
< in terms of p:
<
< (%i2) f:S0*%Delta*(1-u*exp(-r*T))+fu*exp(-r*T);
<
< (%o2) %Delta*S0*(1-u*%e^-(r*T))+fu*%e^-(r*T)
< (%i3) %Delta:(fu-fd)/(S0*u-S0*d);
<
< (%o3) (fu-fd)/(u*S0-d*S0)
< (%i4) p:(exp(r*T)-d)/(u-d);
<
< (%o4) (%e^(r*T)-d)/(u-d)
< (%i5) peq : solve(p='p,exp(r*T));
<
< (%o5) [%e^(r*T) = p*u-d*p+d]
< (%i6) f;
<
< (%o6) %Delta*S0*(1-u*%e^-(r*T))+fu*%e^-(r*T)
< (%i7) rpeq : 1/peq;
<
< (%o7) [%e^-(r*T) = 1/(p*u-d*p+d)]
< (%i8) subst(rpeq,f);
<
< (%o8) %Delta*(1-u/(p*u-d*p+d))*S0+fu/(p*u-d*p+d)
< (%i9) subst(rpeq,''f);
<
< (%o9) (fu-fd)*(1-u/(p*u-d*p+d))*S0/(u*S0-d*S0)+fu/(p*u-d*p+d)
< (%i10) rat(%);
<
< (%o10) ((fu-fd)*p+fd)/(p*u-d*p+d)
< (%i11) subst(rhs(peq[1])=lhs(peq[1]),%);
<
< (%o11) ((fu-fd)*p+fd)*%e^-(r*T)
<
< This final expression is almost what you want.
<
< (%i12) collectterms(expand(part(%o11,1)),fu,fd);
<
< (%o12) fu*p+fd*(1-p)
< (%i13) %*part(%o11,2);
<
< (%o13) (fu*p+fd*(1-p))*%e^-(r*T)
<
< --
< The University of Edinburgh is a charitable body, registered in
< Scotland, with registration number SC005336.
<
<
<
<
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.