
P1: JYS
c06 JWBK378-Fletcher May 12, 2009 18:55 Printer: Yet to come
84 Financial Modelling in Python
for tenor in tenors:
end = start
date+roll duration(tenor)
if end < day:
raise RuntimeError, "tenors are not monotonically increasing"
i=0
while day < end:
roll
start = start+roll duration(i*roll period)
roll
end = start+roll duration((i+1)*roll period)
pay = shift(roll
end, shift method, holiday centres)
day = pay
dates.append(day)
indices.append(cnt)
i+=1
cnt += 1
start = end
import numpy
all
values = numpy.zeros((len(keys), len(dates)))
for i in range(len(keys)):
for j in range(len(dates)):
idx = indices[j]
all
values[i][j] = values[i][idx]
return adjuvant
table(keys, dates, all values)
A sample invocation of the generate adjuvant table() function is shown below:
>>> from ppf.date time import *
>>> from numpy import *
>>> adjuvants = generate
adjuvant table(
... keys = ["spread","coupon"]
... , tenors = [12,24,36]
... , values = array([[0.005, 0.006, 0.007], [0.05, 0.06, 0.07]])
... , start
date = date(2008, May, 1)
... , roll
period = 6
... , shift
method = shift convention.modified following)
>>> print adjuvants
{’coupon’: {2455137: 0.06, 2455683: 0.07, 2454953: 0.05,
2455502: 0.07, 2454772: 0.05, 2455318: 0.06},
’spread’: {2455137: 0.006, 2455683: 0.007,
2454953: 0.005, 2455502: 0.007,
2454772: 0.005, 2455318: 0.006}}
6.4 LEGS
In essence, a leg is simply a collection of flows. However, we also need to know whether the
cash