QuantLib-Python中以现金结算的掉期定价

时间:2019-01-02 19:24:46

标签: python quantlib quantlib-swig

我正在尝试使用Swiged 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上失败,引发异常:

"invalid settlement method for cash settlement"

如果在交换实例中将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 &)

1 个答案:

答案 0 :(得分:1)

SWIG界面尚未更新以反映基础库中的更改(您可能要为此在https://github.com/lballabio/QuantLib-SWIG/issues处发布问题)。

同时,使用QuantLib 1.13应该可以。