QuantLibPython中的现金结算掉期期权定价

2024-09-27 21:30:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在QuantLib中为现金结算的掉期期权定价,代码如下:

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()

在现金结算案例中,Settlement::checkTypeAndMethodConsistency的代码失败,引发异常:

^{pr2}$

如果在swaption实例化中将ql.Settlement.Cash替换为ql.Settlement.Physical,则相同的代码可以正常工作。在

有没有办法从Python设置结算方式?我看到Python只有两个构造函数可用,没有一个接受settlementMethod参数:

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 &)

Tags: 代码todaycalendarperiodschedulecurveqlconst

热门问题