
P1: JYS
c04 JWBK378-Fletcher May 23, 2009 4:21 Printer: Yet to come
Basic Mathematical Tools 59
def rollback(self, t, T, xt, xT, xtT, ftT, yT):
# create cache of moments
self.
create cached moments(xtT, ftT)
return self.
rollback (t, T, xt, xT, xtT, yT, ftT.regrid,
ftT.integral)
def rollback
max(self, t, T, xt, xT, xtT, ftT, yT):
# create cache of moments
self.
create cached moments(xtT, ftT)
return self.
rollback (t, T, xt, xT, xtT, yT, ftT.regrid,
ftT.integral
max)
Note that we precompute the moments in the function create cached moments() prior
to performing the rollback. Doing this improves the efficiency of the algorithm dramatically
because otherwise we keep computing (unnecessarily) the moments nt times. Typically
nt ≈ 41, so you can see why we make such a huge computational saving by precomputing
the moments.
A number of tests have been written for the semi-analytic domain integrator. The tests can
be found in the module ppf.test.test
math with each separate test represented by a
method of the class integrator
tests. The first test checks that we can perform the
conditional expectation of the following classical exponential martingale correctly
5
:
y
T
= exp
σ X
T
−
1
2
σ
2
T
(4.46)
with σ ∈ R
+
. Because we know y
T
is a martingale the following identity must hold.
E[y
T
|F
t
] = exp
σ X
t
−
1
2
σ
2
t
(4.47)
The snippet of code below gives the details of the test just described.
def lognormal martingale test(self):
integrator = ppf.math.semi ...