
P1: JYS
c08 JWBK378-Fletcher May 12, 2009 18:58 Printer: Yet to come
118 Financial Modelling in Python
expected libors = numpy.zeros(10)
expected
libors.fill(expected libor)
expected
swaps = numpy.zeros(10)
expected
swaps.fill(expected swap)
actual
libors = ret[:, 0]
actual
swaps = ret[:, 1]
assert seq close(actual libors, expected libors)
assert seq close(actual swaps, expected swaps)
8.2 THE MODEL AND MODEL FACTORIES
The model class brings all the components from the preceding sections together into one place.
The module ppf.model.model is illustrated below. A model is constructed by passing the
components into the constructor. An exception is thrown if both the evolve component and
the rollback component are null or both the evolve and rollback components are non-null.
Accessor methods to the contained components are also provided.
class model:
def
init (self, requestor, state, fill, rollback = None,
evolve = None\ , exercise = None):
self.
requestor = requestor
self.
state = state
self.
fill = fill
self.
rollback = rollback
self.
evolve = evolve
self.
exercise = exercise
# check that either the evolve or rollback policy isn’t None
if self.
rollback == None and self. evolve == None:
raise RuntimeError, \
"either the ’rollback’ or ’evolve’ must be defined"
if self.
rollback <> None and self. evolve <> None:
raise RuntimeError, \
"either the ’rollback’ or ’evolve’ must be defined"
# check that the exercise policy can only ...