|
From: Ngonidzashe F. <ngo...@gm...> - 2018-02-24 18:57:27
|
Dear QuantLib Users,
I am modelling an option with Bermudan Exercise. I would like the holder of
the option to be able to exercise the option any date between two dates.
How do I adjust my bermudanDates object to suit that. The code is shown
below;
from QuantLib import *
# global data
todaysDate = Date(1,January,2000) #today's date
Settings.instance().evaluationDate = todaysDate #set valuation date
settlementDate = Date(1,January,2000)
riskFreeRate = FlatForward(settlementDate, 0.0481, Actual365Fixed()) #set
risk-free rate
# option parameters
*bermudanDates =[Date(31,December,2002),Date(31,December,2004)] #adjust
here*
exercise = BermudanExercise(bermudanDates) #set exercise type and maturity
date i.e. European,American or Bermudan
payoff = PlainVanillaPayoff(Option.Call, 83.45) #set option type and strike
price
# market data
underlying = SimpleQuote(139.08) #set current stock price
volatility = BlackConstantVol(todaysDate, TARGET(), 0.25023,
Actual365Fixed()) #set volatility of stock
dividendYield = FlatForward(settlementDate, 0.0374, Actual365Fixed()) #set
dividend yield of stock
# report
header = '%19s' % 'method' + ' |' + \
' |'.join(['%17s' % tag for tag in ['value'] ])
#print('')
print(header)
print('-'*len(header))
#refValue = None
def report(method, x):
x = '%.5f' % x
print('%19s' % method + ' |' +
' |'.join(['%17s' % y for y in [x] ]))
# Process
process = BlackScholesMertonProcess(QuoteHandle(underlying),
YieldTermStructureHandle(dividendYield),
YieldTermStructureHandle(riskFreeRate),
BlackVolTermStructureHandle(volatility))
option = VanillaOption(payoff, exercise)
# method: binomial
timeSteps = 801
option.setPricingEngine(BinomialVanillaEngine(process,'jr',timeSteps))
report('binomial (JR)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'crr',timeSteps))
report('binomial (CRR)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'eqp',timeSteps))
report('binomial (EQP)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'trigeorgis',timeSteps))
report('bin. (Trigeorgis)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'tian',timeSteps))
report('binomial (Tian)',option.NPV())
option.setPricingEngine(BinomialVanillaEngine(process,'lr',timeSteps))
report('binomial (LR)',option.NPV())
Regards,
Ngoni
|