
P1: JYS
c12 JWBK378-Fletcher May 28, 2009 10:59 Printer: Yet to come
Python Excel Integration 173
a given enviroment,
def AddConstant(self, tag, name, value):
try:
MarketServer.retrieve(tag, ’environments’).add
constant(
str(name), value)
except RuntimeError, e: utils.raise
com exception(e)
should now be readily understandable.
AddSurface
The AddSurface function uses all the tricks uncovered in the explanation of the AddCurve
method (see subsection 12.2.2):
def AddSurface(self, tag, name, expiries, tenors, values):
try:
import numpy
exp, ten = expiries[1:], tenors[1:]
surface = [x[1:] for x in values[1:]]
MarketServer.retrieve(tag,’environments’).add
surface(
str(name),
ppf.market.surface(exp, ten, numpy.array-(surface)))
except RuntimeError, e: utils.raise
com exception(e)
In this function, exp is an array of M expiries (in years), tenors an array of N tenors (in
days) and surface the surface data as an M × N array. Figure 12.4 shows how the data for
the surface might be arranged in an Excel worksheet.
Figure 12.4 Adding a surface to a market environment.