
P1: JYS
c06 JWBK378-Fletcher May 12, 2009 18:55 Printer: Yet to come
88 Financial Modelling in Python
self. legs = legs
self.
exercise info = exercise info
def legs(self):
return self.
legs
def exercise
type(self):
if not self.
exercise info:
raise RuntimeError, "missing exercise information"
return self.
exercise info[1]
def exercise
schedule(self):
if not self.
exercise info:
raise RuntimeError, "missing exercise information"
return self.
exercise info[0]
def has
exercise schedule(self):
return self.
exercise schedule != None
The following snippet shows a simple example of how to assemble a trade:
>>> #semi-annual flows
>>> flows = generate
flows(
... start = date(2007, Jun, 29)
... , end = date(2017, Jun, 29)
... , duration = ppf.date
time.months
... , period = 6
... , shift
method = shift convention.modified following
... , basis = "ACT/360")
>>> pay
leg = leg(flows, PAY)
>>> receive
leg = leg(flows, RECEIVE)
>>> #1y nc
>>> ex
sched = generate exercise table(
... start = date(2008, Jun, 29)
... , end = date(2016, Jun, 29)
... , period = 1
... , duration = ppf.date
time.years
... , shift
method = shift convention.modified following)
>>> structure = trade([pay
leg, receive leg], [ex sched, \
exercise
type.callable])
>>> print ("callable", "cancellable")[structure.exercise
type()
== -1]
callable
6.7 TRADE UTILITIES
It is not uncommon to perform standard operations on the trade representation. For example,
the writer of a pricing model