
P1: JYS
c05 JWBK378-Fletcher May 12, 2009 16:54 Printer: Yet to come
64 Financial Modelling in Python
0.522045776761
0.496585303791
0.472366552741
0.449328964117
0.427414931949
0.406569659741
0.386741023455
0.367879441171
0.349937749111
5.2 SURFACES
A surface is the common name ascribed to a model of a multivariabled function. In the interest
of brevity, we restrict our attention to modelling functions in just two variables f = f (x, y).
The ppf.market.surface module offers the class surface for their representation,
which is associated with the commonly encountered bilinear–interpolation scheme that relies
on the ppf.utility.bound function (refer to section 4.3):
import ppf.utility
class surface:
def
init (self, first axis, second axis, values):
self.
first axis = first axis
self.
second axis = second axis
self.
values = values
def
call (self, x, y):
i1, i2 = ppf.utility.bound(x, self.
first axis)
j1, j2 = ppf.utility.bound(y, self.
second axis)
f = self.
values
x1 = self.
first axis[i1]
x2 = self.
first axis[i2]
y1 = self.
second axis[j1]
y2 = self.
second axis[j2]
r = (x2 - x1)*(y2 - y1)
return (f[i1, j1]/r)*(x2 - x)*(y2 - y) + \
(f[i2, j1]/r)*(x - x1)*(y2 - y) + \
(f[i1, j2]/r)*(x2 - x)*(y - y1) + \
(f[i2, j2]/r)*(x - x1)*(y - y1)
The ppf.test.test market module provides us with an example of using instances of
this type for surface representation, in this case an expiry-tenor volatility surface:
class surface tests(unittest.TestCase): ...