I am trying to price a cash-settled swaption in QuantLib
using the swigged python version, the code is as follows:
import QuantLib as ql
# QL session
today = ql.Date(2, ql.January, 2019)
ql.Settings.instance().evaluationDate = today
# Underlying swap definition
curve = ql.YieldTermStructureHandle(ql.FlatForward(today, 0.03, ql.Actual365Fixed()))
libor_3m = ql.USDLibor(ql.Period('3M'), curve)
calendar = ql.UnitedStates()
effective = calendar.advance(today, 1, ql.Years)
maturity = calendar.advance(effective, 4, ql.Years)
fixed_schedule = ql.Schedule(effective, maturity, ql.Period('6M'), calendar,
ql.ModifiedFollowing, ql.ModifiedFollowing,
ql.DateGeneration.Forward, False)
float_schedule = ql.Schedule (effective, maturity, ql.Period('3M'), calendar,
ql.ModifiedFollowing, ql.ModifiedFollowing,
ql.DateGeneration.Forward, False)
notional = 1e6
swap = ql.VanillaSwap(ql.VanillaSwap.Payer, notional, fixed_schedule, 0.03,
ql.Actual365Fixed(), float_schedule, libor_3m, 0.,
ql.Actual360())
# Swaption definition
swaption = ql.Swaption(swap, ql.EuropeanExercise(effective), ql.Settlement.Cash)
engine = ql.BlackSwaptionEngine(curve, ql.QuoteHandle(ql.SimpleQuote(0.1)))
swaption.setPricingEngine(engine)
swaption.NPV()
The code fails on Settlement::checkTypeAndMethodConsistency
in the cash-settled case, throwing the exception:
"invalid settlement method for cash settlement"
The same code works fine if you replace ql.Settlement.Cash
by ql.Settlement.Physical
in the swaption instantiation.
Is there a way to set the settlement method from Python? I see only two constructors available from Python and none takes a settlementMethod
argument:
Possible C/C++ prototypes are:
SwaptionPtr::SwaptionPtr(VanillaSwapPtr const &,boost::shared_ptr<Exercise > const &,Settlement::Type)
SwaptionPtr::SwaptionPtr(VanillaSwapPtr const &,boost::shared_ptr<Exercise > const &)
The SWIG interface has not yet been updated to reflect the changes in the underlying library (you might want to open an issue at https://github.com/lballabio/QuantLib-SWIG/issues for that).
In the meantime, using QuantLib 1.13 should work.