0
$\begingroup$

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

  1. stddevs

  2. extrapolatePayoff

  3. flatPayoffExtrapolation

  4. probabilities*

Your pointer is highly appreciated.

$\endgroup$
3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Thanks. In "Gaussian1dSwaptionEngine" function, you input various parameters as "(64, 7.0, True, False)". Could you please help understanding these parameters? $\endgroup$ – Bogaso Sep 14 '20 at 7:16
  • $\begingroup$ rkapl123.github.io/QLAnnotatedSource/d2/db3/… <-- defined here, integrationPoints and stddevs control the gridding that is used by the pricer (line 54 here rkapl123.github.io/QLAnnotatedSource/d0/db9/…), the remaining two extrapolatePayoff and flatPayoffExtrapolation control the extrapolations outside of these ranges $\endgroup$ – StackG Sep 14 '20 at 8:37
  • $\begingroup$ Thanks. However I am aware of this file. What I could not understand is the underlying mathematical model to setup such grid and purpose thereof. Do you have any information on the technical article/resources to explain them? $\endgroup$ – Bogaso Sep 14 '20 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.