
P1: JYS
c04 JWBK378-Fletcher May 23, 2009 4:21 Printer: Yet to come
Basic Mathematical Tools 49
if biga <> 0: bigb = q/biga
r1 = (biga+bigb)-a/3.0
if r1 >= xl and r1 <= xh:
roots.append(r1)
return roots
else:
return quadratic
roots(b, c, d, xl, xh)
Finally, note that in the actual implementations we only return the real roots, quadratic or
cubic, if they lie in the range [x
l
, x
h
]. Moreover we always sort the real roots. The reason for
doing this will become clear in the next section when we apply the above algorithms in the
context of integrating a polynomial.
4.8 INTEGRATION
In finance we often need to calculate the expectation of some function f : R
n
→ R of a
number of random variables X : → R
n
. Throughout this section we will only consider
financial payoffs that can be written in terms of a single random variable X : → R and
belong to the space C
3
(R), that is the space of continuous three-times differentiable functions
on R. But the following can be extended to higher dimensions with more effort.
4.8.1 Piecewise Constant Polynomial Fitting
Let X denote a random variable on R which we sample on a uniform lattice {x
1
, x
2
, ..., x
N
}
with spacing . The corresponding values of the function f on the uniform lattice are denoted
by {f
1
, f
2
, ..., f
N
}. Similarly the first, second and third derivatives of f at any node of the
lattice x
i
are denoted by f
i
, f
i
and f
i
respectively. Our aim is to fit the function ...