Pricing American Swaptions with QuantLib Short-Rate Models
Summary
The document asks how to value an American swaption with Monte Carlo simulation under a Hull–White short-rate model in QuantLib. The response offers a tree-based alternative: set up the swaption, attach a Hull–White model and a tree pricing engine, then request its value. It notes that the example uses default model parameters and omits calibration, so the resulting estimate is only an illustration for a chosen parameter set.
For a model with time-varying volatility, the response also sketches a one-factor Gaussian setup with volatility step dates and a Gaussian one-dimensional swaption engine. It points to QuantLib examples for calibration guidance. The discussion does not supply the requested Monte Carlo implementation or compare numerical accuracy, and its practical pricing guidance remains limited by the missing calibration step. It suggests trees as an available route for this early-exercise product, while leaving the original simulation question unresolved.
Key ideas
- A QuantLib tree engine can value an American swaption under a Hull–White short-rate model.
- The example uses default parameters, so meaningful market pricing requires calibration.
- A Gaussian one-factor model can represent volatility changes at specified step dates.
- The response does not demonstrate a Monte Carlo engine for the requested American swaption.
Tags
Full text
# Instrument valuation using Monte Carlo simulation with Quantlib
# 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
## Answer by David Duarte (score 1)
https://quant.stackexchange.com/a/58550
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()
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.