P1: JYS
c06 JWBK378-Fletcher May 12, 2009 18:55 Printer: Yet to come
82 Financial Modelling in Python
Dec-29,
1000000.000000, JPY, [2008-Dec-29, 2009-Jun-29], basis
30360, 2009-
Jun-29,
1000000.000000, JPY, [2009-Jun-29, 2009-Dec-29], basis
30360, 2009-
Dec-29,
1000000.000000, JPY, [2009-Dec-29, 2010-Jun-29], basis
30360, 2010-
Jun-29,
1000000.000000, JPY, [2010-Jun-29, 2010-Dec-29], basis
30360, 2010-
Dec-29,
1000000.000000, JPY, [2010-Dec-29, 2011-Jun-29], basis
30360, 2011-
Jun-29,
1000000.000000, JPY, [2011-Jun-29, 2011-Dec-29], basis
30360, 2011-
Dec-29,
1000000.000000, JPY, [2011-Dec-29, 2012-Jun-29], basis
30360, 2012-
Jun-29,
1000000.000000, JPY, [2012-Jun-29, 2012-Dec-31], basis
30360, 2012-
Dec-31,
1000000.000000, JPY, [2012-Dec-31, 2013-Jun-28], basis
30360, 2013-
Jun-28,
1000000.000000, JPY, [2013-Jun-28, 2013-Dec-30], basis
30360, 2013-
Dec-30,
1000000.000000, JPY, [2013-Dec-30, 2014-Jun-30], basis
30360, 2014-
Jun-30,
1000000.000000, JPY, [2014-Jun-30, 2014-Dec-29], basis
30360, 2014-
Dec-29,
1000000.000000, JPY, [2014-Dec-29, 2015-Jun-29], basis
30360, 2015-
Jun-29,
1000000.000000, JPY, [2015-Jun-29, 2015-Dec-29], basis
30360, 2015-
Dec-29,
1000000.000000, JPY, [2015-Dec-29, 2016-Jun-29], basis
30360, 2016-
Jun-29,
1000000.000000, JPY, [2016-Jun-29, 2016-Dec-29], basis
30360, 2016-
Dec-29,
1000000.000000, JPY, [2016-Dec-29, 2017-Jun-29], basis
30360, 2017-
Jun-29,
6.3 ADJUVANTS
A financial payoff can depend on constants that vary over time, such as a gearing or barrier
level. The class adjuvant
table in module ppf.core.adjuvant table provides a
simple structure for storing these time-dependent constants. The class is constructed by taking
a list of keys, or equivalently variable names, the dates on which they apply, and the values.
Access to a particular constant at a specific time is provided via the function call operator.
class adjuvant table:
def
init (self, keys, dates, values):
if len(values.shape) <>2:
raise RuntimeError, "expected 2d array of values"
if len(keys) <> values.shape[0] or len(dates) <>
values.shape[1]:
raise RuntimeError, "incorrect size of values array"
P1: JYS
c06 JWBK378-Fletcher May 12, 2009 18:55 Printer: Yet to come
Data Model 83
self. table = {}
i=0
for key in keys:
elem = {}
j=0
for dt in dates:
elem[dt.julian
day()] = values[i][j]
j+=1
self.
table[key] = elem
i+=1
def
call (self, key, dt):
if self.
table.has key(key):
elem = self.
table.get(key)
if elem.has
key(dt.julian day()):
return elem.get(dt.julian
day())
else:
raise RuntimeError, \
"unable to find date in adjuvant table"+" dt = "+str(dt)
else:
raise RuntimeError, "unable to find key in adjuvant table"
def
str (self):
return self.
table. str ()
A high-level generator for adjuvant tables is provided in the ppf.core.generate
adjuvant table module.
def generate adjuvant table(
keys
, tenors
, values
, start
date
, roll
period = 6
, roll
duration = ppf.date time.months
, holiday
centres = None
, shift
method = ppf.date time.shift convention.modified following
, *arguments
, **keywords):
if len(values.shape) <>2:
raise RuntimeError, "expected 2d array of values"
if len(keys) <> values.shape[0] or len(tenors) <> values.shape[1]:
raise RuntimeError, "incorrect size of values array"
from ppf.date
time import days
shift = ppf.date
time.shift
day=0
dates = []
indices = []
cnt=0
start = start
date

Get Financial Modelling in Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.