# Instrument valuation using Monte Carlo simulation with Quantlib

I am looking for some example to value an American swaption using monte carlo simulation of Hull-white short model with Quantlib.

There is a list of various pricing engines available in https://quantlibjl.readthedocs.io/en/latest/pricing_engines.html, although it is with Python. However there is no mention of the simulation approach.

There is a similar discussion available in https://quantlib.wordpress.com/2015/06/27/xva-for-bermudan-swaptions/#respond. This suggested to build a pricing engine in the line of -

boost::shared_ptr<PricingEngine> mcEngine =
MakeMcGaussian1dNonstandardSwaptionEngine<>(gsrFixed)
.withSteps(1) // the gsr model allows for large steps
.withSamples(10000)
.withSeed(42)
.withCalibrationSamples(10000)
.withProxy(true);


However I failed to find any class called MakeMcGaussian1dNonstandardSwaptionEngine in the Quantlib's git repository. So, where does this class MakeMcGaussian1dNonstandardSwaptionEngine come from?

There is also a discussion in American Swaption Pricing with Monte-Carlo method. However the link given in the solution appears to be broken.

Any pointer towards simulation approach for American swaption pricing with C++ or Python will be very helpful

• Just to be sure, you want an American Swaption, not a Bermudan Swaption, right? – rvignolo Oct 6 '20 at 16:38
• Ideally, I want an approach which will allow me to price all types of exercises. However presently I am focusing on American. – Daniel Oct 6 '20 at 17:11
• Both the choice of Hull-White, and of Monte Carlo, are inadvisable for professional work on bermudan or american exercise swaptions. If you are just playing around or doing academic work, they can be OK for that, and you will need something like Longstaff-Schwarz. It's not very fast or accurate, but it works. – Brian B Oct 6 '20 at 17:22
• @BrianB This is not for any professional work, rather academic. I agree with your comment. – Daniel Oct 6 '20 at 17:24
• do you think if there is any possibility that Quantlib will be able to handle this? – Daniel Oct 7 '20 at 7:03

Any reason why you want the valuation using Monte Carlo instead of trees?

Here is an example using python. After you setup you swaption:

import QuantLib as ql

calendar = ql.TARGET()
today = ql.Date().todaysDate()
yts = ql.YieldTermStructureHandle(ql.FlatForward(today, 0.01, ql.Actual360()))
exerciseDate = calendar.advance(today, ql.Period('5y'))
exercise = ql.AmericanExercise(today, exerciseDate)
swap = ql.MakeVanillaSwap(ql.Period('5y'), ql.Euribor6M(yts), 0.01, ql.Period('5y'))
swaption = ql.Swaption(swap, exercise)


You can value the swaption using a Tree and a short rate model:

model = ql.HullWhite(yts)
engine = ql.TreeSwaptionEngine(model, 10)
swaption.setPricingEngine(engine)
swaption.NPV()


This example is missing the step of calibrating the model parameters and is using the default ones. After calibrating, this approach would allow you to approximate the price for a given set of parameters, although don't be using it to manage risk. Notice Bloomberg uses the HW1F factor model in it's SWPM pricer for American swaption, although with time varying vols. These bloomberg pricers are good for a quick approximation to the market

For a better model you can also check out the examples in the QuantLib github (https://github.com/lballabio/QuantLib-SWIG/blob/master/Python/examples/gaussian1d-models.py) to see how you can calibrate a One factor gaussian model swaption engine.

Without going into the calibration, here is how you could use it for a given set of parameters.

stepDates = [calendar.advance(today, n, ql.Years) for n in range(1,6)]
sigmas = [ql.QuoteHandle(ql.SimpleQuote(0.01)) for x in range(1, 7)]
reversion = [ql.QuoteHandle(ql.SimpleQuote(0.01))]

gsr = ql.Gsr(yts, stepDates, sigmas, reversion)
swaptionEngine = ql.Gaussian1dSwaptionEngine(gsr, 64, 7.0, True, False, yts)

swaption.setPricingEngine(swaptionEngine)
swaption.NPV()

• Thanks. But I wan monte carlo as I am writing a report on valuations w.r.t. various approaches and one of them is MC. Besides, above code fails to generate NPV with error RuntimeError: cannot roll the asset back to5.07222 (it is already at t = 3.28333). Appreciate for any insight on MC approach. – Daniel Oct 8 '20 at 11:31