
P1: JYS
c12 JWBK378-Fletcher May 28, 2009 10:59 Printer: Yet to come
188 Financial Modelling in Python
reg clsid = "{08632905-0B63-45B5-B388-30C73CAE611C}"
public methods = \
[
"CreateHullWhiteLatticePricer"
, "InvokePricer"
]
pricers = {}
retrieve = staticmethod(
lambda tag, which :
utils.retrieve(’pricer
server’, ’PricerServer’, tag, which))
def CreateHullWhiteLatticePricer(
self
, tag
, trade
id
, env
id
, num
states
, num
std dev):
try:
from trade
server import TradeServer
from market
server import MarketServer
trade = TradeServer.retrieve(trade
id, ’trades’)
env = MarketServer.retrieve(env
id, ’environments’)
model
args = {"num states": num states, "num std dev":
num
std dev}
factory = ppf.model.hull
white lattice model factory()
model = factory(trade, env, model
args)
pricer = ppf.pricer.lattice
pricer(trade, model, env, None)
PricerServer.
pricers[tag] = pricer
return tag
except RuntimeError, e: ppf.com.utils.raise
com exception(e)
def InvokePricer(self, tag):
try:
return PricerServer.retrieve(tag, ’pricers’).
call ()
except RuntimeError, e: utils.raise
com exception(e)
if
name == " main ": utils.register com class(PricerServer)
The explanations provided by the earlier sections should make the above code self-explanatory
rendering further comment unnecessary. Figure 12.6 shows an example session pricing a
Bermudan in an Excel session.
Pricer VBA Client
Here is the example client code for interfacing to the ‘ppf.pricer’ COM object. ...