Using the GSR Model with QuantLib’s Gaussian Swaption Engine
Summary
The document explains why a QuantLib Gaussian one-factor swaption engine rejects a Vasicek model: the engine expects a model derived from Gaussian1dModel, while Vasicek does not meet that interface. The accepted answer shows using a GSR model instead, initialized with a term structure, volatility inputs, and mean-reversion inputs, then passing it to the engine.
The example addresses the constructor error and gives a way to proceed with swaption valuation. It does not explain the engine’s integration and extrapolation settings, despite the question asking about them, and it offers no pricing results or comparison against another model. The GSR parameters in the example are illustrative; model calibration and appropriate parameterization remain the user’s responsibility.
Key ideas
- Gaussian1dSwaptionEngine requires a model compatible with Gaussian1dModel.
- Vasicek is not compatible with this engine’s expected model interface.
- A GSR model can be supplied with a yield curve, volatility inputs, and mean-reversion inputs.
- The example resolves the constructor type error but does not define the engine’s numerical settings.
Tags
Full text
# How to implement the Gaussian one factor model for Short rate
# How to implement the Gaussian one factor model for Short rate
I am struggling to understand how I should use the Gaussian one factor model for short rate for valuation of a `Swaption`. Below is my `Swaption` parameters -
```
from QuantLib import *
import datetime
import numpy as np
import pandas as pd
calc_date = Date(29, 3, 2019)
start = 10
length = 10
start_date = TARGET().advance(calc_date, start, Years)
maturity_date = start_date + Period(length, Years)
spot_curve = FlatForward(calc_date, QuoteHandle(SimpleQuote(0.01)), Actual365Fixed())
termStructure = YieldTermStructureHandle(spot_curve)
index = Euribor6M(termStructure)
fixedSchedule = Schedule(start_date, ## pd.DataFrame({'date': list(fixedSchedule)})
maturity_date,
Period(1, Years),
TARGET(),
Unadjusted,
Unadjusted,
DateGeneration.Forward,
False
)
floatingSchedule = Schedule(start_date, ## pd.DataFrame({'date': list(floatingSchedule)})
maturity_date,
Period(6, Months),
TARGET(),
ModifiedFollowing,
ModifiedFollowing,
DateGeneration.Forward,
True
)
forward = VanillaSwap(VanillaSwap.Receiver,
10000000,
fixedSchedule,
1.45 / 100,
Thirty360(Thirty360.BondBasis),
floatingSchedule,
index,
0.0,
index.dayCounter()
)
swap = forward
exercise = start_date
exercised = EuropeanExercise(exercise)
settlementtype = "physical"
atmswaption = Swaption(swap, exercised)
vol1 = QuoteHandle(SimpleQuote(0.005266))
```
Now I use the `Gaussian1dSwaptionEngine` to value the Swaption as below -
```
atmswaption.setPricingEngine(Gaussian1dSwaptionEngine(Vasicek(0.05, 0.1, 0.05, 0.01, 0.0),
64,
7.0,
True,
False,
termStructure
)); print(atmswaption.NPV())
```
With this I am getting below error -
```
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
File "/Users/aaa/ql-env/lib/python3.6/site-packages/QuantLib/QuantLib.py", line 21358, in __init__
_QuantLib.Gaussian1dSwaptionEngine_swiginit(self, _QuantLib.new_Gaussian1dSwaptionEngine(*args))
TypeError: Wrong number or type of arguments for overloaded function 'new_Gaussian1dSwaptionEngine'.
Possible C/C++ prototypes are:
Gaussian1dSwaptionEngine::Gaussian1dSwaptionEngine(boost::shared_ptr< Gaussian1dModel > const &,int const,Real const,bool const,bool const,Handle< YieldTermStructure > const &,Gaussian1dSwaptionEngine::Probabilities const)
Gaussian1dSwaptionEngine::Gaussian1dSwaptionEngine(boost::shared_ptr< Gaussian1dModel > const &,int const,Real const,bool const,bool const,Handle< YieldTermStructure > const &)
Gaussian1dSwaptionEngine::Gaussian1dSwaptionEngine(boost::shared_ptr< Gaussian1dModel > const &,int const,Real const,bool const,bool const)
Gaussian1dSwaptionEngine::Gaussian1dSwaptionEngine(boost::shared_ptr< Gaussian1dModel > const &,int const,Real const,bool const)
Gaussian1dSwaptionEngine::Gaussian1dSwaptionEngine(boost::shared_ptr< Gaussian1dModel > const &,int const,Real const)
Gaussian1dSwaptionEngine::Gaussian1dSwaptionEngine(boost::shared_ptr< Gaussian1dModel > const &,int const)
Gaussian1dSwaptionEngine::Gaussian1dSwaptionEngine(boost::shared_ptr< Gaussian1dModel > const &)
```
Could you please help me to understand why am I getting this error?
I also failed to understand the meaning of the parameters passed to the `Gaussian1dSwaptionEngine` -
*1. integrationPoints
- stddevs
- extrapolatePayoff
- flatPayoffExtrapolation
- probabilities*
Your pointer is highly appreciated.
## Answer by StackG (score 3)
https://quant.stackexchange.com/a/57983
Your problem is caused because the class `Gaussian1dSwaptionEngine` expects a model of the parent class `Gaussian1dModel`, which `Vasicek` is not.
This snippet gives an example of defining a GSR model, which is accepted by your engine:
```
volStepDates = [Date(1, 1, 2020)]
volatilities = [vol1, vol1]
reversions = [QuoteHandle(SimpleQuote(0.01)), QuoteHandle(SimpleQuote(0.01))]
gsr = Gsr(termStructure, volStepDates, volatilities, reversions)
engine = Gaussian1dSwaptionEngine(gsr, 64, 7.0, True, False, termStructure)
atmswaption.setPricingEngine(engine)
print(atmswaption.NPV())
```
You can read mode about the GSR model here (paper) or here (high level view with links) - in the snippet above I've entered holding parameters but you should think about how you would like to parameterise your model.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.